Telegram bot template based on grammY
Last updated Jun 30, 2026
439
Stars
61
Forks
15
Issues
0
Stars/day
Attention Score
71
Topics
Language breakdown
TypeScript 97.6%
Fluent 2.1%
JavaScript 0.3%
โธ Files
click to expand
README
๐ค 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)
- Ultrafast and multi-runtime server (powered by hono)
- Ready-to-use deployment setups:
- Examples:
Usage
Follow these steps to set up and run your bot using this template:
- Create a New Repository
- Environment Variables Setup
cp .env.example .env
Open the newly created .env file and set the BOT_TOKEN environment variable.
- Launching the Bot
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:
npm install --only=prod
Set DEBUG environment variable to false in your .env file.
Start the bot in production mode:
npm run start:force # skip type checking and start # or npm start # with type checking (requires development dependencies)
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.
Directory Structure
project-root/
โโโ locales # Localization files
โโโ src
โโโ bot # Code related to bot
โ โโโ callback-data # Callback data builders
โ โโโ features # Bot features
โ โโโ filters # Update filters
โ โโโ handlers # Update handlers
โ โโโ helpers # Helper functions
โ โโโ keyboards # Keyboard builders
โ โโโ middlewares # Bot middlewares
โ โโโ i18n.ts # Internationalization setup
โ โโโ context.ts # Context object definition
โ โโโ index.ts # Bot entry point
โโโ server # Code related to web server
โ โโโ middlewares # Server middlewares
โ โโโ environment # Server environment setup
โ โโโ index.ts # Server entry point
โโโ config.ts # Application config
โโโ logger.ts # Logging setup
โโโ main.ts # Application entry point
Deploy
Docker (docker.com)
Branch: deploy/docker-compose (open diff)
Use in your project:
- Add the template repository as a remote
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
- Merge deployment setup
git merge template/deploy/docker-compose -X theirs --squash --no-commit --allow-unrelated-histories
- Follow the usage instructions in the
deploy/docker-composebranch.
Vercel (vercel.com)
Branch: deploy/vercel (open diff)
Use in your project:
- Add the template repository as a remote
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
- Merge deployment setup
git merge template/deploy/vercel -X theirs --squash --no-commit --allow-unrelated-histories
- Follow the usage instructions in the
deploy/vercelbranch.
Examples
grammY conversations (grammy.dev/plugins/conversations)
Branch: example/plugin-conversations (open diff)
Use in your project:
- Add the template repository as a remote
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
- Merge example
git merge template/example/plugin-conversations -X theirs --squash --no-commit --allow-unrelated-histories
- Install dependencies
npm i @grammyjs/conversations
- Follow the usage instructions in the
example/plugin-conversationsbranch.
Prisma ORM (prisma.io)
Branch: example/orm-prisma (open diff)
Use in your project:
- Add the template repository as a remote
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
- Merge example
git merge template/example/orm-prisma -X theirs --squash --no-commit --allow-unrelated-histories
- Install dependencies
npm i -D prisma
npm i @prisma/client
- Follow the usage instructions in the
example/orm-prismabranch.
Bun (bun.sh)
Branch: example/runtime-bun (open diff)
Use in your project:
- Add the template repository as a remote
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
- Merge example
git merge template/example/runtime-bun -X theirs --squash --no-commit --allow-unrelated-histories
- Install dependencies
# remove Node-related dependencies
npm r @types/node tsx tsc-watch
install dependencies
bun i
remove npm lockfile
rm package-lock.json
install bun typings
bun add -d @types/bun
- Follow the usage instructions in the
example/runtime-bunbranch.
Environment Variables
| Variable | Type | Description |
|---|---|---|
| BOT_TOKEN | String | Telegram Bot API token obtained from @BotFather. |
| BOT_MODE | String |
Specifies method to receive incoming updates (polling or webhook).
|
| LOG_LEVEL | String |
Optional.
Specifies the application log level. Use info for general logging. Check the Pino documentation for more log level options. Defaults to info.
|
| DEBUG | Boolean |
Optional.
Enables debug mode. You may use config.isDebug flag to enable debugging functions.
|
| BOT_WEBHOOK | String |
Optional in polling mode.
Webhook endpoint URL, used to configure webhook.
|
| BOTWEBHOOKSECRET | String |
Optional in polling mode.
A secret token that is used to ensure that a request is sent from Telegram, used to configure webhook.
|
| SERVER_HOST | String |
Optional in polling mode. Specifies the server hostname. Defaults to 0.0.0.0.
|
| SERVER_PORT | Number |
Optional in polling mode. Specifies the server port. Defaults to 80.
|
| BOTALLOWEDUPDATES | 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 chatmember, messagereaction and messagereactioncount).
|
| 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. |
๐ More in this category