An automated tool for monitoring Telegram channels and groups, filtering messages with AI, and forwarding interesting content to a target chat.
- Monitor multiple Telegram channels and groups
- Filter messages using AI (OpenRouter/Gemini)
- Forward interesting messages to a target chat
- Support for both regular and media group messages
- Persistent state storage to avoid duplicate messages
- Proper logging
pip install telethon requests
Copy the example configuration and fill it with your values:
cp config.example.py config.py
Then edit config.py
with your:
- Telegram API credentials (from https://my.telegram.org/apps)
- Source chats to monitor
- Target chat for forwarding
- OpenRouter API key (from https://openrouter.ai/keys)
To easily get a list of all your channels and groups with their IDs, run:
python list_chats.py
This will:
- Connect to your Telegram account
- Generate a text file (
telegram_chats.txt
) with all your chats and their IDs - Create a JSON file (
telegram_chats.json
) with the same data - Display sample configuration entries
Use the output to update your config.py
file with the correct chat identifiers.
Start the forwarder with:
python main.py
The script will:
- Connect to your Telegram account
- Initialize all source chats
- Start monitoring for new messages
- Filter messages using AI
- Forward interesting messages to your target chat
- Channels: Uses the Telegram PTS (Point of Truth Sequence) for tracking updates
- Groups: Tracks message IDs to fetch only new messages
Messages are filtered using the Gemini AI model through OpenRouter API.
The AI evaluates message content according to rules defined in the AIFilter
class.
The forwarder maintains persistent state to:
- Track channel/group update markers
- Store message hashes to prevent duplicate processing
main.py
- Entry point and orchestrationconfig.py
- Configuration settingslogger.py
- Logging systemstate_manager.py
- State persistencetelegram_client.py
- Telegram client operationsai_filter.py
- AI-based message filteringlist_chats.py
- Utility to list all chats and IDs