AI-Powered Telegram Trivia Bot with Auto Question Generation & User Management โ€” n8n Workflow

High complexityโšก Trigger31 nodes๐Ÿท๏ธ Miscellaneous๐Ÿ‘ 2,658 viewsby Luka Zivkovic

Overview

Complete Telegram Trivia Bot with AI Question Generation

Build a fully-featured Telegram trivia bot that automatically generates fresh questions daily using OpenAI and tracks user progress with NocoDB. Perfect for communities, education, or entertainment!

Get Started with n8n now!

โœจ Key Features

๐Ÿค– AI Question Generation: Automatically creates 40+ new trivia questions daily across 8 categories ๐Ÿ“Š Smart User Management: Tracks scores, prevents question repeats, maintains leaderboards ๐ŸŽฎ Game Mec

Nodes used

TelegramNocoDBCodeOpenAI

Workflow Preview

๐Ÿ“Š NocoDB Database Setup Required
Table 1: Users
- `Id` - Auto Number (Primary Key)
- `telegram_id` - Number (Unique)
- `username` - Single Line Text
- `first_name` - Single Line Text
๐Ÿค– AI Question Generation System
Purpose: Automatically generates fresh trivia questions
Schedule: Runs once per day
Output: 5 questions per category (8 categories = 40 que
๐Ÿ“จ Message Processing Pipeline
Step 1: Telegram webhook receives message
Step 2: Parse user data and message content
Step 3: Check if user exists in database
Step 4: Create new
๐ŸŽฎ Smart Question System
Features:
โœ… No Repeats: Users never see correctly answered questi
โœ… History Tracking: Every answer is logged
โœ… Dynamic Selection: Always fresh
๐Ÿ“Š Leaderboard System
Features:
- Top 10 players by score
- Shows current user's position
- Real-time ranking updates
- Emoji medals for top 3
โœ… Answer Processing Engine
Input Validation:
- Only accepts A, B, C, D answers
- Must be in "waiting_answer" state
- Case-insensitive processing
Scoring System:
๐Ÿ”„ Game State Management
States:
- `idle` - Ready for new question
- `waiting_answer` - Question active, awaiting response
Tracking:
- Current question ID
๐Ÿ“ค Response System
Features:
- Markdown formatting for rich messages
- Emoji integration for visual appeal
- Consistent message structure
- Error handling and fallbacks
๐ŸŽฒ Question History Tracking
Purpose: Ensures users never see the same correctly ans
Process:
1. Get user's answer history
2. Collect all correctly answered questio
๐Ÿ”„ Data Flow Summary
Input: Telegram message
Processing:
1. Parse & validate user
2. Route command or answer
3. Process business logic
tool
โšก
T
Telegram Trigger
Parse Telegram Data
Check Existing User
U
User Exists?
Create New User
Merge User Data
I
Is Command?
C
Command Router
Handle Basic Commands
Format Question
Update User Game State
Get Leaderboard
Format Leaderboard
V
Valid Answer?
Get Current Question
Process Answer
Update User Stats
Handle Unknown Text
Telegram
M
Merge
OpenAI
N
NocoDB
โšก
D
Daily Question Generator
Get Possible Categories
Send New Questions Availโ€ฆ
M
Merge1
A
Aggregate
Get User History
Mark Question As Answered
A
Aggregate1
Get Random Question
31 nodes39 edges

How it Works

  1. 1

    Trigger

    The workflow starts with a trigger trigger.

  2. 2

    Process

    Data flows through 31 nodes, connecting aggregate, code, if.

  3. 3

    Output

    The workflow completes its automation and delivers the result to the configured destination.

Node Details (31)

TE

Telegram

telegram

#1
NO

NocoDB

nocoDb

#2
CO

Code

code

#3
OP

OpenAI

n8n-nodes-langchain.openAi

#4

How to Import This Workflow

  1. 1Click Download JSON button on the right to save the workflow file.
  2. 2Open your n8n instance. Go to Workflows โ†’ New โ†’ Import from file.
  3. 3Select the downloaded ai-powered-telegram-trivia-bot-with-auto-question-generation-user-management file and click Import.
  4. 4Set up credentials for each service node (API keys, OAuth, etc.).
  5. 5Click Test Workflow to verify everything works, then activate it.

Or paste directly in n8n โ†’ Import from JSON:

{ "name": "AI-Powered Telegram Trivia Bot with Auto Question Generation & User Management", "nodes": [...], ...}

Integrations

aggregatecodeifmergenocodbnocodbtoolopenaischeduletriggerswitchtelegramtelegramtrigger

Get This Workflow

Download and import in one click

Download JSONView on n8n.io
Nodes31
Complexityhigh
Triggertrigger
Views2,658

Created by

Luka Zivkovic

Luka Zivkovic

@zivkovic58

Tags

aggregatecodeifmergenocodbnocodbtoolopenaischeduletriggerswitchtelegram
โšก

New to n8n?

n8n is a free, open-source workflow automation tool. Self-host it or use the cloud version.

Get n8n Free โ†’

Related Miscellaneous Workflows