Code Monkey home page Code Monkey logo

grammy-starter-kit's Introduction

๐Ÿค– 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
  • Session storage
  • Internationalization with language change
  • Graceful shutdown
  • Metrics collection (in prometheus format)
  • Fast and low overhead fastify server
  • Ready-to-use Docker setup

Usage

Clone this repo

git clone https://github.com/tsvetkovv/grammy-starter-kit
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
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.

Metrics

Prometheus metrics are available at /metrics endpoint like http://BOT_SERVER_HOST:BOT_SERVER_PORT/metrics

grammy-starter-kit's People

Contributors

tsvetkovv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.