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
| Field | Type | Description |
|---|---|---|
sender | String | Display name or username of the message author |
content | String | Text content of the message |
timestamp | Option<DateTime<Utc>> | When the message was sent |
id | Option<u64> | Platform-specific message identifier |
reply_to | Option<u64> | ID of the parent message (for replies) |
edited | Option<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: StringDisplay name or username of the message author.
content: StringText 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
impl Message
Sourcepub fn new(sender: impl Into<String>, content: impl Into<String>) -> Self
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());Sourcepub 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
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.
Sourcepub fn with_timestamp(self, ts: DateTime<Utc>) -> Self
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());Sourcepub fn with_id(self, id: u64) -> Self
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));Sourcepub fn with_reply_to(self, reply_id: u64) -> Self
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));Sourcepub fn with_edited(self, ts: DateTime<Utc>) -> Self
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());Sourcepub fn has_metadata(&self) -> bool
pub fn has_metadata(&self) -> bool
Returns true if this message has any metadata (timestamp, id, reply_to, or edited).