A robust TypeScript tool for extracting, parsing, filtering, and exporting conversation data from multiple formats.
- Multiple Input Formats: Parse conversations from JSON, WhatsApp exports, and plain text
- Flexible Filtering: Filter conversations by participants, dates, keywords, and sender patterns
- Multiple Export Formats: Export to JSON, CSV, plain text, or Markdown
- Statistics: Generate detailed statistics about conversations
- CLI Interface: Easy-to-use command-line interface
- TypeScript Support: Full TypeScript definitions included
- Comprehensive Testing: Well-tested with Jest
npm install
npm run build# Extract conversation and show statistics
npm run cli extract examples/sample.json --format json --stats
# Filter by participants
npm run cli extract examples/whatsapp.txt --format whatsapp --participants "Alice,Bob" --output filtered.json
# Filter by date range
npm run cli extract examples/sample.json --format json --startDate "2024-01-01" --endDate "2024-12-31"
# Filter by keywords
npm run cli extract examples/sample.json --format json --keywords "meeting,urgent" --output meeting-messages.txt --exportFormat txt
# Export to different formats
npm run cli extract examples/sample.json --format json --output output.csv --exportFormat csv
npm run cli extract examples/sample.json --format json --output output.md --exportFormat markdown# Convert WhatsApp to JSON
npm run cli convert examples/whatsapp.txt converted.json --inputFormat whatsapp --outputFormat json
# Convert JSON to Markdown
npm run cli convert examples/sample.json output.md --inputFormat json --outputFormat markdown
# Convert to CSV
npm run cli convert examples/sample.json output.csv --inputFormat json --outputFormat csvimport {
ConversationExtractor,
JSONParser,
WhatsAppParser,
JSONExporter,
MarkdownExporter,
} from 'conversation-extractor';
// Parse conversations
const parser = new JSONParser();
const conversations = await parser.parseFile('conversation.json');
// Create extractor
const extractor = new ConversationExtractor(conversations);
// Filter conversations
const filtered = extractor.filterConversations({
participants: ['Alice', 'Bob'],
keywords: ['meeting'],
startDate: new Date('2024-01-01'),
});
// Get statistics
const stats = extractor.getStatistics();
console.log(`Total messages: ${stats.totalMessages}`);
console.log(`Participants: ${stats.participants.join(', ')}`);
// Export to different formats
const jsonExporter = new JSONExporter({ format: 'json', prettify: true });
await jsonExporter.exportToFile(filtered, 'output.json');
const mdExporter = new MarkdownExporter({ format: 'markdown' });
await mdExporter.exportToFile(filtered, 'output.md');Main class for managing and filtering conversations.
addConversation(conversation: Conversation): void- Add a conversationaddConversations(conversations: Conversation[]): void- Add multiple conversationsgetConversations(): Conversation[]- Get all conversationsfilterConversations(filter: ConversationFilter): Conversation[]- Filter conversationsextractMessages(filter: ConversationFilter): Message[]- Extract messages matching filtergetStatistics()- Get conversation statisticsmergeConversations(ids?: string[]): Conversation | null- Merge conversationsclear(): void- Clear all conversations
Parse conversations from JSON format.
const parser = new JSONParser();
const conversations = await parser.parseFile('file.json');Parse conversations from WhatsApp export format.
const parser = new WhatsAppParser();
const conversations = await parser.parseFile('whatsapp.txt');Supports formats:
[DD/MM/YYYY, HH:MM:SS] Sender: MessageDD/MM/YYYY, HH:MM - Sender: Message
Parse conversations from generic text format.
const parser = new TextParser();
const conversations = await parser.parseFile('conversation.txt');Supports formats:
[YYYY-MM-DD HH:MM:SS] Sender: MessageYYYY-MM-DD HH:MM:SS Sender: Message
Export conversations to JSON format.
const exporter = new JSONExporter({
format: 'json',
includeMetadata: true,
prettify: true,
});
await exporter.exportToFile(conversations, 'output.json');Export conversations to CSV format.
const exporter = new CSVExporter({ format: 'csv' });
await exporter.exportToFile(conversations, 'output.csv');Export conversations to plain text format.
const exporter = new TextExporter({ format: 'txt' });
await exporter.exportToFile(conversations, 'output.txt');Export conversations to Markdown format.
const exporter = new MarkdownExporter({ format: 'markdown' });
await exporter.exportToFile(conversations, 'output.md');interface Conversation {
id?: string;
title?: string;
participants: string[];
messages: Message[];
startTime: Date;
endTime: Date;
metadata?: Record<string, unknown>;
}interface Message {
id?: string;
timestamp: Date;
sender: string;
content: string;
metadata?: Record<string, unknown>;
}interface ConversationFilter {
participants?: string[];
startDate?: Date;
endDate?: Date;
keywords?: string[];
senderPattern?: RegExp;
}See the examples/ directory for sample conversation files:
sample.json- JSON format examplewhatsapp.txt- WhatsApp export exampletext-conversation.txt- Plain text format example
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Watch mode for tests
npm run test:watch
# Lint code
npm run lint
# Format code
npm run formatThe project includes comprehensive tests using Jest. Run them with:
npm testCoverage report:
npm run test:coverageMIT
Contributions are welcome! Please feel free to submit a Pull Request.