Skip to content

Telegram Advance AI ChatBot: 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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Advanced AI Telegram Bot

Python Telegram MongoDB License





A powerful AI-driven Telegram bot that brings cutting-edge artificial intelligence features to your fingertips.

✨ Features

πŸ’¬ AI Chat
Natural conversations powered by GPT-4o and other models
🎨 Image Generation
Create stunning images from text descriptions, with /img and inline mode
πŸ”Š Voice Processing
Two-way voice message and text conversion (speech-to-text, text-to-speech)
πŸ“ Text Extraction (img2text)
Extract text, solve MCQs, and answer questions from images and documents
🌐 Multi-language Support
Communicate in your preferred language, with translation and language settings
πŸ‘₯ Group Integration
Full AI functionality in group chats, with group-specific settings
πŸ“± Inline Mode
Generate AI responses and images in any chat, with advanced inline query handling
⚑ Fast, Reliable Delivery
Optimized for quick, robust interactions, including large code/image snippets
πŸ—‚οΈ File-to-Text (img2text)
Upload images or documents and interact with their content via AI
⏳ Image Context Expiry
Uploaded images for vision/AI analysis are auto-deleted after 2 minutes (configurable)
πŸ”’ Premium Model Handling
Premium AI/image models are shown only to eligible users
πŸ›‘οΈ Admin Tools
Broadcast images (/share), code snippets (/snippet), ban/unban, premium management, logs, and more
🧩 Multi-Bot Support
Run multiple bots with isolated sessions and MongoDB fork safety
🧠 Advanced Prompting
Smart prompt logic for images, MCQs, and document Q&A

πŸ“± Try it now: t.me/AdvChatGptBot

πŸš€ Quick Start

# Clone repository
git clone https://github.com/TechyCSR/AdvAITelegramBot.git

# Navigate to directory
cd AdvAITelegramBot

# Set up virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure your bot
cp config.example.py config.py
# Edit config.py with your API credentials

# Launch!
python run.py

πŸ“‹ Commands

Command Description
/start 🏁 Start a conversation with the bot
/help ❓ Get help and see available commands
/settings βš™οΈ Adjust preferences, language, and models
/img [prompt] or /generate [prompt] 🎨 Generate an image from text
/newchat, /reset, /new, /clear_chat πŸ”„ Start a new conversation
Upload image/document πŸ“ Extract text, solve MCQs, or ask questions about content

How to use:

  • Upload an image or document in private chat to extract text, solve MCQs, or ask questions about its content. Only one image context is active per user; uploading a new image replaces the previous one. Images are auto-deleted after 2 minutes (user is notified).
  • For image generation, the bot always replies with a /img command snippet and clear copy-paste instructions.
  • All code/image snippets are delivered unbroken, using HTML formatting for reliability.

πŸ› οΈ Configuration

Edit config.py with the following fields:

BOT_TOKEN = "your_telegram_bot_token"  # From BotFather
API_KEY = "your_telegram_api_key"      # From my.telegram.org
API_HASH = "your_telegram_api_hash"    # From my.telegram.org
DATABASE_URL = "mongodb://localhost:27017/"  # MongoDB connection string
ADMINS = [123456789]  # List of Telegram user IDs with admin rights
# Optional advanced settings:
IMAGE_CONTEXT_EXPIRY_MINUTES = 2        # Minutes before uploaded images are auto-deleted
PREMIUM_MODELS = ["gpt-4o", "dalle3", ...] # List of premium models (shown only to premium users)
MULTI_BOT = True                        # Enable multi-bot support (one process per bot)
  • For multi-bot, provide multiple BOT_TOKENs and set MULTI_BOT = True.
  • For MongoDB fork safety, each process creates its own MongoClient.
  • All settings are documented in config.py.

🧠 Usage Notes

  • Image/Document Upload:

    • Upload an image or document, then ask questions, solve MCQs, or request a description.
    • If a caption is present, it is used as the prompt; otherwise, the bot will prompt the AI to answer questions, solve MCQs, or describe the image.
    • Only one image context is active per user; uploading a new image replaces the previous one.
    • Images are auto-deleted after expiry, and the user is notified.
  • AI Prompting:

    • The bot is aware of all its capabilities (text, image, vision, MCQ, document, multi-model).
    • For any image generation request, the bot always replies with a /img command snippet and clear copy-paste instructions.
  • Code/Prompt Snippets:

    • Code and image generation snippets are always delivered unbroken, using HTML formatting for reliability.

🧠 Architecture

The bot employs a modern, modular architecture with several key design patterns:

  • πŸ’‰ Service Container: Centralized dependency injection for clean, testable code
  • πŸ”„ Singleton Database Service: Efficient MongoDB connection pooling
  • πŸ“Š Model-View Pattern: Separation of data and presentation layers
  • πŸ”„ Async Processing: Non-blocking operations for inline queries and image generation

πŸ› οΈ Setup Guide

System Requirements

  • Python 3.8 or higher
  • MongoDB (local or cloud instance)
  • Telegram Bot Token from BotFather
  • 1GB+ RAM recommended for image generation

Detailed Installation

1. Environment Setup
# Make sure you have Python 3.8+ installed
python --version

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
2. Install Dependencies
# Install required packages
pip install -r requirements.txt

# Verify installations
pip list
3. Configuration

Create a config.py file with your credentials:

BOT_TOKEN = "your_telegram_bot_token"  # From BotFather
API_KEY = "your_telegram_api_key"      # From my.telegram.org
API_HASH = "your_telegram_api_hash"    # From my.telegram.org
DATABASE_URL = "mongodb://localhost:27017/"
ADMINS = [123456789]  # Your Telegram user ID
# Optional advanced settings:
IMAGE_CONTEXT_EXPIRY_MINUTES = 2        # Minutes before uploaded images are auto-deleted
PREMIUM_MODELS = ["gpt-4o", "dalle3", ...] # List of premium models (shown only to premium users)
MULTI_BOT = True                        # Enable multi-bot support (one process per bot)
4. Database Setup
# Start MongoDB (if using local instance)
mongod --dbpath /path/to/data/db

# The bot will automatically create required collections
5. Running the Bot
# Start the bot
python run.py

# For production deployment
# Consider using systemd, Docker, or PM2

πŸ”§ Advanced Configuration

Docker Deployment
# Build the Docker image
docker build -t advai-telegram-bot .

# Run the container
docker run -d --name advai-bot advai-telegram-bot
Environment Variables

You can use environment variables instead of config.py:

export BOT_TOKEN="your_telegram_bot_token"
export API_KEY="your_telegram_api_key"
export API_HASH="your_telegram_api_hash"
export DATABASE_URL="mongodb://localhost:27017/"

πŸ’» Technologies

  • Pyrogram: Modern, fast, and elegant Telegram client library for Python.
  • MongoDB: Scalable NoSQL database for user data and bot state.
  • OpenAI GPT-4o & Vision: Advanced language and vision models for text, image, and document understanding.
  • Docker: Containerization for easy deployment and scaling.
  • Python 3.8+: The core language powering all features and async operations.

🀝 Contributing

Contributions are welcome! Check out our Contributing Guide to get started.

Development Workflow
  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❀️ by @TechyCSR
Website β€’ Twitter β€’ LinkedIn