Module message

Module message 

Source
Expand description

Universal message type for all chat platforms.

This module provides Message, the normalized representation of chat messages. All platform parsers convert their native formats into this structure, enabling uniform processing regardless of source.

§Overview

A message consists of:

  • Required: sender and content
  • Optional: timestamp, id, reply_to, edited

§Examples

§Basic Usage

use chatpack::Message;

let msg = Message::new("Alice", "Hello, world!");
assert_eq!(msg.sender(), "Alice");
assert_eq!(msg.content(), "Hello, world!");

§Builder Pattern

use chatpack::Message;
use chrono::Utc;

let msg = Message::new("Bob", "Check this out!")
    .with_id(12345)
    .with_timestamp(Utc::now())
    .with_reply_to(12344);

assert!(msg.has_metadata());

§Serialization

use chatpack::Message;

let msg = Message::new("Alice", "Hello!");
let json = serde_json::to_string(&msg)?;
let parsed: Message = serde_json::from_str(&json)?;

assert_eq!(msg, parsed);

Structs§

Message
A normalized chat message from any supported platform.