A powerful Telegram bot that implements the Leitner spaced repetition system for language learning, powered by Cloudflare Workers and Google's Gemini AI.
🎯 Smart Vocabulary Learning
- Automatic word extraction from any topic using AI
- Multi-language support (19+ languages)
- Intelligent spaced repetition using the Leitner system
- Manual word addition with AI-generated definitions
📊 Progress Tracking
- 5-box Leitner system implementation
- Study statistics and accuracy tracking
- Daily study streaks
- Progress visualization
🔔 Smart Reminders
- Customizable daily reminder times
- Intelligent scheduling based on card due dates
- Automatic reminder system
🌐 Multi-language Support
- 19 supported languages including English, Spanish, French, German, Russian, Chinese, Japanese, and more
- Automatic language detection
- Source and target language configuration
- Telegram Bot Token: Get one from @BotFather
- Google Gemini API Key: Get one from Google AI Studio
- Cloudflare Account: Sign up at cloudflare.com
- Node.js: Version 18+ installed locally
- GitHub Repository: For automatic deployment
-
Fork or clone this repository to GitHub
-
Run the setup script:
# On Windows ./setup-github-actions.bat # On macOS/Linux chmod +x setup-github-actions.sh ./setup-github-actions.sh
-
Set up GitHub Secrets: Go to your GitHub repository → Settings → Secrets and variables → Actions
Add these secrets:
CLOUDFLARE_API_TOKEN- Get from Cloudflare dashboardCLOUDFLARE_ACCOUNT_ID- Your Cloudflare account IDTELEGRAM_BOT_TOKEN- Your Telegram bot tokenGEMINI_API_KEY- Your Google Gemini API keyWEBHOOK_SECRET- Any random stringWORKER_DOMAIN- Your worker domain (e.g.,leitner-telegram-bot.your-subdomain.workers.dev)
-
Set up Cloudflare Environment Variables: In Cloudflare dashboard → Workers & Pages → Your Worker → Settings → Variables:
TELEGRAM_BOT_TOKENGEMINI_API_KEYWEBHOOK_SECRET
-
Push to GitHub:
git add . git commit -m "Initial deployment" git push origin main
Your bot will automatically deploy! 🚀
- Clone and setup the project:
npm install-
Configure environment variables in Cloudflare:
TELEGRAM_BOT_TOKEN: Your Telegram bot tokenGEMINI_API_KEY: Your Google Gemini API keyWEBHOOK_SECRET: A random secret for webhook security
-
Create KV namespace:
npx wrangler kv:namespace create "LEITNER_DB"
npx wrangler kv:namespace create "LEITNER_DB" --preview-
Update wrangler.toml with your KV namespace IDs
-
Deploy to Cloudflare Workers:
npm run deploy- Set up the webhook:
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \
-H "Content-Type: application/json" \
-d '{"url": "https://your-worker.your-subdomain.workers.dev/webhook"}'/start- Welcome message and setup/help- Show all available commands/study- Start a review session/add <word> <translation>- Manually add a word/topic <subject>- Generate vocabulary from a topic/stats- View your learning statistics/settings- Configure languages and reminders/languages- List supported languages
The bot supports multiple interface languages:
- English (en) - Default
- Persian/Farsi (fa) - فارسی
- Arabic (ar) - العربية
- Spanish (es) - Español
- Russian (ru) - Русский
Users can change the interface language via /settings → Interface Language.
Access the admin dashboard at: https://your-worker.your-subdomain.workers.dev/admin
Default Admin Credentials:
- Username:
admin - Password: Set via
ADMIN_PASSWORDenvironment variable/secret
Admin features include:
- User management and analytics
- Bulk word assignments
- Direct messaging to users
- Support ticket management
- System monitoring and reports
For detailed admin setup instructions, see ADMIN_SETUP.md.
-
Generate vocabulary from a topic:
/topic cookingThe bot will extract 10 cooking-related words with translations and definitions.
-
Add words manually:
/add bonjour hello -
Start studying:
/studyReview cards using the interactive interface.
The Leitner system uses 5 boxes with increasing review intervals:
- Box 1: Review daily (new words)
- Box 2: Review every 2 days
- Box 3: Review every 4 days
- Box 4: Review every 8 days
- Box 5: Review every 16 days (mastered words)
When you get a word correct, it moves to the next box. When incorrect, it goes back to Box 1.
English, Spanish, French, German, Italian, Portuguese, Russian, Chinese, Japanese, Korean, Arabic, Hindi, Turkish, Polish, Dutch, Swedish, Danish, Norwegian, Finnish
- Cloudflare Workers: Serverless runtime for the bot
- Cloudflare KV: Data storage for users, cards, and sessions
- Google Gemini AI: Word extraction and translation
- Telegram Bot API: User interface
The project includes GitHub Actions for automatic deployment:
- Simple Deployment: Deploys on push to main/master branch
- CI/CD Pipeline: Includes testing, staging, and production environments
See DEPLOYMENT.md for detailed setup instructions.
npm run devThis project includes comprehensive monitoring and logging capabilities:
# View live logs with pretty formatting
npm run logs:live
# View raw logs
npm run logs
# Search logs for specific terms
npm run logs:search "ERROR"# Check service status
npm run health
# Debug endpoint
curl https://your-worker.your-subdomain.workers.dev/debug- Analytics Engine Integration: Track all bot events and performance metrics
- Real-time Error Tracking: Immediate notification of issues
- Performance Monitoring: Request times, success rates, and resource usage
- User Activity Analytics: Command usage patterns and engagement metrics
- Custom Dashboards: Visual monitoring of key metrics
# Local development with enhanced logging
npm run debug
# View analytics data
npm run analyticsFor detailed monitoring setup and troubleshooting, see docs/logging-monitoring.md
npm run buildnpm run deploySet these in your Cloudflare Workers dashboard:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
GEMINI_API_KEY=your_gemini_api_key
WEBHOOK_SECRET=your_webhook_secret
The bot includes automatic daily reminders configured in wrangler.toml:
[triggers]
crons = ["0 8,14,20 * * *"] # 8 AM, 2 PM, and 8 PM daily- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the documentation
- Open an issue on GitHub
- Contact support
Built with ❤️ using Cloudflare Workers and Google AI