A flexible boilerplate for building Telegram bots using modern tools and best practices. This project is designed to simplify the setup, development, and scaling of Telegram bots, with support for both development and production environments
- Python 3.12+: Built with the latest Python features
- Telegram Bot API: Powered by
python-telegram-bot - Auto-Reload: Supports auto-reloading during development using
watchfiles - Environment Configuration: Easy setup with
.envfile - Docker Support: Ready for containerized deployments
- Makefile: Simplified commands for common tasks
- Clean Structure: Modular and scalable architecture for adding features
Ensure you have the following installed:
- Python 3.12+: Download Python
- Poetry: For dependency management (Install Poetry)
- Docker (optional): For running the bot in a container
- Clone the repository:
Replace YOUR_APP_NAME with your desired project name
git clone https://github.com/2rage/telegram_bot_boilerplate.git
mv telegram_bot_boilerplate YOUR_APP_NAME
cd YOUR_APP_NAME- Removing Git History:
rm -rf .git
git init- Set up environment variables:
-
Create a .env file by copying the example:
cp .env.example .env && rm .env.example -
Edit the
.envfile and add your configuration
- Install dependencies:
poetry install- Run the bot
make bot-dev├── Dockerfile # Docker image setup
├── Makefile # Simplified automation commands
├── README.md # Project documentation
├── app/ # Main application folder
│ ├── exceptions/ # Custom exception classes
│ │ └── base.py # Base application exception
│ ├── handlers/ # Command and message handlers
│ │ ├── base.py # Basic command handlers (e.g., /start)
│ │ └── errors.py # Error handling logic
│ ├── main.py # Entry point for the bot
│ └── settings.py # Configuration and environment variables
├── docker_compose/ # Docker Compose configuration
│ └── bot.yaml # Configuration for running the bot container
├── poetry.lock # Poetry lock file
└── pyproject.toml # Poetry configuration