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
- Dependency injection
- Session storage
- Internationalization with language change
- 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
Launch
- Create environment variables file
cp .example.bot.env .env
-
Edit environment variables in
.env
-
Launch bot
Development mode:
# install dependencies npm i # run migrations npx prisma migrate deploy # run bot npm run dev
Production mode:
# install dependencies npm i --only=prod # run migrations npx prisma migrate deploy # build bot npm run build # run bot npm start
Launch using Docker
- Create development and production environment variables files
# development
cp .example.bot.env docker-compose.dev.bot.env
cp .example.postgres.env docker-compose.dev.postgres.env
# production
cp .example.bot.env docker-compose.prod.bot.env
cp .example.postgres.env docker-compose.prod.postgres.env
-
Edit environment variables in
docker-compose.dev.bot.env
anddocker-compose.prod.bot.env
-
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
Variable | Description |
---|---|
NODE_ENV | Node environment |
LOG_LEVEL | Log level |
CHECKPOINT_DISABLE | Prisma Telemetry |
DATABASE_URL | Database URL |
REDIS_URL | Redis URL |
BOT_SERVER_HOST | Server address |
BOT_SERVER_PORT | Server port |
BOT_ALLOWED_UPDATES | List of update types to receive |
BOT_TOKEN | Token, get it from @BotFather |
BOT_WEBHOOK | Webhook endpointUsed for setup a webhook in production mode. |
BOT_ADMIN_USER_ID | Administrator user IDCommands, such as/stats or /setcommands , will only be available to the user with this ID. |