clean-tg-chat
v1.0.1
Published
Removes useless information from JSON file with exported Telegram chat
Maintainers
Readme
Clean TG Chat
A lightweight CLI tool for cleaning exported Telegram chats. Removes unnecessary data while preserving the essential structure for analysis.
Features
- 🔥 Reduces JSON file size by 3-10x
- 📊 Preserves conversation structure (message replies)
- 😀 Saves reactions with user information
- 🎯 Keeps only essential fields for analysis
- 🚀 Simple CLI interface
- 📦 Zero dependencies
Installation
Global installation (recommended)
npm install -g clean-tg-chatLocal installation
npm install clean-tg-chatDirect usage (no installation)
npx clean-tg-chat <input.json> [output.json]Usage
Basic usage
clean-tg-chat result.jsonCreates clean_chat.json in the current directory.
With custom output file
clean-tg-chat result.json cleaned.jsonUsing as a Node.js module
const { cleanChat } = require('clean-tg-chat');
// Synchronous cleaning
const cleanedData = cleanChat('result.json', 'cleaned.json');
console.log(`Processed ${cleanedData.messages.length} messages`);
// Asynchronous cleaning (Promise-based)
await cleanChat.async('result.json', 'cleaned.json');What Gets Preserved
After processing, only these essential fields remain:
For each message:
id- unique message identifierdate- timestamp (ISO string)from- sender nametext- message text (extracted from all formats)reply_to_message_id- ID of replied message (if applicable)reactions- message reactions (if any)
Reactions format:
{
"emoji": "😁",
"users": [
{
"name": "Username",
"id": "user123456789",
"date": "2026-01-12T19:52:39"
}
]
}Example Output
clean-tg-chat result.json
✅ Done!
📁 Saved to: clean_chat.json
💬 Messages: 145
👥 Participants: 2
↪️ Replies: 32
😀 Reactions: 15 (12 with user info)
Example reactions:
😁: John
👍: MarkData Preparation
How to export a chat from Telegram:
- Open the desired chat in Telegram Desktop
- Click ⋮ (three dots) → Export chat history
- Select format: JSON
- Uncheck Media (photos, videos, etc.)
- Export and get the
result.jsonfile
API Reference
cleanChat(inputPath: string, outputPath?: string): object
Synchronously cleans a Telegram chat export.
Parameters:
inputPath: Path to the input JSON fileoutputPath: Optional output path (default:'clean_chat.json')
Returns: The cleaned data object
cleanChat.async(inputPath: string, outputPath?: string): Promise<object>
Asynchronously cleans a Telegram chat export.
License
MIT
Support
Found a bug or have suggestions?
Compatibility
- Node.js 12+
- Telegram Desktop JSON exports
- All operating systems (Windows, macOS, Linux)
