Skip to main content

Tutorial: Quiz Bot

Build an interactive quiz that tracks scores and shows results.


What We're Building

A fun quiz bot that:

  1. Asks multiple-choice questions
  2. Tracks correct answers
  3. Shows the final score
  4. Saves high scores

Step 1: Start the Quiz

  1. Add a Command Trigger for /quiz

  2. Add a Set Variable to initialize score:

    • flow.score = 0
  3. Add a Send Message:

🎯 Welcome to the Quiz!

You'll get 3 questions. Let's see how you do!

Ready?
[▶️ Start Quiz]

Step 2: Question 1

  1. Add a Send Message with inline buttons:
❓ Question 1/3

What is the capital of France?

[🇬🇧 London] [🇫🇷 Paris] [🇩🇪 Berlin]

Callback data: q1_london, q1_paris, q1_berlin

  1. Add a Message Trigger for callbacks starting with q1_

  2. Add a Condition:

    • Expression: ctx.Input == "q1_paris"
  3. If True:

    • Add 1 to score: flow.score + 1
    • Send: ✅ Correct! Paris is the capital of France.
  4. If False:

    • Send: ❌ Not quite! The answer was Paris.

Step 3: Questions 2 & 3

Repeat the pattern:

Question 2

❓ Question 2/3

What is 7 × 8?

[54] [56] [64]

Correct: 56

Question 3

❓ Question 3/3

Which planet is known as the Red Planet?

[Venus] [Mars] [Jupiter]

Correct: Mars


Step 4: Show Results

After all questions:

Results Message:

🎉 Quiz Complete!

Your score: {{flow.score}}/3

{{flow.score == 3 ? "🏆 Perfect score! You're a genius!" :
flow.score >= 2 ? "👍 Great job!" : "📚 Keep practicing!"}}

Play again? [🔄 Restart]

Step 5: Save High Score

  1. Add a Condition: flow.score > var.high_score
  2. If True:
    • Set var.high_score = {{flow.score}}
    • Add message: 🌟 New high score!

The Complete Flow


Enhancements

Randomize Questions

Store questions in a list and use Random to pick:

[
{"q": "Capital of France?", "a": "Paris", "options": ["London", "Paris", "Berlin"]},
{"q": "7 × 8?", "a": "56", "options": ["54", "56", "64"]}
]

Time Limits

Add urgency with a timer message:

⏱️ You have 10 seconds!

Leaderboard

Track top scores in shared variables:

🏆 Leaderboard:
1. @alice - 10 points
2. @bob - 8 points
3. @charlie - 7 points

Your rank: #5

Categories

Let users choose quiz topics:

Choose a category:
[🌍 Geography] [🔢 Math] [🎬 Movies] [🎵 Music]

Tips

Make It Fun

Use emojis, celebrate correct answers, and keep a playful tone!

Progressive Difficulty

Start easy, get harder — keeps users engaged.

Share Feature

Let users share their scores on Telegram.


Next Steps