A production-grade Telegram quiz platform β create, manage, and run interactive quizzes at scale.
Originally developed by devgagan Β β’Β Sponsored by Qzio
π€ Try the Live Bot β @advance_quiz_bot
- Features
- Architecture
- Prerequisites
- Quick Start
- Configuration Reference
- Running the Platform
- Docker Deployment
- Mini App β the Visual Quiz Player
- Database
- Credits
| Category | Capability |
|---|---|
| Quiz Creation | Text input, forwarded Telegram quiz polls, file/PDF import, AI-generated quizzes |
| Quiz Formats | Standard, sectional (per-section timers), practice & exam modes |
| Smart Filtering | Strips [1/100]-style progress tags, usernames, links, and custom word lists from imported polls |
| Editing | Shuffle questions, retitle, adjust timers, add/remove questions |
| Access Control | Free and paid quiz tiers, batch access, auth-chat lists, optional premium gate |
| Analytics | Per-user performance, leaderboards, sectional score breakdowns |
| HTML Reports | Self-contained interactive HTML scorecards β question navigator, KaTeX/Markdown rendering, dark/light theme |
| Mini App | Visual in-Telegram quiz player (practice + exam mode) as a Telegram WebApp |
| Inline Sharing | Share any quiz by ID via inline query, with a working Play button |
| Payments | Razorpay-backed premium plans |
| Broadcast | Send announcements to all users (owner only) |
quizbot/
βββ database/ Shared async MongoDB layer
β βββ db.py Motor connection manager + automatic index setup
β βββ repositories.py One repository class per domain (users, quizzes, payments, ...)
β
βββ shared/ Code shared by both bots
β βββ config.py All configuration & secrets, loaded from .env
β βββ utils/ Text cleanup, premium checks, async file I/O
β βββ html/ Quiz-report HTML generator (exam UI + analysis)
β
βββ creator_bot/ Pyrogram bot β quiz creation, editing, batches, payments
β βββ bot.py Client setup + run_creator_bot()
β βββ handlers/ One module per feature area
β
βββ runner_bot/ python-telegram-bot bot β playing quizzes, AI generation
β βββ bot.py Application setup + run_runner_bot()
β βββ handlers/ One module per feature area
β
βββ mini_app/ FastAPI Mini App β the visual "Play" quiz player
βββ telegram_auth.py Verifies Telegram WebApp initData (HMAC-SHA256)
βββ player_service.py Play-session state, scoring, DB persistence
βββ routes.py FastAPI app + /api/* endpoints
βββ static/index.html Single-file frontend (practice + exam mode UI)
run.py Combined launcher β starts both bots (+ Mini App, if configured)
requirements.txt
Procfile Heroku process declaration (single web dyno)
Dockerfile / docker-compose.yml
.env.example Environment variable template
Everything runs from one process (run.py) by default, sharing a single async MongoDB database:
- Creator Bot (Pyrogram) handles quiz creation, editing, imports, batches, and payments.
- Runner Bot (python-telegram-bot) handles quiz sessions β sending polls, tracking answers, building leaderboards.
- Mini App (FastAPI, optional) serves a visual in-Telegram quiz player when a public domain is configured.
| Requirement | Minimum Version | Notes |
|---|---|---|
| Python | 3.11+ | |
| MongoDB | Atlas free tier (M0) or self-hosted | MONGODB_URI in .env |
| Telegram API credentials | β | From my.telegram.org |
| Two Telegram bot tokens | β | same token for both runner and creator u can keep seperate too |
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
nano .env # fill in your values β see Configuration Reference below
python run.pyThe database and all its indexes are created automatically on first connect β no manual schema step needed.
All values live in .env (copy from .env.example). Note: you must not expose these values in the repo you fork directly otherwise you may loose your bot, data (securely fill these vars and secret in the environment of the platform you are using)
| Variable | Required | Description |
|---|---|---|
API_ID / API_HASH |
β | Telegram API credentials from my.telegram.org |
CREATOR_BOT_TOKEN |
β | Token for the Pyrogram bot (creation, editing, payments) |
RUNNER_BOT_TOKEN |
β | Token for the PTB bot (playing, scheduling, AI generation) |
MONGODB_URI |
β | MongoDB Atlas connection string |
MONGODB_DB_NAME |
β | Database name (default: quizbot) |
OWNER_ID |
β | Your Telegram user ID |
ADMIN_IDS |
β | Space-separated additional admin user IDs |
LOG_GROUP |
β | Negative chat ID for error/log channel |
BOT_GROUP |
β | Main community group ID |
CHANNEL_ID |
β | Announcement channel ID |
REQUIRED_SUB_CHANNEL |
β | Channel users must join to use /start, /create, /myquizzes, /add |
FREE_BOT |
β | true to treat every user as premium |
RAZORPAY_KEY_ID / RAZORPAY_KEY_SECRET |
β | Leave blank to disable the /pay premium-purchase flow |
PDF_API_BASE |
β | Optional external PDF-generation microservice for /testseries |
MINI_APP_DOMAIN |
β | Public HTTPS URL for the Mini App β leave blank to disable it entirely |
MINI_APP_HOST / MINI_APP_PORT |
β | Local bind address behind your reverse proxy (default 0.0.0.0:8080) |
OPENROUTER_DEFAULT_KEYS |
β | Comma-separated fallback AI provider keys |
Rate limits, session timeouts, and other tuning knobs have sensible defaults β see the comments in .env.example for the full list.
python run.pyStarts both bots, and the Mini App server too if MINI_APP_DOMAIN is set.
python run.py --only creator # Creator Bot only
python run.py --only runner # Runner Bot only
python run.py --only miniapp # Mini App server onlysudo nano /etc/systemd/system/quizbot.service[Unit]
Description=Quizbot Platform
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/quizbot
ExecStart=/opt/quizbot/.venv/bin/python run.py
Restart=always
RestartSec=10
EnvironmentFile=/opt/quizbot/.env
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now quizbot
sudo journalctl -u quizbot -f # live logsdocker compose up -d --buildThis starts the Creator Bot, Runner Bot, and (if MINI_APP_DOMAIN is set) the Mini App as separate containers, each connecting out to the same MongoDB Atlas cluster via MONGODB_URI β no local volume needed, since nothing is stored on the container's own filesystem.
To skip the Mini App entirely:
docker compose up -d --build creator-bot runner-botHeroku / other PaaS: a single Procfile (web: python run.py) runs the whole platform from one dyno/process β set the same .env variables as Config Vars.
A "Play" button (opened as a Telegram WebApp) appears after quiz creation and on inline-share cards, offering two modes:
- Practice mode β instant correct/incorrect feedback with the explanation shown right after each answer, then auto-advance.
- Exam mode β no answers revealed until the end, followed by a full top-to-bottom review of every question, your answer, the correct answer, and the explanation.
It's strictly a player β no creation or editing happens here, and it enforces the same access rules as both bots (free/paid quizzes, batch access, auth-chat lists, optional premium gate).
Telegram requires a public HTTPS URL for WebApp buttons, so put a reverse proxy or tunnel (nginx, Caddy, Cloudflare Tunnel, etc.) in front of the FastAPI server and set MINI_APP_DOMAIN accordingly. Leave it blank to disable the feature entirely β no Play buttons are shown, and the server doesn't start.
Identity comes solely from Telegram's own initData, verified server-side via HMAC-SHA256 on every request. Quiz content in every API response is AES-256-GCM encrypted with a per-session key, and the correct answer is never present in a question's payload before it's answered.
Data lives in MongoDB Atlas β a free M0 cluster is enough to get started (see Quick Start). quizbot/database/db.py connects via Motor and creates every required index automatically on first connect, so there's no manual schema step. Both bots read and write through repository classes in quizbot/database/repositories.py β there's no separate API layer to keep in sync.
| Role | |
|---|---|
| Originally developed by | devgagan |
| Sponsored by | Qzio β The Smart Quiz Platform |
| Telegram Libraries | Pyrogram & python-telegram-bot |
| Database | MongoDB Atlas |
Built for educators, exam aspirants, and quiz creators.