Skip to content

Telegram bot template based on grammY

Notifications You must be signed in to change notification settings

bot-base/telegram-bot-template

Repository files navigation

🤖 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

  1. Create a new repository using this template.

  2. Create an environment variables file:

cp .env.example .env
  1. Set BOT_TOKEN environment variable in .env file.

  2. Launch bot

    Development mode:

    # 1. Install dependencies
    npm i
    
    # 2. Run bot (in watch mode)
    npm run dev

    Production mode:

    # 1. Install dependencies
    npm i --only=prod
    
    # 2. Set NODE_ENV to production and change BOT_WEBHOOK to the actual URL to receive updates
    
    # 3. Run bot
    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 — Runs type checking.
  • npm run dev — Starts the bot in development mode.
  • npm run start — Starts the bot.
  • npm run start:force — Starts the bot without type checking.

Deploy

Docker

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 --no-commit --allow-unrelated-histories

Vercel

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 --no-commit --allow-unrelated-histories

Examples

Prisma ORM

Branch: example/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/prisma -X theirs --no-commit --allow-unrelated-histories

Environment Variables

Variable Description
NODE_ENV Node environment (development or production)
LOG_LEVEL Log level
BOT_SERVER_HOST Server address (default 0.0.0.0)
BOT_SERVER_PORT Server port (default 80)
BOT_ALLOWED_UPDATES List of update types to receive
BOT_TOKEN Token, get it from @BotFather
BOT_WEBHOOK
Webhook endpointWill be used to setup webhook in production mode.
BOT_ADMIN_USER_ID
Administrator user IDCommands, such as /setcommands, will only be available to the user with this ID.