A personal Telegram bot that collects messages from public Telegram channels, clusters them into topics using Claude AI, fact-checks key claims via web search, and delivers a condensed digest on demand.
- You subscribe to public Telegram channels via bot commands.
- When you send
/summary, the bot fetches the last 24 hours of messages from all subscribed channels. - Messages are sent to Claude AI, which clusters them into topics, categorises them, and identifies key claims.
- Claims are fact-checked against the web using Tavily search.
- A formatted digest is delivered back to you in Telegram.
- macOS (tested on macOS Ventura+)
- Python 3.11+
- Telegram account (for the MTProto user client that reads channels)
- API keys (see Configuration below)
If you don't have Python 3.11+ installed, use Homebrew:
brew install python@3.12Verify:
python3 --versioncd ~/Coding/telegram-aggregator-bot
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtYou'll need four sets of credentials:
- Open Telegram and message @BotFather.
- Send
/newbotand follow the prompts. - Copy the bot token.
- Message @userinfobot on Telegram.
- It will reply with your user ID (a number like
123456789).
- Go to https://my.telegram.org.
- Log in with your phone number.
- Go to API development tools.
- Create a new application (name and platform don't matter).
- Copy the App api_id and App api_hash.
Important: This bot uses the Anthropic API platform, not the claude.ai consumer chat. These are separate products with separate billing. A Claude Pro subscription (claude.ai) does not cover API usage. You need credits on the API platform at console.anthropic.com.
- Go to https://console.anthropic.com.
- Create an account or sign in.
- Add billing / credits under Plans & Billing — this is what the bot consumes.
- Navigate to API Keys and create a new key.
- Go to https://tavily.com.
- Sign up for an account.
- Copy your API key from the dashboard.
Copy the example env file and fill in your credentials:
cp .env.example .envEdit .env:
# Telegram Bot API token (from @BotFather)
BOT_TOKEN=your_bot_token_here
# Your personal Telegram user ID
OWNER_ID=123456789
# Telegram API credentials (from https://my.telegram.org)
TELEGRAM_API_ID=12345678
TELEGRAM_API_HASH=your_api_hash_here
# Anthropic API key
ANTHROPIC_API_KEY=sk-ant-...
# Tavily API key
TAVILY_API_KEY=tvly-...source .venv/bin/activate
python -m botOn the first run, Telethon will prompt you in the terminal to authenticate your Telegram user account:
- Enter your phone number (international format, e.g.
+1234567890). - Enter the verification code Telegram sends you.
- If you have 2FA enabled, enter your password.
This creates a user_session.session file locally. Do not share this file — it grants access to your Telegram account.
Subsequent runs will use the saved session automatically.
Once the bot is running, open your bot in Telegram and use these commands:
| Command | Description |
|---|---|
/start |
Welcome message |
/add_channel <username> |
Subscribe to a channel (e.g. /add_channel durov) |
/remove_channel <username> |
Unsubscribe from a channel |
/list_channels |
Show all subscribed channels |
/summary |
Generate a digest of the last 24 hours |
/help |
Show available commands |
/add_channel durov
/add_channel telegram
/add_channel bbcnews
/summary
telegram-aggregator-bot/
├── bot/
│ ├── __init__.py
│ ├── __main__.py # Entry point — starts aiogram + Telethon
│ ├── config.py # Environment-based configuration
│ ├── database.py # SQLite storage (channels & messages)
│ ├── channel_reader.py # Telethon MTProto client — reads channels
│ ├── summarizer.py # Claude API — topic clustering & summarisation
│ ├── fact_checker.py # Tavily API — claim verification
│ ├── formatter.py # Report formatting for Telegram HTML
│ └── handlers.py # aiogram command handlers
├── .env.example # Template for environment variables
├── .gitignore
├── requirements.txt
├── PRD.md # Product requirements document
└── README.md # This file
Press Ctrl+C in the terminal. The bot will shut down gracefully.
Make sure your .env file exists and all required variables are set. Compare with .env.example.
Delete user_session.session and restart the bot to re-authenticate:
rm user_session.session
python -m bot- Verify
OWNER_IDmatches your actual Telegram user ID. - Make sure you started a conversation with the bot first (send
/start).
- The channel must be public.
- Your Telegram account (not the bot) must be able to access the channel.
- Check that the channel username is correct (without the
@prefix).
- Claude API and Tavily both have rate limits on free tiers.
- If summarisation fails, check the logs for API error details.