pub struct PlainMessage<T = Value> {Show 13 fields
pub id: String,
pub typ: String,
pub type_: String,
pub body: T,
pub from: String,
pub to: Vec<String>,
pub thid: Option<String>,
pub pthid: Option<String>,
pub extra_headers: HashMap<String, Value>,
pub created_time: Option<u64>,
pub expires_time: Option<u64>,
pub from_prior: Option<String>,
pub attachments: Option<Vec<Attachment>>,
}Expand description
Wrapper for plain message. Provides helpers for message building and packing/unpacking. Adapted from https://github.com/sicpa-dlab/didcomm-rust/blob/main/src/message/message.rs
Fields§
§id: StringMessage id. Must be unique to the sender.
typ: StringOptional, if present it must be “application/didcomm-plain+json”
type_: StringMessage type attribute value MUST be a valid Message Type URI, that when resolved gives human readable information about the message. The attribute’s value also informs the content of the message, or example the presence of other attributes and how they should be processed.
body: TMessage body - strongly typed when T is specified.
from: StringSender identifier. The from attribute MUST be a string that is a valid DID or DID URL (without the fragment component) which identifies the sender of the message.
to: Vec<String>Identifier(s) for recipients. MUST be an array of strings where each element is a valid DID or DID URL (without the fragment component) that identifies a member of the message’s intended audience.
thid: Option<String>Uniquely identifies the thread that the message belongs to.
If not included the id property of the message MUST be treated as the value of the thid.
pthid: Option<String>If the message is a child of a thread the pthid
will uniquely identify which thread is the parent.
extra_headers: HashMap<String, Value>Custom message headers.
created_time: Option<u64>The attribute is used for the sender to express when they created the message, expressed in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC). This attribute is informative to the recipient, and may be relied on by protocols.
expires_time: Option<u64>The expires_time attribute is used for the sender to express when they consider the message to be expired, expressed in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC). This attribute signals when the message is considered no longer valid by the sender. When omitted, the message is considered to have no expiration by the sender.
from_prior: Option<String>from_prior is a compactly serialized signed JWT containing FromPrior value
attachments: Option<Vec<Attachment>>Implementations§
Source§impl<T> PlainMessage<T>where
T: Serialize + DeserializeOwned,
impl<T> PlainMessage<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn new(id: String, type_: String, body: T, from: String) -> Self
pub fn new(id: String, type_: String, body: T, from: String) -> Self
Create a new PlainMessage with the given body
Sourcepub fn with_recipients(self, to: Vec<String>) -> Self
pub fn with_recipients(self, to: Vec<String>) -> Self
Builder method to set recipients
Sourcepub fn with_recipient(self, recipient: &str) -> Self
pub fn with_recipient(self, recipient: &str) -> Self
Builder method to add a single recipient
Sourcepub fn with_thread_id(self, thid: Option<String>) -> Self
pub fn with_thread_id(self, thid: Option<String>) -> Self
Builder method to set thread ID
Sourcepub fn with_parent_thread_id(self, pthid: Option<String>) -> Self
pub fn with_parent_thread_id(self, pthid: Option<String>) -> Self
Builder method to set parent thread ID
Sourcepub fn with_expires_at(self, expires_time: u64) -> Self
pub fn with_expires_at(self, expires_time: u64) -> Self
Builder method to set expiration time
Sourcepub fn with_attachments(self, attachments: Vec<Attachment>) -> Self
pub fn with_attachments(self, attachments: Vec<Attachment>) -> Self
Builder method to add attachments
Sourcepub fn with_header(self, key: String, value: Value) -> Self
pub fn with_header(self, key: String, value: Value) -> Self
Builder method to add a custom header
Source§impl<T> PlainMessage<T>
impl<T> PlainMessage<T>
Sourcepub fn to_plain_message(self) -> Result<PlainMessage<Value>>
pub fn to_plain_message(self) -> Result<PlainMessage<Value>>
Convert to untyped PlainMessage for serialization/transport
Sourcepub fn extract_participants(&self) -> Vec<String>
pub fn extract_participants(&self) -> Vec<String>
Extract recipients based on the message body participants
Source§impl<T> PlainMessage<T>
impl<T> PlainMessage<T>
Sourcepub fn extract_participants_with_context(&self) -> Vec<String>
pub fn extract_participants_with_context(&self) -> Vec<String>
Extract participants using MessageContext
Sourcepub fn new_typed_with_context(body: T, from: &str) -> Self
pub fn new_typed_with_context(body: T, from: &str) -> Self
Create a typed message with automatic recipient detection
Sourcepub fn routing_hints(&self) -> RoutingHints
pub fn routing_hints(&self) -> RoutingHints
Get routing hints from the message body
Sourcepub fn transaction_context(&self) -> Option<TransactionContext>
pub fn transaction_context(&self) -> Option<TransactionContext>
Get transaction context from the message body
Source§impl PlainMessage<Value>
impl PlainMessage<Value>
Sourcepub fn from_untyped(plain_msg: PlainMessage<Value>) -> Self
pub fn from_untyped(plain_msg: PlainMessage<Value>) -> Self
Create a typed message from an untyped PlainMessage
Sourcepub fn parse_body<T: TapMessageBody>(self) -> Result<PlainMessage<T>>
pub fn parse_body<T: TapMessageBody>(self) -> Result<PlainMessage<T>>
Try to parse the body into a specific TAP message type
Sourcepub fn parse_tap_message(&self) -> Result<TapMessage>
pub fn parse_tap_message(&self) -> Result<TapMessage>
Parse into the TapMessage enum for runtime dispatch
Trait Implementations§
Source§impl<T: Clone> Clone for PlainMessage<T>
impl<T: Clone> Clone for PlainMessage<T>
Source§fn clone(&self) -> PlainMessage<T>
fn clone(&self) -> PlainMessage<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Connectable for PlainMessage
impl Connectable for PlainMessage
Source§fn with_connection(&mut self, connection_id: &str) -> &mut Self
fn with_connection(&mut self, connection_id: &str) -> &mut Self
Source§fn has_connection(&self) -> bool
fn has_connection(&self) -> bool
Source§impl<T: Debug> Debug for PlainMessage<T>
impl<T: Debug> Debug for PlainMessage<T>
Source§impl<'de, T> Deserialize<'de> for PlainMessage<T>where
T: Serialize + DeserializeOwned,
impl<'de, T> Deserialize<'de> for PlainMessage<T>where
T: Serialize + DeserializeOwned,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: PartialEq> PartialEq for PlainMessage<T>
impl<T: PartialEq> PartialEq for PlainMessage<T>
Source§impl PlainMessageExt<Value> for PlainMessage<Value>
impl PlainMessageExt<Value> for PlainMessage<Value>
Source§fn into_typed(self) -> PlainMessage<Value>
fn into_typed(self) -> PlainMessage<Value>
Source§fn parse_as<U: TapMessageBody>(self) -> Result<PlainMessage<U>>
fn parse_as<U: TapMessageBody>(self) -> Result<PlainMessage<U>>
Source§impl<T> Serialize for PlainMessage<T>where
T: Serialize + DeserializeOwned,
impl<T> Serialize for PlainMessage<T>where
T: Serialize + DeserializeOwned,
Source§impl TapMessage for PlainMessage
impl TapMessage for PlainMessage
Source§fn is_tap_message(&self) -> bool
fn is_tap_message(&self) -> bool
Source§fn get_tap_type(&self) -> Option<String>
fn get_tap_type(&self) -> Option<String>
Source§fn body_as<T: TapMessageBody>(&self) -> Result<T>
fn body_as<T: TapMessageBody>(&self) -> Result<T>
Source§fn get_all_participants(&self) -> Vec<String>
fn get_all_participants(&self) -> Vec<String>
Source§fn parent_thread_id(&self) -> Option<&str>
fn parent_thread_id(&self) -> Option<&str>
Source§fn message_id(&self) -> &str
fn message_id(&self) -> &str
Source§fn create_reply<T: TapMessageBody>(
&self,
body: &T,
creator_did: &str,
) -> Result<PlainMessage>
fn create_reply<T: TapMessageBody>( &self, body: &T, creator_did: &str, ) -> Result<PlainMessage>
Source§impl<T: TapMessageBody> TryFrom<PlainMessage<T>> for TapMessagewhere
TapMessage: From<T>,
Helper to convert between typed messages and TapMessage enum
impl<T: TapMessageBody> TryFrom<PlainMessage<T>> for TapMessagewhere
TapMessage: From<T>,
Helper to convert between typed messages and TapMessage enum