greentic_types/
messaging.rs

1//! Generic channel messaging envelope shared across providers.
2
3use alloc::{collections::BTreeMap, string::String, vec::Vec};
4
5#[cfg(feature = "schemars")]
6use schemars::JsonSchema;
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10use crate::TenantCtx;
11
12/// Collection of metadata entries associated with a channel message.
13pub type MessageMetadata = BTreeMap<String, String>;
14
15/// Generic attachment referenced by a channel message.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18#[cfg_attr(feature = "schemars", derive(JsonSchema))]
19pub struct Attachment {
20    /// MIME type of the attachment (for example `image/png`).
21    pub mime_type: String,
22    /// URL pointing at the attachment payload.
23    pub url: String,
24    /// Optional display name for the attachment.
25    #[cfg_attr(
26        feature = "serde",
27        serde(default, skip_serializing_if = "Option::is_none")
28    )]
29    pub name: Option<String>,
30    /// Optional attachment size in bytes.
31    #[cfg_attr(
32        feature = "serde",
33        serde(default, skip_serializing_if = "Option::is_none")
34    )]
35    pub size_bytes: Option<u64>,
36}
37
38/// Envelope for channel messages exchanged with adapters.
39#[derive(Clone, Debug, PartialEq, Eq)]
40#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41#[cfg_attr(feature = "schemars", derive(JsonSchema))]
42pub struct ChannelMessageEnvelope {
43    /// Stable identifier for the message.
44    pub id: String,
45    /// Tenant context propagated with the message.
46    pub tenant: TenantCtx,
47    /// Abstract channel identifier or type.
48    pub channel: String,
49    /// Conversation or thread identifier.
50    pub session_id: String,
51    /// Optional user identifier associated with the message.
52    #[cfg_attr(
53        feature = "serde",
54        serde(default, skip_serializing_if = "Option::is_none")
55    )]
56    pub user_id: Option<String>,
57    /// Optional text content.
58    #[cfg_attr(
59        feature = "serde",
60        serde(default, skip_serializing_if = "Option::is_none")
61    )]
62    pub text: Option<String>,
63    /// Attachments included with the message.
64    #[cfg_attr(
65        feature = "serde",
66        serde(default, skip_serializing_if = "Vec::is_empty")
67    )]
68    pub attachments: Vec<Attachment>,
69    /// Free-form metadata for adapters and flows.
70    #[cfg_attr(feature = "serde", serde(default))]
71    pub metadata: MessageMetadata,
72}