Skip to content

jaskaur18/telegramBot-TemplateGrammyTypescript

Repository files navigation

🤖 Bot By Honey Singh

Bot 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

git clone ulr
Launch
  1. Create environment variables file
cp .example.bot.env .env
  1. Edit environment variables in .env

  2. 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
  1. 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
  1. Edit environment variables in docker-compose.dev.bot.env and docker-compose.prod.bot.env

  2. 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

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.

About

Telegram Bot Telegram Based On grammY Nodejs Typescript and prisma orm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published