Giter Site home page Giter Site logo

izzzzzi / telegram-bot-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from donbarbos/telegram-bot-template

0.0 0.0 0.0 3.76 MB

๐Ÿค– Template for telegram bot using postgres, pgbouncer, redis, docker, amplitude, prometheus, grafana, CI

License: GNU Lesser General Public License v3.0

JavaScript 5.40% Python 68.14% CSS 0.79% HTML 23.86% Mako 0.61% Dockerfile 1.20%

telegram-bot-template's Introduction

Telegram bot template

Best way to create a scalable telegram bot with analytics

GitHub tag (latest SemVer) Linters Status Docker Build Status Python License Code style

โœจ Features

๐Ÿš€ How to Use

๐Ÿณ Running in Docker (recommended method)

  • configure environment variables in .env file

  • start services

    docker compose up -d --build
  • make migrations

    docker compose exec bot alembic upgrade head

๐Ÿ’ป Running on Local Machine

  • install dependencies using Poetry

    poetry install
  • start the necessary services (at least the database and redis)

  • configure environment variables in .env file

  • start telegram bot

    poetry run python -m bot
  • start admin panel

    poetry run gunicorn -c admin/gunicorn_conf.py
  • make migrations

    poetry run alembic upgrade head
  • create tables (from sqlite)

    poetry run alembic revision --autogenerate -m "Added user table"

๐ŸŒ Environment variables

to launch the bot you only need a token bot, database and redis settings, everything else can be left out

name description
BOT_TOKEN Telegram bot API token
RATE_LIMIT Maximum number of requests allowed per minute for rate limiting
DEBUG Enable or disable debugging mode (e.g., True or False)
USE_WEBHOOK Flag to indicate whether the bot should use a webhook for updates (e.g., True or False)
WEBHOOK_BASE_URL Base URL for the webhook
WEBHOOK_PATH Path to receive updates from Telegram
WEBHOOK_SECRET Secret key for securing the webhook communication
WEBHOOK_HOST Hostname or IP address for the main application
WEBHOOK_PORT Port number for the main application
ADMIN_HOST Hostname or IP address for the admin panel
ADMIN_PORT Port number for the admin panel
DEFAULT_ADMIN_EMAIL Default email for the admin user
DEFAULT_ADMIN_PASSWORD Default password for the admin user
SECURITY_PASSWORD_HASH Hashing algorithm for user passwords (e.g., bcrypt)
SECURITY_PASSWORD_SALT Salt value for user password hashing
USE_SQLITE Flag to uses sqlite (e.g., True or False)
DB_HOST Hostname or IP address of the PostgreSQL database
DB_PORT Port number for the PostgreSQL database
DB_USER Username for authenticating with the PostgreSQL database
DB_PASS Password for authenticating with the PostgreSQL database
DB_NAME Name of the PostgreSQL database
REDIS_HOST Hostname or IP address of the Redis database
REDIS_PORT Port number for the Redis database
REDIS_PASS Password for authenticating with the Redis database
SENTRY_DSN Sentry DSN (Data Source Name) for error tracking
AMPLITUDE_API_KEY API key for Amplitude analytics
POSTHOG_API_KEY API key for PostHog analytics
PROMETHEUS_PORT Port number for the Prometheus monitoring system
GRAFANA_PORT Port number for the Grafana monitoring and visualization platform
GRAFANA_ADMIN_USER Admin username for accessing Grafana
GRAFANA_ADMIN_PASSWORD Admin password for accessing Grafana

๐Ÿ“‚ Project Folder Structure

.
โ”œโ”€โ”€ admin # Source code for admin panel
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ app.py # Main application module for the admin panel
โ”‚ย ย  โ”œโ”€โ”€ config.py # Configuration module for the admin panel
โ”‚ย ย  โ”œโ”€โ”€ Dockerfile # Dockerfile for admin panel
โ”‚ย ย  โ”œโ”€โ”€ gunicorn_conf.py # Gunicorn configuration file for serving admin panel
โ”‚ย ย  โ”œโ”€โ”€ static # Folder for static assets
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ css/
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ fonts/
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ img/
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ js/
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ plugins/
โ”‚ย ย  โ”œโ”€โ”€ templates # HTML templates for the admin panel
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ admin/
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ my_master.html
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ security/
โ”‚ย ย  โ””โ”€โ”€ views # Custom View modules for handling web requests
โ”‚ย ย      โ”œโ”€โ”€ __init__.py
โ”‚ย ย      โ””โ”€โ”€ users.py
โ”‚
โ”œโ”€โ”€ bot # Source code for Telegram Bot
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ __main__.py # Main entry point to launch the bot
โ”‚ย ย  โ”œโ”€โ”€ analytics/ # Interaction with analytics services (e.g., Amplitude or Google Analytics)
โ”‚ย ย  โ”œโ”€โ”€ cache/ # Logic for using Redis cache
โ”‚ย ย  โ”œโ”€โ”€ core/ # Settings for application and other core components
โ”‚ย ย  โ”œโ”€โ”€ database/ # Database functions and SQLAlchemy Models
โ”‚ย ย  โ”œโ”€โ”€ filters/ # Filters for processing incoming messages or updates
โ”‚ย ย  โ”œโ”€โ”€ handlers/ # Handlers for processing user commands and interactions
โ”‚ย ย  โ”œโ”€โ”€ keyboards # Modules for creating custom keyboards
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ default_commands.py # Default command keyboards
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ inline/ # Inline keyboards
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ reply/ # Reply keyboards
โ”‚ย ย  โ”œโ”€โ”€ locales/ # Localization files for supporting multiple languages
โ”‚ย ย  โ”œโ”€โ”€ middlewares/ # Middleware modules for processing incoming updates
โ”‚ย ย  โ”œโ”€โ”€ services/ # Business logic for application
โ”‚ย ย  โ””โ”€โ”€ utils/ # Utility functions and helper modules
โ”‚
โ”œโ”€โ”€ migrations # Database Migrations managed by Alembic
โ”‚ย ย  โ”œโ”€โ”€ env.py # Environment setup for Alembic
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ README
โ”‚ย ย  โ”œโ”€โ”€ script.py.mako # Script template for generating migrations
โ”‚ย ย  โ””โ”€โ”€ versions/ # Folder containing individual migration scripts
โ”‚
โ”œโ”€โ”€ configs # Config folder for Monitoring (Prometheus, Node-exporter and Grafana)
โ”‚ย ย  โ”œโ”€โ”€ grafana # Configuration files for Grafana
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ datasource.yml
โ”‚ย ย  โ””โ”€โ”€ prometheus # Configuration files for Prometheus
โ”‚ย ย      โ””โ”€โ”€ prometheus.yml
โ”‚
โ”œโ”€โ”€ alembic.ini # Configuration file for migrations
โ”œโ”€โ”€ docker-compose.yml # Docker Compose configuration file for orchestrating containers
โ”œโ”€โ”€ Dockerfile # Dockerfile for Telegram Bot
โ”œโ”€โ”€ LICENSE.md # License file for the project
โ”œโ”€โ”€ poetry.lock # Lock file for Poetry dependency management
โ”œโ”€โ”€ pyproject.toml # Configuration file for Python projects, including build tools, dependencies, and metadata
โ””โ”€โ”€ README.md # Documentation

๐Ÿ”ง Tech Stack

  • sqlalchemy โ€” object-relational mapping (ORM) library that provides a set of high-level API for interacting with relational databases
  • asyncpg โ€” asynchronous PostgreSQL database client library
  • aiogram โ€” asynchronous framework for Telegram Bot API
  • flask-admin โ€” simple and extensible administrative interface framework
  • loguru โ€” third party library for logging in Python
  • poetry โ€” development workflow
  • docker โ€” to automate deployment
  • postgres โ€” powerful, open source object-relational database system
  • pgbouncer โ€” connection pooler for PostgreSQL database
  • redis โ€” in-memory data structure store used as a cache and FSM
  • prometheus โ€” time series database for collecting metrics from various systems
  • grafana โ€” visualization and analysis from various sources, including Prometheus

๐Ÿ‘ท Contributing

First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork this repository
  2. Create a branch
  3. Commit your changes
  4. Push your commits to the branch
  5. Submit a pull request

๐Ÿ“ License

Distributed under the LGPL-3.0 license. See LICENSE for more information.

๐Ÿ“ข Contact

donbarbos: [email protected]

telegram-bot-template's People

Contributors

donbarbos avatar dependabot[bot] avatar realaashil avatar aoulaa 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.