A command-line tool to list and dump messages from Telegram channels, including text, replies, and attached media.
- ✅ List all channels you're part of
- ✅ Dump full message history from a selected channel
- ✅ Download attached photos
- ✅ Save messages in structured JSONL format
- ✅ Interactive CLI interface with tabular output
- Python 3.8+
telethon
(Telegram API client)pandas
(for table formatting)tabulate
(for prettier output)
# Create a virtual environment
python3 -m venv venv
# Activate the environment
source venv/bin/activate # Unix/macOS
# OR
venv\Scripts\activate # Windows
pip install -r dependencies.txt
Go to my.telegram.org → "API development tools" → Create Application
export API_ID=your_api_id_here
export API_HASH=your_api_hash_here
Now you can use env variables to pass them to DTC.
python3 DTC --help
python3 DTC <api_id> <api_hash>
Example:
python3 DTC 1234567 abcdef1234567890abcdef1234567890
Lists all Telegram channels you're part of:
>> list
Output:
+----+----------------------------+-------------+
| | name | telegram id |
+====+============================+=============+
| 0 | My Favorite Channel | 123456789 |
+----+----------------------------+-------------+
| 1 | News Channel | 987654321 |
+----+----------------------------+-------------+
Dumps messages and media from a channel using the list index:
>> dump 0
Output:
Processed message 12345 (3 replies)
Downloaded photo: media/123456789_12345.jpg
Channel dump completed. Output saved to 'output.jsonl'.
Each line contains:
{
"id": 12345,
"date": "2024-07-01 12:34:56",
"sender_id": 1122334455,
"text": "This is a message with photo",
"media_path": "media/123456789_12345.jpg",
"replies": [
{
"id": 12346,
"date": "2024-07-01 12:35:01",
"sender_id": 5544332211,
"text": "Nice photo!",
"media_path": null
}
]
}
Photos are saved in media/
with naming:
media/{channel_id}_{msg_id}_reply_{reply_id}.jpg
- Sessions are stored
- Reuse sessions to avoid re-login and rate limits
- Delete session file to log out
- Telegram enforces strict rate limits
- Avoid rapid login attempts or spamming requests
- If you hit
FloodWaitError
, wait for the required time
- Never share
.session
files - Don't commit API credentials to public repos
# 0. clone repo
git clone https://github.com/dfwdfq/DCT.git
# 1. cd into directory
cd DCT
# 3. Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# 4. Install dependencies
pip install -r dependencies.txt
# 5. get back
cd ..
# 6. Run the tool
python DCT 1234567 abcdef1234567890abcdef1234567890
# 7. In the CLI
>> list
>> dump 0
Feel free to open issues or PRs for:
- Adding video/media support
- Improving error handling
- Adding CLI argument parsing
- Supporting config files
For questions or feedback: [haskel.list@yandex.ru]