- Created Docker configuration files for development and production. - Added Dockerfile for building the bot image. - Implemented configuration loading from environment variables. - Developed main application logic and command handlers. - Included README with setup instructions and usage details. - Added .gitignore and .dockerignore files to exclude unnecessary files. - Provided example environment file (.env.example) for bot token configuration. - Established basic error handling for the bot.
1.9 KiB
Duty Teller (Telegram Bot)
A minimal Telegram bot boilerplate using python-telegram-bot v22 with the Application API.
Get a bot token
- Open Telegram and search for @BotFather.
- Send
/newbotand follow the prompts to create a bot. - Copy the token BotFather gives you.
Setup
-
Clone and enter the project
cd duty-teller -
Create a virtual environment (recommended)
python -m venv venv source venv/bin/activate # Linux/macOS # or: venv\Scripts\activate # Windows -
Install dependencies
pip install -r requirements.txt -
Configure the bot
cp .env.example .envEdit
.envand setBOT_TOKENto the token from BotFather.
Run
python main.py
The bot runs in polling mode. Send /start or /help to your bot in Telegram to test.
Run with Docker
Ensure .env exists (e.g. cp .env.example .env) and contains BOT_TOKEN.
-
Dev (volume mount; code changes apply without rebuild):
docker compose -f docker-compose.dev.yml up --buildStop with
Ctrl+Cordocker compose -f docker-compose.dev.yml down. -
Prod (no volume; runs the built image; restarts on failure):
docker compose -f docker-compose.prod.yml up -d --buildFor production deployments you may use Docker secrets or your orchestrator’s env instead of a
.envfile.
Project layout
main.py– Builds theApplication, registers handlers, runs polling.config.py– LoadsBOT_TOKENfrom env; exits if missing.handlers/– Command and error handlers; add new handlers here.requirements.txt– Pinned dependencies (PTB with job-queue, python-dotenv).
To add commands, define async handlers in handlers/commands.py (or a new module) and register them in handlers/__init__.py.