CLI utility for downloading Telegram chat history to JSON
Project description
Telegram Chat Downloader
A command-line utility to download Telegram chat history to JSON and TXT format.
Features
- Download complete chat history from any Telegram chat, group, or channel
- Save messages in JSON format with full message metadata
- Save messages in TXT format with user-friendly display names
- Support for resuming interrupted downloads
Usage Examples
Here are some practical use cases for the tool:
-
Learning and Research
- Find a Telegram group about a new topic you're studying
- Download the entire chat history
- Get a summary of the discussions using the generated text files
-
Social Analysis
- Download chat history from your friends' group
- Analyze topics and conversations
- Get insights about who talks about what
-
Personal Communication Analysis
- Download your personal chat history
- Study the chronology of your conversations
- Analyze communication patterns over time
-
Recent Discussions Analysis
- Download the last 1000 messages from a chat
- Get a summary of recent discussions
- Filter messages by date to analyze specific time periods
-
Saved Messages
- Download your saved messages (favorites)
- Requires specifying your username
- Useful for organizing and analyzing important conversations
Note: The generated text files can be loaded into Google NotebookLM for further analysis. However, loading histories larger than 10,000 messages may cause issues.
Installation
Using pip
pip install telegram-download-chat
Using uvx
uvx install git+https://github.com/popstas/telegram-download-chat.git
Configuration
API Credentials
To use this tool, you'll need to obtain API credentials from my.telegram.org:
- Go to API Development Tools
- Log in with your phone number
- Important: Do not use a VPN when obtaining API credentials
- Create a new application
- Copy the
api_idandapi_hashto yourconfig.yml
Configuration File (config.yml)
telegram_app:
api_id: your_api_id # Get from https://my.telegram.org
api_hash: your_api_hash # Get from https://my.telegram.org
# Map user IDs to display names for text exports
users_map:
123456: "Alice"
789012: "Bob"
# full settings: see config.example.yml
Usage
For the first run, you will need to log in to your Telegram account.
Basic Usage
telegram-download-chat target
Where target can be:
- Chat/Group/Channel/User ID (e.g.,
-123456789) - Username (e.g.,
username) - Group URL (e.g.,
https://t.me/group_name) - Invite link (e.g.,
https://t.me/+invite_code) - Phone number (e.g.,
+1234567890)
# Download chat by username
telegram-download-chat username
# Download chat by numeric ID (negative for groups/channels)
telegram-download-chat -123456789
# Download chat by invite link
telegram-download-chat https://t.me/+invite_code
# Download chat by phone number (must be in your contacts)
telegram-download-chat +1234567890
Advanced Usage
# Download with a limit on number of messages
telegram-download-chat username --limit 1000
# Download messages until a specific date (YYYY-MM-DD)
telegram-download-chat username --until 2025-05-01
# Specify custom output file
telegram-download-chat username -o my_chat_history.json
# Enable debug logging
telegram-download-chat username --debug
# Download last 100 messages from channel
telegram-download-chat https://t.me/group_name --limit 100
# Convert JSON to TXT with subchat filtering and custom directory name
telegram-download-chat big_chat.json --subchat 104888 --subchat-name "my_subchat"
Command Line Options
usage: telegram-download-chat [-h] [-o OUTPUT] [--limit LIMIT] [--until DATE] [-s] chat
Download Telegram chat history to JSON
positional arguments:
chat Chat identifier (group URL, @username, phone number, or invite link)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output JSON filename (default: chat_history.json)
--limit LIMIT Number of messages per API request (50-1000, default: 500)
--until DATE Only download messages until this date (format: YYYY-MM-DD)
--subchat SUBCHAT Filter messages for txt by subchat id or URL (only with --json)
--subchat-name NAME Name for the subchat directory (default: subchat_<subchat_id>)
-s, --silent Suppress progress output (default: False)
Output Format
The tool generates two files for each chat:
[chat_name].json- Complete message data in JSON format[chat_name].txt- Human-readable text version of the chat
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_download_chat-0.1.2.tar.gz.
File metadata
- Download URL: telegram_download_chat-0.1.2.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e47b97f3dafbcdffda476bf850343a6a5cdf7dfaa265431eb468cf54665f733
|
|
| MD5 |
b5a8972cd651774b75a017381b8aaa74
|
|
| BLAKE2b-256 |
bbaa7c4a4a2d6aec6784d34e8101f737ec65dfd34ccaedc3f67df584187cc97d
|
File details
Details for the file telegram_download_chat-0.1.2-py3-none-any.whl.
File metadata
- Download URL: telegram_download_chat-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f682ee23fba1b1513cdcae941ca9a6c87c9a4ea21d72cace625ce611179f50d4
|
|
| MD5 |
c19f33746d2ed145d15010c79b1117a2
|
|
| BLAKE2b-256 |
2a30d0c9c2280b87eae49a46d8bf9694b8d20a30337c9651ba4a46b0dfb99023
|