How shadabansari794/telegramragbot works
Project type and purpose
• This is a Python-based Telegram Channel AI Chat Bot.
• Purpose: fetch messages from one or more Telegram channels, index them in a vector database for semantic search, and answer user queries (date-based or topical) by invoking OpenAI’s GPT.
File structure
• Top-level files:
• README.md – project overview, setup and usage
• bot.py – application entrypoint
• config.py – configuration loader (reads .env, holds API keys and settings)
• llm_client.py – wrapper around OpenAI API calls
• vector_store.py – abstraction for vector database (e.g., FAISS, Pinecone)
• telegram_client.py – low-level interface to Telegram API (session/auth)
• telegram_bot_handler.py – logic for responding to Telegram bot commands (/start, /setchannel, /help, /status)
• message_processor.py – core business logic: fetches messages, indexes them, answers queries by orchestrating vector_store & llm_client
Additional README insights
• Uses Python 3.8+, Telegram API credentials, Bot Token, OpenAI API Key
• Key flows: authentication, message ingestion, vector indexing, question handling, real-time responses
Main components
a. External Systems
• Telegram API (for channel messages & Bot updates)
• OpenAI API (GPT endpoints)
b. Internal Modules
• Config Loader (config.py)
• Telegram Client (telegram_client.py)
• Bot Handler (telegram_bot_handler.py)
• Message Processor (message_processor.py)
• Vector Store (vector_store.py)
• LLM Client (llm_client.py)
c. Entry point
• bot.py – wires up config, instantiates clients, starts polling/listening loop
Relationships and interactions
1. User sends message/command in Telegram → Telegram API → Bot Handler
2. Bot Handler parses command → may invoke Message Processor
3. Message Processor
• For “fetch” or ingestion tasks: uses Telegram Client to pull channel messages, then passes messages to Vector Store to index vectors
• For “query” tasks: consults Vector Store for relevant message vectors, then calls LLM Client to generate an answer
4. LLM Client ↔ OpenAI API → receives generated response
5. Bot Handler receives processed answer → sends response back through Telegram API to user
Architectural patterns and design principles
• Separation of concerns: each module has a clear responsibility
• Adapter pattern for external APIs (telegram_client.py, llm_client.py)
• Pipeline style in message_processor: ingestion vs. query pipelines
• Config management centralized in config.py for environment isolation