An intelligent Telegram bot that leverages Google's Gemini AI model for chat interactions, image analysis, PDF summarization, and web search capabilities. The bot maintains conversation history and user data using MongoDB for a personalized experience.
- 💬 AI-powered chat with conversation memory
- 📸 Image analysis and description
- 📄 PDF document summarization
- 🔍 Web search with AI-generated summaries
- 👤 User registration with phone number verification
- 💾 Persistent storage of conversations and user data
- Python 3.8+
- Telegram Bot Token
- Google Gemini API Key
- SerpAPI Key
- MongoDB Connection String
- Clone the repository:
git clone <repository-url>
cd telegram-bot- Install required dependencies:
pip install -r requirements.txt- Create a
.envfile in the root directory with the following variables:
bot_key=YOUR_TELEGRAM_BOT_TOKEN
gemini_key=YOUR_GEMINI_API_KEY
serpapi_key=YOUR_SERPAPI_API_KEY
mongo_url=YOUR_MONGODB_CONNECTION_STRING
python-telegram-bot
google-generativeai
python-dotenv
Pillow
PyPDF2
requests
pymongo
serpapi
- Start the bot:
python main.py- In Telegram, interact with the bot using these commands:
/start- Register and set up your profile/help- View available commands and features/clear- Clear conversation history/websearch [query]- Perform web search with AI summary
- Additional Features:
- Send text messages to chat with the AI
- Send images to get AI-generated descriptions
- Share PDF files to receive summaries
- Share contact information for registration
- Maintains conversation history
- Contextual responses based on chat history
- Maximum history length of 10 messages for context
- Supports JPG/PNG formats
- Generates detailed descriptions using Gemini AI
- Stores image metadata in MongoDB
- PDF file support
- Text extraction and summarization
- Document metadata storage
- Integration with SerpAPI for web results
- AI-generated summaries of search results
- Source link preservation
- Results sorted by date
- User profiles
- Chat histories
- File metadata
- Search queries and results
The bot uses MongoDB with the following collections:
users: Stores user profiles and contact informationchats: Maintains conversation histories and contextsfiles: Stores metadata for processed files
- Comprehensive logging system
- Graceful error messages for users
- Exception handling for API failures
- Phone number verification
- Secure storage of user data
- Environment variable configuration
- API key protection
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Google Gemini AI for natural language processing
- SerpAPI for web search capabilities
- MongoDB for data storage
- Python Telegram Bot community