[][src]Crate whatsapp_export_parser

A utility crate for parsing the text file you get when exporting a WhatsApp conversation.

Examples

The main purpose of this crate is the parse() function for parsing source text into Messages and ParseErrors.

use whatsapp_export_parser::{parse, Body, DirectMessage, Message, Span};

let src = r#"
31/10/19, 16:16 - Michael-F-Bryan: This is a message!
31/10/19, 14:13 - +60 12-345 6789: IMG-20191031-WA0005.jpg (file attached)
"#;

let parsed = dbg!(parse(src));

assert!(parsed.errors.is_empty(), "Everything should have parsed successfully");
assert_eq!(parsed.messages.len(), 2);

assert_eq!(parsed.messages[0].meta.sender, "Michael-F-Bryan");
let expected_body = Body::from(DirectMessage {
    content: String::from("This is a message!"),
    span: Span::new(36, 54),
});
assert_eq!(parsed.messages[0].body, expected_body);
assert_eq!(parsed.messages[1].meta.sender, "+60 12-345 6789");

Cargo Features

To help reduce compile times some features have been hidden behind cargo feature flags.

  • serde-1 - implements serialization for exported types

Structs

Attachment

A link to an attachment.

DirectMessage

A message with text.

Message

A single chat message.

Metadata

Message metadata.

ParseError

An error that can occur while parsing.

Parsed

The outcome of parsing an exported WhatsApp chat.

Span

The half-open interval representing the location of something in some text.

Enums

Body

A Message's contents.

Functions

parse

Try to parse some WhatsApp messages from an export file.