Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

TG Export Chat

A powerful command-line interface for Telegram that allows you to export chat messages from any chat, group, or channel you have access to.

Features

  • 🚀 Easy Setup - Interactive setup wizard for Telegram API credentials
  • 💬 Chat Export - Export messages from any chat, group, or channel
  • 🔍 Smart Search - Filter and search through your chats by name or type
  • 🎨 Rich Interface - Beautiful CLI with colors, tables, and progress bars
  • 📱 Session Management - Persistent authentication sessions
  • 🔒 Secure - Local credential storage with gitignore protection
  • 📊 Flexible Export - Choose specific message count or export ALL messages
  • Complete Backup - Full chat history export with progress tracking

Prerequisites

  • Python 3.7+
  • Telegram account
  • Telegram API credentials (API ID and API Hash)

Installation

  1. Clone this repository:
git clone https://github.com/almas-cp/TG-export-chat.git
cd TG-export-chat
  1. Install required dependencies:
pip install telethon rich
  1. Get your Telegram API credentials:

Usage

Run the application:

python script.py

First Run Setup

On your first run, the application will guide you through:

  1. Entering your API ID and API Hash
  2. Phone number verification
  3. Telegram verification code entry

Your credentials are securely stored locally and won't be asked again.

Exporting Chats

  1. Select "Export Chat" from the main menu
  2. Browse your available chats, groups, and channels
  3. Search and Filter (optional):
    • Type s to search for specific chats by name or type
    • Type r to reset filters and show all chats
    • Type q to quit
  4. Select a chat by entering its number
  5. Choose export size:
    • Enter a specific number (e.g., 100, 500, 1000)
    • Type all to export the complete chat history
  6. Wait for the export to complete

Exported files are saved as chat_export_[CHAT_NAME]_[TIMESTAMP].txt

Search Examples

  • Search for "work" to find work-related chats
  • Search for "group" to show only group chats
  • Search for "channel" to show only channels

Output Format

Exported chat files include:

  • Chat metadata (name, type, export date)
  • Message count
  • Chronologically ordered messages with timestamps and sender names

Example:

Chat Export: My Group Chat (Supergroup)
Export Date: 2025-08-16 15:39:23
Total Messages: 423
================================================================================

[2025-07-31 12:59:39] John Doe: Hello everyone!
[2025-07-31 13:01:30] Jane Smith: How's everyone doing?

File Structure

├── script.py              # Main application
├── .auth                  # API credentials (auto-generated)
├── telegram_session.session # Telegram session (auto-generated)
├── chat_export_*.txt      # Exported chat files
└── .gitignore            # Protects sensitive files

Security Notes

  • Your API credentials are stored locally in .auth
  • Session files are stored as .session files
  • All sensitive files are automatically ignored by git
  • Never share your .auth or .session files

Troubleshooting

Authentication Issues

  • Ensure your API ID and API Hash are correct
  • Check that your phone number includes the country code
  • Verify the verification code is entered correctly

Export Issues

  • Make sure you have access to the chat you're trying to export
  • Some channels may restrict message history access
  • Large exports may take time - be patient
  • Full exports (all option) can take significant time for large chats with thousands of messages

Dependencies

If you encounter import errors:

pip install --upgrade telethon rich

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is open source. Please ensure you comply with Telegram's Terms of Service when using this tool.

Support

If you find this project helpful, please give it a ⭐ on GitHub!

Disclaimer

This tool is for personal use and data backup purposes. Always respect privacy and terms of service of the platforms you're accessing.

About

A beautiful Telegram CLI for exporting messages from your chats, groups, and channels, featuring smart search and full chat backups.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages