✓ Verified 🌐 Web Scrapers ✓ Enhanced Data

Telegram History

Fetch Telegram chat message history via MTProto user API (Telethon)

Rating
4.6 (162 reviews)
Downloads
9,168 downloads
Version
1.0.0

Overview

Fetch Telegram chat message history via MTProto user API (Telethon)

Complete Documentation

View Source →

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

bash
pip3 install telethon

2. Get API credentials

Go to https://my.telegram.org/apps and create an app. Save credentials in the skill directory:
bash
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.

bash
# Step 1: Request a login code (sent to your Telegram app)
python3 scripts/login.py send +1234567890

# Output: Code sent! phone_code_hash: abc123
# Output: Run: python3 login.py verify +1234567890 <code> abc123

# Step 2: Verify with the code you received
# IMPORTANT: Do NOT send the code via Telegram — Telegram detects shared codes and blocks login.
# Use a file, another messenger, or run the command directly in terminal.
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH>

# If 2FA is enabled, append your password:
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH> <2FA_PASSWORD>

# Check login status:
python3 scripts/login.py check +1234567890

Session persists in session/ — no need to re-login after initial setup.

Usage

bash
# Fetch last 50 messages from a chat
python3 scripts/tg_history.py history <chat_id> --limit 50

# Fetch from a forum topic
python3 scripts/tg_history.py history <chat_id> --topic <topic_id> --limit 30

# JSON output
python3 scripts/tg_history.py history <chat_id> --json

# Paginate (messages before a specific ID)
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

Installation

Terminal bash

openclaw install telegram-history
    
Copied!

💻Code Examples

Go to https://my.telegram.org/apps and create an app. Save credentials in the skill directory:

go-to-httpsmytelegramorgapps-and-create-an-app-save-credentials-in-the-skill-directory.sh
cat > <skill-dir>/api_credentials.json << 'EOF'
{"api_id": YOUR_API_ID, "api_hash": "YOUR_API_HASH"}
EOF

python3 scripts/login.py check +1234567890

python3-scriptsloginpy-check-1234567890.txt
Session persists in `session/` — no need to re-login after initial setup.

## Usage
example.sh
# Step 1: Request a login code (sent to your Telegram app)
python3 scripts/login.py send +1234567890

# Output: Code sent! phone_code_hash: abc123
# Output: Run: python3 login.py verify +1234567890 <code> abc123

# Step 2: Verify with the code you received
# IMPORTANT: Do NOT send the code via Telegram — Telegram detects shared codes and blocks login.
# Use a file, another messenger, or run the command directly in terminal.
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH>

# If 2FA is enabled, append your password:
python3 scripts/login.py verify +1234567890 <CODE> <PHONE_CODE_HASH> <2FA_PASSWORD>

# Check login status:
python3 scripts/login.py check +1234567890
example.sh
# Fetch last 50 messages from a chat
python3 scripts/tg_history.py history <chat_id> --limit 50

# Fetch from a forum topic
python3 scripts/tg_history.py history <chat_id> --topic <topic_id> --limit 30

# JSON output
python3 scripts/tg_history.py history <chat_id> --json

# Paginate (messages before a specific ID)
python3 scripts/tg_history.py history <chat_id> --offset-id <msg_id> --limit 50

Tags

#browser_and-automation #api

Quick Info

Category Web Scrapers
Model Claude 3.5
Complexity One-Click
Author rhlsthrm
Last Updated 3/10/2026
🚀
Optimized for
Claude 3.5
🧠

Ready to Install?

Get started with this skill in seconds

openclaw install telegram-history