Sexy Django + python-telegram-bot + Celery + Redis + Postgres + Dokku + GitHub Actions template. Production-realy Telegram bot with database, admin panel and a bunch of useful built-in methods.
Check the example bot that uses the code from Main branch: t.me/djangotelegrambot
- Database: Postgres, Sqlite3, MySQL - you decide!
- Admin panel (thanks to Django)
- Background jobs using Celery
- Production-ready deployment using Dokku
- Telegram API usage in pooling or webhook mode
- Reverse geocode of user via ArcGis
- Export all users in
.csv - Native telegram commands in menu
Built-in Telegram bot methods:
/broadcast— send message to all users (admin command)/export_users— bot sends you info about your users in .csv file (admin command)/stats— show basic bot stats/ask_for_location— log user location when received and reverse geocode it to get country, city, etc.
Check out our Wiki for more info.
The fastest way to run the bot is to run it in pooling mode using SQLite database without all Celery workers for background jobs. This should be enough for quickstart:
git clone https://github.com/ohld/django-telegram-bot
cd django-telegram-botCreate virtual environment (optional)
python3 -m venv dtb_venv
source dtb_venv/bin/activateInstall all requirements:
pip install -r requirements.txt
Create .env file in root directory and copy-paste this:
DJANGO_DEBUG=True
DATABASE_URL=sqlite:///db.sqlite3
TELEGRAM_TOKEN=<ENTER YOUR TELEGRAM TOKEN HERE>Run migrations to setup SQLite database:
python manage.py migrateCreate superuser to get access to admin panel:
python manage.py createsuperuserRun bot in pooling mode:
python run_pooling.py If you want to open Django admin panel which will be located on http://localhost:8000/tgadmin/:
python manage.py runserverIf you like docker-compose you can check full instructions in our Wiki.
Read Wiki page on how to deploy production-ready scalable Telegram bot using Dokku.