# ๐ฆ chatpack
> Compress chat exports from Telegram, WhatsApp, and Instagram into token-efficient CSV for LLMs.
Less tokens. Same conversation.
## โจ Features
- **Token optimization** โ Merges consecutive messages from the same sender, reducing token count by 30-50%
- **Multi-platform** โ Supports Telegram, WhatsApp, and Instagram exports
- **Clean output** โ Strips metadata (timestamps, IDs, reactions) leaving only sender and content
- **LLM-ready** โ CSV format with semicolon delimiter, perfect for feeding into AI models
- **Fast** โ Written in Rust for maximum performance
## ๐ Example
**Before** (62 messages):
```
[14:25] Alice: Hey
[14:25] Alice: How are you?
[14:26] Alice: Did you see the news?
[14:27] Bob: Hi! Yes I did
```
**After** (2 rows, 43.5% reduction):
```csv
Sender;Content
Alice;Hey
How are you?
Did you see the news?
Bob;Hi! Yes I did
```
## ๐ Installation
### From source
```bash
git clone https://github.com/berektassuly/chatpack.git
cd chatpack
cargo build --release
```
Binary will be at `./target/release/chatpack`
### Using Cargo
```bash
cargo install --path .
```
## ๐ Usage
```bash
chatpack <source> <input_file> [output_file]
```
### Examples
```bash
# Telegram JSON export
chatpack telegram result.json
chatpack tg chat.json output.csv
# WhatsApp TXT export
chatpack whatsapp _chat.txt
chatpack wa chat.txt messages.csv
# Instagram JSON export
chatpack instagram messages.json
chatpack ig inbox.json chat.csv
```
### Options
| `-h, --help` | Show help message |
| `-v, --version` | Show version |
### Output format
- **File:** `optimized_chat.csv` (default)
- **Delimiter:** Semicolon (`;`)
- **Columns:** `Sender`, `Content`
- **Encoding:** UTF-8
## ๐ฑ Supported Sources
| Telegram | JSON | โ
Ready | Desktop โ Settings โ Export chat |
| WhatsApp | TXT | ๐ฒ Coming | Chat โ More โ Export chat |
| Instagram | JSON | ๐ฒ Coming | Settings โ Download your data |
## ๐๏ธ Project Structure
```
chatpack/
โโโ Cargo.toml
โโโ src/
โโโ main.rs # CLI entry point
โโโ core/
โ โโโ mod.rs
โ โโโ models.rs # InternalMessage struct
โ โโโ processor.rs # Merge logic + CSV writer
โโโ parsers/
โโโ mod.rs # ChatParser trait + factory
โโโ telegram.rs # โ
Implemented
โโโ whatsapp.rs # ๐ฒ Stub
โโโ instagram.rs # ๐ฒ Stub
```
## ๐ง Adding a New Parser
1. Create `src/parsers/newsource.rs`:
```rust
use crate::core::InternalMessage;
use super::ChatParser;
pub struct NewSourceParser;
impl NewSourceParser {
pub fn new() -> Self { Self }
}
impl ChatParser for NewSourceParser {
fn name(&self) -> &'static str {
"NewSource"
}
fn parse(&self, file_path: &str) -> Result<Vec<InternalMessage>, Box<dyn Error>> {
// Your parsing logic here
// Return Vec<InternalMessage { sender, content }>
}
}
```
2. Register in `src/parsers/mod.rs`:
```rust
mod newsource;
pub use newsource::NewSourceParser;
// In ChatSource enum:
NewSource,
// In from_arg():
// In create_parser():
ChatSource::NewSource => Box::new(NewSourceParser::new()),
```
3. Done! No changes needed in `main.rs` or `processor.rs`.
## ๐งช Running Tests
```bash
cargo test
```
## ๐ Benchmarks
| Small | 62 | 35 | 43.5% | <1ms |
| Medium | 1,000 | ~600 | ~40% | ~5ms |
| Large | 10,000 | ~5,500 | ~45% | ~50ms |
## ๐ค Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/discord-parser`)
3. Implement the `ChatParser` trait for your source
4. Add tests
5. Submit a pull request
## ๐ License
MIT License โ see [LICENSE](LICENSE) for details.
## ๐ Acknowledgments
- Built for the AI era, where every token counts
- Inspired by the need to analyze chat histories with LLMs without burning through context windows