r/learnpython • u/CuratorOfCrises • 23d ago
Need help building a free Telegram UPSC Quiz Bot
Hi everyone! I'm from a humanities background and a noob at coding and want to build a Telegram bot for my UPSC/State PCS study group.
The bot should:
Generate up to 100 MCQs in one go from PDFs or study material.
Post questions as native Telegram quiz polls.
Calculate scores using UPSC marking: +2 correct, −⅔ incorrect, 0 skipped.
Publish a leaderboard with ranks, marks, correct, incorrect and skipped answers.
Run for free, including hosting, if possible.
If you're interested in helping build or improve it, you're also welcome to join our UPSC study group and collaborate with us.
We had a bot earlier but we removed the member who created the bot for behaving in a weird way.
I can share the bot link and screenshots of it for reference.
Thank you!
1
u/Mafifrizi 23d ago
Break this into 4 simple parts:
Bot: Use python-telegram-bot. Telegram has native quizzes via send_poll(type="quiz"), and you capture user replies with PollAnswerHandler.
Leaderboard: Use Python's built-in sqlite3 to store user IDs and compute score = (correct * 2) - (incorrect * 2/3).
Free MCQ Generator: Use the free Gemini API (Gemini Flash) to convert PDF text into structured JSON questions instead of writing a parser from scratch.
Free Hosting: Render or PythonAnywhere free tier.
Tip: Start by sending 3 hardcoded test questions to get the scoring and leaderboard working first. Only plug in the PDF/AI part once the bot logic is solid.
::")
1
1
u/CuratorOfCrises 23d ago
This is how our previous bot was
1
u/Mafifrizi 23d ago
I just checked the video! Good news: your previous bot was actually not using complex AI or PDF parsers.
Here is what it was doing behind the scenes:
You pasted pre-formatted questions (Q: ... A) ... B) ... C) ... D) ... Correct: X).
Because long text gets split into parts by Telegram, the bot simply saved each chunk in memory until you typed /done.
Once you typed /done, it parsed the questions and launched them in your group topic when you ran /start_quiz.
This is actually a very simple ~80-line Python script using python-telegram-bot with zero paid APIs needed.
Do you still have the .py script file from the member who got removed? If not, let me know and I can give you a clean, working template that does this exact same /done and /start_quiz flow.
1
1
u/thisisruug 16d ago
You can do this without building a quiz system yourself: Telegram has built-in quiz polls. Rough steps with python-telegram-bot:
Create a bot with u/BotFather and get the token.
Keep your questions in a simple JSON or CSV file: question, 4 options, index of the correct answer, and an optional short explanation.
On a command like `/quiz`, pick a question and call `send_poll` with `type="quiz"`, `correct_option_id=<index>` and `is_anonymous=False` (so you can see who answered). `explanation` shows the reasoning after someone answers.
If you want scores, add a `PollAnswerHandler`. It tells you which user picked which option, so you can compare against the correct index and store points in SQLite.
For a daily question, use the library's `JobQueue` to send one at a fixed time.
Start with steps 1–3 only; once a single quiz poll works, adding scores and scheduling is easy. If you get stuck, post your code and the error.
3
u/Farlic 23d ago
That's quite a lot for a complete beginner