Giter Site home page Giter Site logo

template's Introduction

๐Ÿค– Telegram Bot Template

Bot starter template based on grammY bot framework.

Features

  • Scalable structure
  • Config loading and validation
  • Internationalization, language changing
  • Graceful shutdown
  • Logger (powered by pino)
  • Fast and low overhead server (powered by fastify)
  • Ready-to-use deployment setups:
  • Examples:

Usage

Follow these steps to set up and run your bot using this template:

  1. Create a New Repository

    Start by creating a new repository using this template. You can do this by clicking here.

  2. Environment Variables Setup

    Create an environment variables file by copying the provided example file:

    cp .env.example .env

    Open the newly created .env file and set the BOT_TOKEN environment variable.

  3. Launching the Bot

    You can run your bot in both development and production modes.

    Development Mode:

    Install the required dependencies:

    npm install

    Start the bot in watch mode (auto-reload when code changes):

    npm run dev

    Production Mode:

    Install only production dependencies (no development dependencies):

    npm install --only=prod

    Set the NODE_ENV environment variable to "production" in your .env file. Also, make sure to update BOT_WEBHOOK with the actual URL where your bot will receive updates.

    NODE_ENV=production
    BOT_WEBHOOK=<your_webhook_url>

    Start the bot in production mode:

    npm start
    # or
    npm run start:force # if you want to skip type checking

List of Available Commands

  • npm run lint โ€” Lint source code.
  • npm run format โ€” Format source code.
  • npm run typecheck โ€” Run type checking.
  • npm run dev โ€” Start the bot in development mode.
  • npm run start โ€” Start the bot.
  • npm run start:force โ€” Starts the bot without type checking.

Deploy

Docker (docker.com)

Branch: deploy/docker-compose (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge deployment setup
git merge template/deploy/docker-compose -X theirs --squash --no-commit --allow-unrelated-histories

Vercel (vercel.com)

Branch: deploy/vercel (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge deployment setup
git merge template/deploy/vercel -X theirs --squash --no-commit --allow-unrelated-histories

Examples

Prisma ORM (prisma.io)

Branch: example/orm-prisma (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge example
git merge template/example/orm-prisma -X theirs --squash --no-commit --allow-unrelated-histories

grammY conversations (grammy.dev/plugins/conversations)

Branch: example/plugin-conversations (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge example
git merge template/example/plugin-conversations -X theirs --squash --no-commit --allow-unrelated-histories

Branch: example/plugin-runner (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge example
git merge template/example/plugin-runner -X theirs --squash --no-commit --allow-unrelated-histories

Web App (Vite, TypeScript)

Branch: example/webapp (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge example
git merge template/example/webapp -X theirs --squash --no-commit --allow-unrelated-histories

Web App with Vue (Vue, Vite, TypeScript)

Branch: example/webapp-vue (open diff)

Use in your project:

  1. Add the template repository as a remote
git remote add template [email protected]:bot-base/telegram-bot-template.git
git remote update
  1. Merge example
git merge template/example/webapp-vue -X theirs --squash --no-commit --allow-unrelated-histories

Environment Variables

Variable Type Description
NODE_ENV String Specifies the application environment. (development or production)
BOT_TOKEN String Telegram Bot API token obtained from @BotFather.
LOG_LEVEL String Optional. Specifies the application log level.
For example, use info for general logging. View the Pino documentation for more log level options.
Defaults to info.
BOT_MODE String Optional. Specifies method to receive incoming updates. (polling or webhook) Defaults to polling.
BOT_WEBHOOK String Optional in polling mode. Webhook endpoint URL, used to configure webhook in production environment.
BOT_SERVER_HOST String Optional. Specifies the server hostname.
Defaults to 0.0.0.0.
BOT_SERVER_PORT Number Optional. Specifies the server port.
Defaults to 80.
BOT_ALLOWED_UPDATES Array of String Optional. A JSON-serialized list of the update types you want your bot to receive. See Update for a complete list of available update types.
Defaults to an empty array (all update types except chat_member).
BOT_ADMINS Array of Number Optional. Administrator user IDs. Use this to specify user IDs that have special privileges, such as executing /setcommands.
Defaults to an empty array.

template's People

Contributors

opvoid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.