A powerful, serverless Telegram bot powered by multiple AI models (Groq, Gemini) running on Cloudflare Workers. Built for speed, scalability, and easy deployment. Focused on being your Personal Assistant, Coach and Chat buddy who gathers information from normal conversations with the bot. Capable of chatting, reminding, track habits and even store documents and media.
- π§ Multi-Model AI Support - Integrates with Groq and Google Gemini for intelligent responses
- β‘ Serverless Architecture - Runs on Cloudflare Workers for global low-latency performance
- πΎ Persistent Storage - Uses Cloudflare D1 (SQLite) for conversation history and user data
- π Context-Aware Conversations - Maintains conversation context for natural interactions
- π― Command-Based Interface - Easy-to-use commands for bot interaction
- π Secure - API keys managed through Cloudflare secrets
- π Global CDN - Deployed across Cloudflare's edge network
- Cloudflare Workers - Serverless compute platform
- Wrangler CLI - Cloudflare Workers CLI tool
- Cloudflare D1 - Serverless SQL database
- Cloudflare KV - Key-value storage for session data
- Groq API - Ultra-fast LLM inference
- Google Gemini API - Google's advanced AI model
- Telegram Bot API - Bot platform integration
- JavaScript/TypeScript - Bot logic and API integrations
- Node.js - Development environment
- β Natural language conversations with AI
- β Multi-turn conversation support with context
- β User session management
- β Command-based interactions
- β Message history storage
- β Multi-environment support (development/production)
- β Automatic webhook setup
- β Error handling and logging
- π Image generation capabilities
- π Voice message support
- π Multi-language support
- π User preferences and settings
- π Rate limiting and usage quotas
- π Analytics and usage dashboard
- π Plugin system for extensibility
- π Group chat support with mentions
- π Document analysis and summarization
- π Custom AI model integration
- Node.js 16+ installed
- Cloudflare account (sign up here)
- Telegram Bot Token (create one via @BotFather)
- Groq API Key (get one here)
- Gemini API Key (get one here)
npm install -g wranglerVerify installation and login:
wrangler whoami
wrangler logingit clone https://github.com/yourusername/telegram-ai-bot.git
cd telegram-ai-bot# Production database
wrangler d1 create telegram-ai-bot > d1_output.txt
# Development database
wrangler d1 create telegram-ai-bot-dev > d2_output.txt# Production KV
wrangler kv namespace create "telegram-ai-assistant" > kv1_output.txt
# Development KV
wrangler kv namespace create "telegram-ai-assistant-dev" > kv2_output.txtCopy the example configuration and update with your resource IDs:
cp wrangler.toml.example wrangler.tomlOpen wrangler.toml and fill in the IDs from the output files created in Step 3.
You can set secrets via CLI or Cloudflare Dashboard.
# Production secrets
wrangler secret put TELEGRAM_BOT_TOKEN --env production
wrangler secret put GROQ_API_KEY --env production
wrangler secret put GEMINI_API_KEY --env production
# Development secrets
wrangler secret put TELEGRAM_BOT_TOKEN --env development
wrangler secret put GROQ_API_KEY --env development
wrangler secret put GEMINI_API_KEY --env development- Go to Cloudflare Dashboard
- Navigate to Workers & Pages > Your Worker > Settings > Variables
- Add the secrets under Environment Variables
# Development environment
wrangler d1 migrations apply telegram-ai-bot-dev --env development --remote
# Production environment
wrangler d1 migrations apply telegram-ai-bot --env production --remote# Deploy to development
wrangler deploy --env development
# Deploy to production
wrangler deploy --env productionReplace [TELEGRAM_BOT_TOKEN] with your bot token and [WORKER-URL] with your Worker URL:
# Your worker URL format
https://<your-worker-name>.<your-subdomain>.workers.devSet the webhook:
https://api.telegram.org/bot[TELEGRAM_BOT_TOKEN]/setWebhook?url=[WORKER-URL]/webhookCheck if everything is working:
# Verify webhook
https://api.telegram.org/bot[TELEGRAM_BOT_TOKEN]/getWebhookInfo
# Verify bot
https://api.telegram.org/bot[TELEGRAM_BOT_TOKEN]/getMe
Once deployed, interact with your bot on Telegram:
/start- Initialize the bot/help- Show available commands- Just type any message to chat with the AI!
View real-time logs:
wrangler tail --env=developmentCheck your Worker status:
https://<your-worker-name>.<your-subdomain>.workers.dev
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Cloudflare Workers for the amazing serverless platform
- Groq for ultra-fast AI inference for it's generous free tier
- Google Gemini for advanced AI capabilities and image generation free tier
- Telegram for the Bot API
If you have any questions or run into issues, please open an issue on GitHub.