Message

Struct Message 

Source
pub struct Message {
    pub sender: String,
    pub content: String,
    pub timestamp: Option<DateTime<Utc>>,
    pub id: Option<u64>,
    pub reply_to: Option<u64>,
    pub edited: Option<DateTime<Utc>>,
}
Expand description

A normalized chat message from any supported platform.

This struct is the core data type in chatpack. All platform-specific parsers convert their native message formats into this universal representation, enabling uniform processing, filtering, and export.

§Fields

FieldTypeDescription
senderStringDisplay name or username of the message author
contentStringText content of the message
timestampOption<DateTime<Utc>>When the message was sent
idOption<u64>Platform-specific message identifier
reply_toOption<u64>ID of the parent message (for replies)
editedOption<DateTime<Utc>>When the message was last edited

§Construction

Use Message::new for simple messages or the builder pattern for metadata:

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

// Simple message
let msg = Message::new("Alice", "Hello!");

// With metadata
let msg = Message::new("Alice", "Hello!")
    .with_timestamp(Utc::now())
    .with_id(12345);

§Serialization

Implements Serialize and Deserialize with these behaviors:

  • Optional fields are omitted from JSON when None
  • Timestamps use RFC 3339 format
  • Suitable for storage, IPC, and RAG pipelines
use chatpack::Message;

let msg = Message::new("Alice", "Hello!").with_id(123);
let json = serde_json::to_string(&msg)?;

// timestamp is omitted (None)
assert!(!json.contains("timestamp"));
assert!(json.contains("123"));

Fields§

§sender: String

Display name or username of the message author.

§content: String

Text content of the message.

May contain newlines for multiline messages. Platform-specific attachments (images, files) are typically represented as text placeholders like [Attachment: image.png].

§timestamp: Option<DateTime<Utc>>

When the message was originally sent.

Available from most platforms except some WhatsApp export formats.

§id: Option<u64>

Platform-specific message identifier.

  • Telegram: message ID from the chat
  • Discord: snowflake ID
  • WhatsApp/Instagram: typically not available in exports
§reply_to: Option<u64>

ID of the message this is replying to.

Enables reconstruction of reply chains and conversation threads.

§edited: Option<DateTime<Utc>>

When the message was last edited.

Present when the platform tracks edit history (Telegram, Discord).

Implementations§

Source§

impl Message

Source

pub fn new(sender: impl Into<String>, content: impl Into<String>) -> Self

Creates a new message with only sender and content.

All metadata fields (timestamp, id, reply_to, edited) are set to None.

§Example
use chatpack::Message;

let msg = Message::new("Alice", "Hello!");
assert_eq!(msg.sender(), "Alice");
assert_eq!(msg.content(), "Hello!");
assert!(msg.timestamp().is_none());
Source

pub fn with_metadata( sender: impl Into<String>, content: impl Into<String>, timestamp: Option<DateTime<Utc>>, id: Option<u64>, reply_to: Option<u64>, edited: Option<DateTime<Utc>>, ) -> Self

Creates a new message with all fields specified.

Use this when you have all metadata available upfront. For incremental construction, prefer new with builder methods.

Source

pub fn with_timestamp(self, ts: DateTime<Utc>) -> Self

Builder method to set the timestamp.

§Example
use chatpack::Message;
use chrono::Utc;

let msg = Message::new("Alice", "Hello")
    .with_timestamp(Utc::now());
assert!(msg.timestamp().is_some());
Source

pub fn with_id(self, id: u64) -> Self

Builder method to set the message ID.

§Example
use chatpack::Message;

let msg = Message::new("Alice", "Hello")
    .with_id(12345);
assert_eq!(msg.id(), Some(12345));
Source

pub fn with_reply_to(self, reply_id: u64) -> Self

Builder method to set the reply reference.

§Example
use chatpack::Message;

let msg = Message::new("Bob", "I agree!")
    .with_reply_to(12344);
assert_eq!(msg.reply_to(), Some(12344));
Source

pub fn with_edited(self, ts: DateTime<Utc>) -> Self

Builder method to set the edited timestamp.

§Example
use chatpack::Message;
use chrono::Utc;

let msg = Message::new("Alice", "Updated message")
    .with_edited(Utc::now());
assert!(msg.edited().is_some());
Source

pub fn sender(&self) -> &str

Returns the sender name.

Source

pub fn content(&self) -> &str

Returns the message content.

Source

pub fn timestamp(&self) -> Option<DateTime<Utc>>

Returns the timestamp, if available.

Source

pub fn id(&self) -> Option<u64>

Returns the message ID, if available.

Source

pub fn reply_to(&self) -> Option<u64>

Returns the reply-to ID, if available.

Source

pub fn edited(&self) -> Option<DateTime<Utc>>

Returns the edited timestamp, if available.

Source

pub fn has_metadata(&self) -> bool

Returns true if this message has any metadata (timestamp, id, reply_to, or edited).

Source

pub fn is_empty(&self) -> bool

Returns true if this message’s content is empty or whitespace-only.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Message

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,