use jiff::Timestamp;
use serde::{Deserialize, Serialize};
use crate::id::{ConversationKey, MessageId, UserRef};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "kebab-case")]
#[non_exhaustive]
pub enum Attachment {
Image {
url: String,
caption: Option<String>,
},
Audio {
url: String,
},
Sticker {
id: String,
},
File {
url: String,
name: Option<String>,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct InboundEvent {
pub event_id: String,
pub conversation: ConversationKey,
pub author: UserRef,
pub text: String,
pub attachments: Vec<Attachment>,
pub mentions_bot: bool,
pub is_direct: bool,
pub restricted: bool,
pub message_id: Option<MessageId>,
pub sent_at: Timestamp,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub locale: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReplyTarget {
pub conversation: ConversationKey,
pub in_reply_to: Option<MessageId>,
}
impl ReplyTarget {
pub fn to_event(event: &InboundEvent) -> Self {
Self {
conversation: event.conversation.clone(),
in_reply_to: event.message_id.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct OutboundMessage {
pub markdown: String,
pub attachments: Vec<Attachment>,
}
impl OutboundMessage {
pub fn text(markdown: impl Into<String>) -> Self {
Self {
markdown: markdown.into(),
attachments: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RenderedMessage {
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SentRef {
pub target: ReplyTarget,
pub message_id: MessageId,
}