π€ Template for telegram bot using postgres, pgbouncer, redis, docker, amplitude, prometheus, grafana, CI with admin panel
Flask-Admin-Dashboard
(Flask-Admin
+ AdminLTE
= β€οΈ )Amplitude
or Posthog
or Google Analytics
Prometheus
and Grafana
Sentry
Docker
and Docker Compose
.csv
(or .xlsx
, .json
, yaml
from admin panel)SQLAlchemy V2
is used to communicate with the databaseAlembic
Pydantic V2
Babel
configure environment variables in .env
file
start services
docker compose up -d --build
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
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 |
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 |
.
βββ 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
β
βββ scripts/ # Sripts folder
βββ Makefile # List of commands for standard
βββ 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
sqlalchemy
β object-relational mapping (ORM) library that provides a set of high-level API for interacting with relational databasesasyncpg
β asynchronous PostgreSQL database client libraryaiogram
β asynchronous framework for Telegram Bot APIflask-admin
β simple and extensible administrative interface frameworkloguru
β third party library for logging in Pythonpoetry
β development workflowdocker
β to automate deploymentpostgres
β powerful, open source object-relational database systempgbouncer
β connection pooler for PostgreSQL databaseredis
β in-memory data structure store used as a cache and FSMprometheus
β time series database for collecting metrics from various systemsgrafana
β visualization and analysis from various sources, including PrometheusFirst 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!
Fork
this repositorybranch
Commit
your changesPush
your commits
to the branch
pull request
Distributed under the LGPL-3.0 license. See LICENSE
for more information.