Skip to content

Telegram Advanced AI Bot: GPT-4.1, Qwen-3, DeepSeek-R1, Dall-E-3, Flux, Flux-Pro, Dall-E Model, OCR and Google Voice2Text.

License

Notifications You must be signed in to change notification settings

TechyCSR/AdvAITelegramBot

Repository files navigation

Advanced AI Telegram Bot

Python Telegram MongoDB License g4f

A next-generation AI-powered Telegram bot with intelligent vision, image editing, and multi-provider architecture.

Try the Bot · Report Bug · Request Feature


Overview

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.


Key Features

AI-Powered Conversations

  • 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

Vision & Image Intelligence

  • 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)

Image Generation & Editing

  • Text-to-Image — Generate images from text descriptions using /img command
  • 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

Voice & Speech

  • 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

Group & Multi-Bot

  • 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

Administration

  • 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

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                           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    │
                    └───────────────┘

Provider Fallback System

The bot implements an intelligent multi-provider fallback mechanism:

  1. Primary Provider — First attempt with the fastest/most capable provider
  2. Secondary Providers — Automatic fallback if primary fails
  3. Error Handling — Graceful degradation with user notification
  4. Load Distribution — Prevents single-point-of-failure

Quick Start

# 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.py

Configuration

Create 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

Commands

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

Image & Vision Usage

Vision Analysis:

  1. Send any image to the bot
  2. Add a caption with your question, or send without caption for general analysis
  3. Use follow-up messages to ask more questions about the same image

Image Editing:

  1. Send an image to the bot
  2. Describe the changes you want (e.g., "make the sky more blue", "add a sunset")
  3. AI automatically detects if you want editing or analysis and responds accordingly

Technology Stack

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

Project Structure

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

Deployment

Docker

# Build image
docker build -t advai-telegram-bot .

# Run container
docker run -d \
  --name advai-bot \
  --restart unless-stopped \
  advai-telegram-bot

Systemd Service

[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.target

Contributing

Contributions are welcome. Please read the Contributing Guide before submitting a pull request.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit changes (git commit -m 'Add new feature')
  4. Push to branch (git push origin feature/new-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License. See LICENSE for details.