Built for a personal Advent project, this bot combines my love for coding, riddles, and the festive countdown to Christmas — all wrapped up in one fun, Python-powered experience with Christmas spirit 🎄
Each day in December unlocks a new riddle — In my setup: some written in text, others in code.
Solving a riddle reveals a unique emoji — That emoji marks the matching present waiting to be unwrapped! 🎁
This Telegram bot turns a classic self-made Advent calendar into a daily riddle challenge — because writing plain numbers on gifts felt just too boring.
(But you can easily adapt the database and logic to fit your own Advent twist!)
- 🎄 Telegram Advent Riddle Bot
- ✨ Features
- 🧠 Tech Stack
- 📁 Project Structure
- ⚙️ Prerequisites
- 💻 Installation
- 🗄️ Database Schema
- 🤖 Bot Commands
- 📄 License
- 🎁 24 Daily Riddles - Solve today's riddle with
/riddle - 🍬 Past Riddle Access - Solve previous days' riddles with
/riddle{day} - 🚫 No Spoilers - Can't access future riddles before they unlock
- 🐳 Docker Support - Easy deployment with Docker Compose
- 🌍 Timezone Aware - Configurable timezone support
- 🔄 Dual Environment - Separate development and production setups
- 📊 JSONB Answers - Multiple valid answer formats per riddle
- Language: Python 3.11
- Framework: python-telegram-bot 20.7
- Database: NeonDB (PostgreSQL)
- Deployment: Docker / Docker Compose
- Environment Management: python-dotenv
telegram-advent-calendar-bot/
├── bot.py # Production bot
├── bot_dev.py # Development bot
├── bot_core.py # Shared bot logic
├── setup_db.py # Database setup script
├── import_data.py # Data import script
├── advent_data_dev.json # Development riddles
├── advent_data_prod.json # Production riddles (excluded from git)
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── requirements.txt # Python dependencies
├── .env.dev # Development environment (excluded from git)
├── .env.prod # Production environment (excluded from git)
└── .env.example # Example environment variables
- Python 3.11+ (for local development)
- PostgreSQL database (NeonDB)
- Telegram Bot Token (from @BotFather)
- Docker & Docker Compose (for production deployment)
- Clone the repository
git clone https://github.com/justArale/telegram-advent-calendar-bot.git
cd telegram-advent-calendar-bot- Install dependencies
pip install -r requirements.txt-
Configure environment
Create
.env.devfile:
BOT_TOKEN=your_telegram_bot_token
DATABASE_URL=your_development_db_url
TIMEZONE=preferred_timezone
ENVIRONMENT=development
MONTH=current_month
ENDDAY=31- Setup database
python setup_db.py dev- Import test riddles
python import_data.py dev- Run the development bot
python bot_dev.py- Clone on your server
git clone https://github.com/justarale/telegram-advent-calendar-bot.git
cd telegram-advent-calendar-bot- Create
.env.prodfile
BOT_TOKEN=your_production_bot_token
DATABASE_URL=your_production_db_url
TIMEZONE=preferred_timezone
ENVIRONMENT=prod
MONTH=12
ENDDAY=24-
Create your production riddles
Create
advent_data_prod.jsonwith your 24 riddles (on your local project):
{
"riddles": [
{
"day_number": 1,
"riddle_text": "Your riddle here",
"answers": ["answer1", "answer2"],
"solution_content": "🎄"
}
]
}- Setup database
# On your local machine
python setup_db.py prod- Import production riddles
# On your local machine
python import_data.py prod- Build and start container
docker compose up -d --buildThe project uses three main tables:
id SERIAL PRIMARY KEY
day_number INTEGER (1-24, UNIQUE)
riddle_text TEXTid SERIAL PRIMARY KEY
riddle_id INTEGER (FOREIGN KEY → riddles.id)
answer_text JSONB (array of valid answers)id SERIAL PRIMARY KEY
riddle_id INTEGER (FOREIGN KEY → riddles.id)
solution_content TEXT (emoji or message)Relationships: Each riddle has one answers entry and one solutions entry.
| Command | Description | Availability |
|---|---|---|
/start |
Welcome message and command overview | All |
/riddle |
Get today's riddle | All |
/riddle{1-24} |
Get a specific day's riddle (e.g., /riddle5) |
All |
/list |
Show all available riddles in database | Dev only |
This project is licensed under the MIT License.