Bot starter template based on grammY bot framework and prisma ORM.
Uses PostgreSQL for data storage (MySQL, MongoDB, SQL Server, SQLite are also supported by prisma) and Redis for session storage.
- Config loading and validation
- Logger
- Sessions
- Language picker and internationalization
- Graceful shutdown
- Metrics collection (in prometheus format)
- Fast and low overhead fastify server
- Ready-to-use Docker setup
-
Clone this repo or generate new repo using this template via link
git clone https://github.com/bot-base/telegram-bot-template
-
Create development and production environment variables files
# development cp ./docker/bot.env.example ./docker/bot.dev.env cp ./docker/postgres.env.example ./docker/postgres.dev.env # production cp ./docker/bot.env.example ./docker/bot.prod.env cp ./docker/postgres.env.example ./docker/postgres.prod.env
-
Edit environment variables in
docker/bot.dev.env
anddocker/bot.prod.env
BOT_TOKEN
— bot token, required to change. Get it from @BotFather.
BOT_WEBHOOK
— bot webhook url, required to change in production. Used for setup a webhook in production mode.
BOT_ADMIN_USER_ID
— administrator user ID. Administrator commands, such as/stats
or/setcommands
, will only be available to the user with this ID.NODE_ENV
— environment (default isdevelopment
, setproduction
to use webhook)
LOG_LEVEL
— log level
DATABASE_URL
— database url
REDIS_URL
— redis url -
Launch bot
Development mode:
# install dependencies npm i # run migrations docker-compose run bot npx prisma migrate deploy # run bot docker-compose up
Production mode:
# run migrations docker-compose -f docker-compose.yml -f docker-compose.prod.yml run bot npx prisma migrate deploy # run bot docker-compose -f docker-compose.yml -f docker-compose.prod.yml up