A next-generation AI-powered Telegram bot with intelligent vision, image editing, and multi-provider architecture.
Advanced AI Telegram Bot is a feature-rich, production-ready bot that leverages multiple AI providers to deliver intelligent conversations, image generation, vision analysis, and image editing capabilities. Built with a robust multi-provider fallback system ensuring high availability and reliability.
- Multi-Model Support — GPT-4o, DeepSeek, Qwen, Llama, and more
- Context-Aware Chat — Maintains conversation history for natural dialogue
- System Prompt Versioning — Ensures all users receive the latest AI behavior updates
- Smart Response Formatting — Proper markdown/HTML rendering with code block support
- AI Vision Analysis — Upload any image and ask questions about it
- Multi-Provider Vision — DeepInfra, Qwen, HuggingFace, DeepSeek Janus, Pollinations
- Document Processing — Extract text, solve MCQs, analyze PDFs and documents
- Follow-up Questions — Continue asking about the same image (configurable uses)
- Text-to-Image — Generate images from text descriptions using
/imgcommand - AI-Driven Image Editing — Send an image and describe changes; AI intelligently decides whether to edit or analyze
- Multi-Provider Image Generation — Flux, DALL-E, Pollinations with automatic fallback
- Inline Mode — Generate images in any chat using inline queries
- Speech-to-Text — Send voice messages for AI transcription and response
- Text-to-Speech — Convert AI responses to voice messages
- Multi-language Voice Support — Process voice in multiple languages
- Full Group Integration — AI works seamlessly in group chats with mentions
- Per-Group Settings — Customize AI behavior for each group
- Multi-Bot Architecture — Run multiple bot instances with isolated sessions
- MongoDB Fork Safety — Each process maintains its own database connection
- User Management — Ban, unban, premium status control
- Broadcast System — Send announcements to all users
- Statistics Dashboard — Track usage, active users, and performance
- Maintenance Mode — Gracefully handle updates and downtime
┌─────────────────────────────────────────────────────────────────────┐
│ User Interfaces │
├──────────────────┬──────────────────┬───────────────────────────────┤
│ Telegram Chat │ Inline Mode │ Web App │
└────────┬─────────┴────────┬─────────┴───────────────┬───────────────┘
│ │ │
└──────────────────┴─────────────────────────┘
│
┌───────▼───────┐
│ Bot Core │
│ Request Queue │
└───────┬───────┘
│
┌───────────────────┼───────────────────┐
│ │ │
┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐
│ Text AI │ │ Vision AI │ │ Image AI │
│ │ │ │ │ │
│ • GPT-4o │ │ • DeepInfra │ │ • Flux │
│ • DeepSeek │ │ • Qwen VL │ │ • DALL-E │
│ • Qwen │ │ • HuggingFace │ │ • Pollinations│
│ • Llama │ │ • Janus Pro │ │ • Kontext │
└───────┬───────┘ └───────┬───────┘ └───────┬───────┘
│ │ │
└───────────────────┼───────────────────┘
│
┌───────▼───────┐
│ MongoDB │
│ Database │
└───────────────┘
The bot implements an intelligent multi-provider fallback mechanism:
- Primary Provider — First attempt with the fastest/most capable provider
- Secondary Providers — Automatic fallback if primary fails
- Error Handling — Graceful degradation with user notification
- Load Distribution — Prevents single-point-of-failure
# Clone the repository
git clone https://github.com/TechyCSR/AdvAITelegramBot.git
cd AdvAITelegramBot
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure the bot
cp config.example.py config.py
# Edit config.py with your credentials
# Run
python run.pyCreate config.py with the following structure:
# Required
BOT_TOKEN = "your_bot_token" # From @BotFather
API_KEY = "your_api_id" # From my.telegram.org
API_HASH = "your_api_hash" # From my.telegram.org
DATABASE_URL = "mongodb://localhost:27017/"
# Admin Configuration
ADMINS = [123456789] # Telegram user IDs with admin rights
# Optional Settings
IMAGE_CONTEXT_EXPIRY_MINUTES = 2 # Auto-delete uploaded images
IMAGE_CONTEXT_MAX_USES = 5 # Follow-up questions per image
MULTI_BOT = False # Enable multi-bot mode
PREMIUM_MODELS = ["gpt-4o", "dall-e-3"] # Premium-only models| Command | Description |
|---|---|
/start |
Initialize conversation with the bot |
/help |
Display available commands and usage |
/settings |
Configure language, model, and preferences |
/img [prompt] |
Generate an image from text description |
/newchat |
Clear conversation history and start fresh |
/endimage |
Clear current image context |
/model |
Select AI model for conversations |
Vision Analysis:
- Send any image to the bot
- Add a caption with your question, or send without caption for general analysis
- Use follow-up messages to ask more questions about the same image
Image Editing:
- Send an image to the bot
- Describe the changes you want (e.g., "make the sky more blue", "add a sunset")
- AI automatically detects if you want editing or analysis and responds accordingly
| Component | Technology |
|---|---|
| Framework | Pyrogram (async Telegram client) |
| Database | MongoDB |
| AI Providers | g4f (GPT4Free), OpenAI, DeepInfra, HuggingFace |
| Image Generation | Flux, DALL-E, Pollinations, BlackForestLabs |
| Vision Models | Llama Vision, Qwen VL, Janus Pro |
| Deployment | Docker, systemd |
AdvAITelegramBot/
├── run.py # Application entry point
├── config.py # Configuration settings
├── modules/
│ ├── models/ # AI response handlers
│ │ ├── ai_res.py # Main AI response logic
│ │ └── multi_provider_text.py
│ ├── image/ # Image processing
│ │ ├── img_to_text.py # Vision & image editing
│ │ └── image_generation.py
│ ├── speech/ # Voice processing
│ ├── user/ # User commands
│ ├── admin/ # Admin tools
│ ├── group/ # Group features
│ └── core/ # Core utilities
├── database/ # Database models
├── webapp/ # Web application
└── tests/ # Test suite
# Build image
docker build -t advai-telegram-bot .
# Run container
docker run -d \
--name advai-bot \
--restart unless-stopped \
advai-telegram-bot[Unit]
Description=Advanced AI Telegram Bot
After=network.target mongodb.service
[Service]
Type=simple
User=bot
WorkingDirectory=/path/to/AdvAITelegramBot
ExecStart=/path/to/.venv/bin/python run.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetContributions are welcome. Please read the Contributing Guide before submitting a pull request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit changes (
git commit -m 'Add new feature') - Push to branch (
git push origin feature/new-feature) - Open a Pull Request
This project is licensed under the MIT License. See LICENSE for details.