{"skill":{"slug":"telegram-history","displayName":"Telegram History","summary":"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...","description":"---\nname: telegram-history\ndescription: 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.\n---\n\n# Telegram History\n\nFetch message history from any Telegram chat using MTProto (Telethon). The Bot API cannot read chat history — this skill uses the user API instead.\n\n## Setup\n\n### 1. Install Telethon\n```bash\npip3 install telethon\n```\n\n### 2. Get API credentials\nGo to https://my.telegram.org/apps and create an app. Save credentials in the skill directory:\n```bash\ncat > <skill-dir>/api_credentials.json << 'EOF'\n{\"api_id\": YOUR_API_ID, \"api_hash\": \"YOUR_API_HASH\"}\nEOF\n```\n\n### 3. Login (one-time)\n\nAll paths below are relative to the skill directory.\n\n```bash\n# Step 1: Request a login code (sent to your Telegram app)\npython3 scripts/login.py send +1234567890\n\n# Output: Code sent! phone_code_hash: abc123\n# Output: Run: python3 login.py verify +1234567890 <code> abc123\n\n# Step 2: Verify with the code you received\n# IMPORTANT: Do NOT send the code via Telegram — Telegram detects shared codes and blocks login.\n# Use a file, another messenger, or run the command directly in terminal.\npython3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH>\n\n# If 2FA is enabled, append your password:\npython3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH> <2FA_PASSWORD>\n\n# Check login status:\npython3 scripts/login.py check +1234567890\n```\n\nSession persists in `session/` — no need to re-login after initial setup.\n\n## Usage\n\n```bash\n# Fetch last 50 messages from a chat\npython3 scripts/tg_history.py history <chat_id> --limit 50\n\n# Fetch from a forum topic\npython3 scripts/tg_history.py history <chat_id> --topic <topic_id> --limit 30\n\n# JSON output\npython3 scripts/tg_history.py history <chat_id> --json\n\n# Paginate (messages before a specific ID)\npython3 scripts/tg_history.py history <chat_id> --offset-id <msg_id> --limit 50\n```\n\n## Notes\n\n- Group chat IDs use `-100` prefix (e.g., `-1001234567890`)\n- Forum topic IDs = the thread/topic message ID\n- Sender names are resolved automatically\n- All paths (session, credentials) are resolved relative to the skill directory — works regardless of install location\n","topics":["Telegram","Message"],"tags":{"latest":"1.1.0"},"stats":{"comments":0,"downloads":2608,"installsAllTime":98,"installsCurrent":18,"stars":1,"versions":3},"createdAt":1771323205081,"updatedAt":1779077075659},"latestVersion":{"version":"1.1.0","createdAt":1771336295051,"changelog":"Fix: use relative paths instead of hardcoded home dir. Fix: SKILL.md now matches actual CLI arguments. Phone number is a required argument, not hardcoded.","license":null},"metadata":null,"owner":{"handle":"rhlsthrm","userId":"s174drpac9wrf84rycv196cqcn83kzey","displayName":"Rahul Sethuram","image":"https://avatars.githubusercontent.com/u/11512787?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1779972597843}}