A starter bot template based on grammY and prisma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Timofey Gelazoniya 24c6f1c469
Merge pull request #3 from xzeldon/renovate/all-minor-patch
6 days ago
.github Setup renovate bot 5 months ago
.vscode remove eslint comments, add vscode formatter config 2 weeks ago
.yarn/releases Update Yarn to v3.2.1 1 week ago
docker edit gitignore and readme.md 2 weeks ago
locales add russian localization 1 week ago
prisma Initial implementation 5 months ago
src remove eslint comments, add vscode formatter config 2 weeks ago
.dockerignore docker support 2 weeks ago
.env.sample clean up 2 weeks ago
.gitignore edit gitignore and readme.md 2 weeks ago
.yarnrc.yml Update Yarn to v3.2.1 1 week ago
README.md extra dot removed 2 weeks ago
package.json Update Yarn to v3.2.1 1 week ago
tsconfig.json Initial implementation 5 months ago
yarn.lock Update Yarn to v3.2.1 1 week ago

README.md

🤖 Telegram Bot Template

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.


Features

  • 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

Usage

Clone this repo or generate new repo using this template via link

git clone https://github.com/xzeldon/telegram-bot-template
Launch
  1. Create environment variables file
cp .env.sample .env
  1. Edit environment variables in .env

  2. Launch bot

    Development mode:

    # install dependencies
    yarn
    
    # run migrations
    yarn migrate
    
    # run bot
    yarn dev
    

    Production mode:

    # install dependencies
    yarn install --production
    
    # run migrations
    yarn migrate
    
    # build bot
    yarn build
    
    # run bot
    yarn start
    
Launch using Docker
  1. Create development and production environment variables files
# development
cp ./docker/.example.bot.env ./docker/docker-compose.dev.bot.env
cp ./docker/.example.postgres.env ./docker/docker-compose.dev.postgres.env

# production
cp ./docker/.example.bot.env ./docker/docker-compose.prod.bot.env
cp ./docker/.example.postgres.env ./docker/docker-compose.prod.postgres.env
  1. Edit environment variables in docker/docker-compose.dev.bot.env and docker/docker-compose.prod.bot.env

  2. Launch bot

    Development mode:

    # install dependencies
    yarn
    
    # run migrations
    cd docker && docker-compose run bot yarn migrate
    
    # run bot
    docker-compose up
    

    Production mode:

    # run migrations
    docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.prod.yml run bot yarn migrate
    
    # run bot
    docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.prod.yml up
    

Environment variables reference

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.