A modern and developer-friendly starter template to build Telegram bots using FastAPI and python-telegram-bot.
- ⚡ FastAPI based async webhook handling
- 🤖 python-telegram-bot v20+ support
- 🧱 Well-organized folder structure
- 🔌 CLI commands to manage the server and webhooks
- 📁
.envbased configuration - 🧪 Ready for deployment (Uvicorn, Docker optional)
src/
├── config/ # Settings, environment variables
│ └── settings.py
├── controllers/ # Telegram webhook controller
│ └── webhook.py
├── core/ # Lifespan handlers, utilities
│ └── lifespan.py
├── services/ # Main bot logic
│ ├── bot.py # Bot application
│ └── cli.py # CLI application
│ main.py # FastAPI app instance
├── .env.example # Example environment variables
├── run.py # CLI runner (runserver, set-webhook, etc)
git clone https://github.com/abdul-rozzaq/fastapi-telegram-bot.git
cd fastapi-telegram-botcp .env.example .envFill in your .env file:
BOT_TOKEN=your_bot_token
WEBHOOK_DOMAIN=https://yourdomain.compython run.py runserver# Set Telegram webhook
python run.py set-webhook
# Delete Telegram webhook
python run.py delete-webhookHere’s how the project looks inside VSCode:
- FastAPI
- python-telegram-bot
- Uvicorn
- Python 3.10+
Telegram bot development usually starts with:
- Rewriting webhook logic
- Copy-pasting CLI tools
- Manually testing endpoint lifecycle
This template removes all the friction and lets you focus on building features.
- Add example handlers (start/help commands)
- Docker support
- Add logging
- Deployment guides (Railway, Render, etc)
Pull requests, issues and ideas are welcome!
If you find this useful, consider giving it a ⭐ star.
MIT License.
Free to use, modify, and share.

