| name | telegram-history |
| description | Fetch Telegram chat message history via MTProto user API (Telethon). Use when needing to read old messages from any Telegram chat, group, or forum topic that the bot API can't access. Supports fetching by chat ID, forum topic/thread, message count, pagination, and JSON output. Requires one-time user login with phone number + 2FA. |
Telegram History
Fetch message history from any Telegram chat using MTProto (Telethon). The Bot API cannot read chat history — this skill uses the user API instead.
Setup
1. Install Telethon
pip3 install telethon
2. Get API credentials
Go to https://my.telegram.org/apps and create an app. Save credentials in the skill directory:
cat > <skill-dir>/api_credentials.json << 'EOF'
{"api_id": YOUR_API_ID, "api_hash": "YOUR_API_HASH"}
EOF
3. Login (one-time)
All paths below are relative to the skill directory.
python3 scripts/login.py send +1234567890
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH>
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH> <2FA_PASSWORD>
python3 scripts/login.py check +1234567890
Session persists in session/ — no need to re-login after initial setup.
Usage
python3 scripts/tg_history.py history <chat_id> --limit 50
python3 scripts/tg_history.py history <chat_id> --topic <topic_id> --limit 30
python3 scripts/tg_history.py history <chat_id> --json
python3 scripts/tg_history.py history <chat_id> --offset-id <msg_id> --limit 50
Notes
- Group chat IDs use
-100 prefix (e.g., -1001234567890)
- Forum topic IDs = the thread/topic message ID
- Sender names are resolved automatically
- All paths (session, credentials) are resolved relative to the skill directory — works regardless of install location