A powerful command-line interface for Telegram that allows you to export chat messages from any chat, group, or channel you have access to.
- 🚀 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
- Python 3.7+
- Telegram account
- Telegram API credentials (API ID and API Hash)
- Clone this repository:
git clone https://github.com/almas-cp/TG-export-chat.git
cd TG-export-chat- Install required dependencies:
pip install telethon rich- Get your Telegram API credentials:
- Go to https://my.telegram.org/apps
- Log in with your Telegram account
- Create a new application
- Note down your
API IDandAPI Hash
Run the application:
python script.pyOn your first run, the application will guide you through:
- Entering your API ID and API Hash
- Phone number verification
- Telegram verification code entry
Your credentials are securely stored locally and won't be asked again.
- Select "Export Chat" from the main menu
- Browse your available chats, groups, and channels
- Search and Filter (optional):
- Type
sto search for specific chats by name or type - Type
rto reset filters and show all chats - Type
qto quit
- Type
- Select a chat by entering its number
- Choose export size:
- Enter a specific number (e.g., 100, 500, 1000)
- Type
allto export the complete chat history
- Wait for the export to complete
Exported files are saved as chat_export_[CHAT_NAME]_[TIMESTAMP].txt
- Search for "work" to find work-related chats
- Search for "group" to show only group chats
- Search for "channel" to show only channels
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?
├── 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
- Your API credentials are stored locally in
.auth - Session files are stored as
.sessionfiles - All sensitive files are automatically ignored by git
- Never share your
.author.sessionfiles
- 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
- 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 (
alloption) can take significant time for large chats with thousands of messages
If you encounter import errors:
pip install --upgrade telethon richContributions 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source. Please ensure you comply with Telegram's Terms of Service when using this tool.
If you find this project helpful, please give it a ⭐ on GitHub!
This tool is for personal use and data backup purposes. Always respect privacy and terms of service of the platforms you're accessing.