How alberteinsteintg/adv-auto-filter-bot-v2 works
Project Type and Purpose
• This is a specialized messaging “service” rather than a typical web app: a Python-based Telegram bot that automatically filters and searches files stored in MongoDB and returns message links as inline buttons.
• It leverages the Pyrogram library to listen for incoming Telegram updates, processes queries via a plugin architecture, and persists chat–channel connections and file metadata in a MongoDB database.
File-Structure Analysis
• Top-level:
• bot/ – the core application package
• bot/database/ – MongoDB adapter (database.py)
• bot/plugins/ – modular business logic for filters, callbacks, channel management, commands, settings
• bot/translation.py – user-facing text templates or multilingual support
• bot/user.py – user/session abstractions
• Procfile, runtime.txt, app.json – deployment configs (Heroku or other PaaS)
• requirements.txt – Python dependencies (pyrogram, pymongo)
a. External Systems
• Telegram API – delivers updates (messages, commands) and receives bot responses
• MongoDB Atlas (or self-hosted) – persistent storage of connected chat-channel mappings and file metadata
b. Bot Application Service (Python container)
• Update Receiver (Pyrogram Client)
• Core Dispatcher – routes each incoming update to the appropriate plugin
• Plugins –
– auto_filter.py: listens for plain-text queries, performs DB searches
– commands.py: handles /add, /del, /delall, /settings commands
– callback.py: processes inline-button callbacks from settings panels or search results
– channel.py, settings.py: channel-connection management and configuration toggles
• Database Layer (bot/database/database.py) – CRUD operations on chat/channel collections
• Translation Layer (bot/translation.py) – static or dynamic text generation for replies and buttons
• User Model (bot/user.py) – encapsulates user or chat metadata, permission checks
c. Deployment Environment
• Heroku or VPS – container or VM running Procfile (worker: python3 -m bot)
• Environment Variables – BOT_TOKEN, API_ID, API_HASH, MONGO_URL, SESSION_STRING
Interactions & Data Flow
1. A user sends a message or command → Telegram API → Bot’s Pyrogram client
2. Dispatcher inspects update:
• If command → plugin commands.py → may update DB via database.py → acknowledges with inline keyboard
• If text query → auto_filter.py → queries MongoDB → builds result buttons via translation layer → sends response
• If callback query → callback.py → modifies settings or paginates results → edits message or sends new keyboard
3. All DB reads/writes flow through the database adapter to MongoDB.
Key Architectural Patterns & Principles
• Modular “Plugin” pattern: each bot capability in its own Python module, making it easy to extend or disable features.
• Separation of Concerns:
• Pyrogram client (network/update handling)
• Core Dispatcher (routing)
• Business logic (plugins)
• Persistence (database adapter)
• Presentation/text (translation layer)
• Configuration via environment variables and a settings panel bot command – no code changes required at runtime.