Skip to content

TimNekk/copier-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Telegram Bot Template

πŸš€ Quickstart

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/project

✨ Features

Built with Copier, this template lets you toggle features during setup - choose what you need and generate files instantly! Ready for Docker 🐳 and Coolify ☁️ deployment.

Core Infrastructure

  • 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

Telegram Bot Framework

  • Aiogram ⚑ Modern async bot framework with state management
  • Aiogram Dialog πŸ–ΌοΈ Create menus and interactive interfaces
  • Redis ❀️ Keep bot data safe between restarts

Database & ORM

  • PostgreSQL 🐘 Powerful database for complex projects
  • SQLAlchemy πŸ› οΈ Work with databases using Python code
  • Alembic ⏳ Track and apply database changes easily

Middlewares

Tooling

  • 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

πŸ“‚ Project Structure

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
β”‚   β”‚   └── 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
β”‚   β”‚   └── default_commands.py  # Defualt commands setup
β”‚   β”‚   
β”‚   β”œβ”€β”€ middleware               # Middleware modules to extend bot behavior
β”‚   β”‚   β”œβ”€β”€ database.py          # Middleware to manage database interactions during eventxs
β”‚   β”‚   β”œβ”€β”€ dependency.py        # Dependency injection middleware for shared resources
β”‚   β”‚   β”œβ”€β”€ logger.py            # Middleware to log events
β”‚   β”‚   └── throttling.py        # Middleware to handle rate-limiting of requests
β”‚   β”‚   
β”‚   β”œβ”€β”€ services/                # Auxiliary services with business logic
β”‚   β”‚   
β”‚   β”œβ”€β”€ __main__.py              # Entry point to run the bot application
β”‚   └── states.py                # FMS states
β”‚   
β”œβ”€β”€ migrations                   # Database migration files (managed by Alembic)
β”‚   β”œβ”€β”€ versions/                # Directory containing individual migration scripts
β”‚   β”œβ”€β”€ 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
β”œβ”€β”€ .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 manager

πŸ“– Usage

Before using the Copier Telegram Bot template, ensure you have the following installed:

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/project

Copier will ask you a lot of questions. Answer them to properly generate the template.

πŸ—ΊοΈ Roadmap

Help shape the future! Planned improvements:

Got ideas? Star ⭐ the repo or open an issue to collaborate! πŸš€

⭐ Star History

Star History Chart

πŸ‘· Contributing

  • 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)

πŸ“ License

Distributed under the Apache License 2.0. See LICENSE for more information.