Ensure uv is installed, then create a new Telegram bot project with:
uvx --with copier-templates-extensions copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/projectBuilt with Copier, this template lets you toggle features during setup - choose what you need and generate files instantly! Ready for Docker π³ and Coolify βοΈ deployment.
-
Docker Composeπ³ Launch bot + services with one command -
Python 3.9β3.13π Choose your Python version easily -
uvπ Fast dependency management powered by Rust -
Poetryπ¦ Manage dependencies safely with virtual environments -
pipπ Classic Python package installer
-
Aiogramβ‘ Modern async bot framework with state management -
Aiogram DialogπΌοΈ Create menus and interactive interfaces -
Redisβ€οΈ Keep bot data safe between restarts
-
PostgreSQLπ Powerful database for complex projects -
SQLAlchemyπ οΈ Work with databases using Python code -
Alembicβ³ Track and apply database changes easily -
User Tableπ€ id, username, first_name, last_name, etc
-
Dependency Injectionπ Share tools/data across bot handlers -
Throttlingπ Stop spam with automatic speed limits -
Database Sessionsβ»οΈ Auto-manage database connections -
Loguruπ Simple logging with colors and fun -
User Registerπ Adds a user to the database on /start -
Callback Answerπ Automatically answer callback queries
-
PostHogπ Product analytics with user tracking and event capture -
i18nπ Multiple languages support -
Dependabotπ€ Automatic dependency updates -
Pydantic Settingsβ Safe config management with type checking -
DynaconfβοΈ Configs for dev/test/prod environments -
RuffπͺΆ Super-fast code linting and cleanup -
Justfileπͺ Short commands for complex tasks -
Cache Decoratorβ‘ Speed up functions with Redis caching
The fully-featured generated project can be found in the example/ directory.
Below is the folder structure of the generated project:
.
βββ bot # Main directory for the bot's source code
β βββ cache # Contains caching-related modules
β β βββ redis.py # Module for Redis-based caching functionality
β β βββ serialization.py # Handles serialization and deserialization for cached data
β β
β βββ core # Core components of the bot
β β βββ loader.py # Initializes and loads core components of the bot
β β βββ settings.py # Configuration and settings for the bot
β β
β βββ database # Database-related modules and models
β β βββ models # Directory for database model definitions
β β β βββ base.py # Base class for database models
β β β βββ user.py # User table model
β β βββ database.py # Database connection
β β
β βββ dialogs # Dialog flow and interaction logic
β β βββ example # Example implementation of dialogs
β β βββ dialogs.py # Defines dialogs
β β βββ getters.py # Retrieves data required for dialogs
β β βββ handlers.py # Handles user interactions within dialogs
β β
β βββ filters/ # Custom filters for handling specific bot commands or messages
β β
β βββ handlers # General handlers for bot events
β β βββ start.py # Handler for the /start command
β β
β βββ keyboards # Defines inline and reply keyboards for user interaction
β β βββ inline # Inline keyboards
β β
β βββ middleware # Middleware modules to extend bot behavior
β β βββ analytics.py # Middleware to identify user for analytics
β β βββ database.py # Middleware to manage database interactions during events
β β βββ dependency.py # Dependency injection middleware for shared resources
β β βββ logger.py # Middleware to log events
β β βββ throttling.py # Middleware to handle rate-limiting of requests
β β βββ user_register.py # Add user to DB on /start
β β
β βββ services/ # Auxiliary services with business logic
β β βββ user.py # User CRUD and helpers
β β
β βββ states/ # FSM states
β β βββ example.py # Example states
β β
β βββ __main__.py # Entry point to run the bot application
β βββ commands.py # Commands setup
β
βββ locales # Translations (Fluent `.ftl` files)
β βββ en
β βββ LC_MESSAGES
β βββ bot.ftl # English texts (add more locales similarly)
β
βββ migrations # Database migration files (managed by Alembic)
β βββ versions/ # Directory containing individual migration scripts
β β βββ add_users_table.py # Creates users table
β βββ env.py # Alembic environment configuration file
β βββ script.py.mako # Template for generating new migration scripts
β
βββ .dockerignore # Specifies files and directories to ignore in Docker builds
βββ .gitignore # Specifies files and directories to ignore in Git version control
βββ .github
β βββ dependabot.yml # Automatic dependency updates
βββ .python-version # Python version specification file for version managers like pyenv
βββ .env # Environment variable settings file
βββ .template.env # Template file for environment variables
βββ alembic.ini # Alembic configuration file for database migrations
βββ compose.yaml # Docker Compose configuration file for multi-container setups
βββ Dockerfile # Instructions to build a Docker image for the application
βββ entrypoint.sh # Script executed as the container's entry point
βββ justfile # Task runner configuration file (for `just` command automation)
βββ pyproject.toml # Python project metadata and dependencies configuration (PEP-518)
βββ README.md # Documentation readme file describing the project
βββ uv.lock # Lock file generated by a dependency managerBefore using the Copier Telegram Bot template, ensure you have the following installed:
- Copier: Refer to the installation guide
- Copier Templates Extensions: Refer to the repository for installation instructions
Once these prerequisites are installed, you're ready to use the template!
copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/projectCopier will ask you a lot of questions. Answer them to properly generate the template.
Help shape the future! Planned improvements:
-
Testingβ Add testing framework -
Flake8/wemakeπ§Ή Alternative strict linting for code quality fans -
Admin Roleπ Add admin filter -
Commands i18nπ Add i18n support for bot commands
Got ideas? Star β the repo or open an issue to collaborate! π
- For a small change, just send a PR.
- For bigger changes open an issue for discussion before sending a PR.
- PR should have:
- Test case
- Documentation
- Example (If it makes sense)
Distributed under the Apache License 2.0. See LICENSE for more information.