use tokio::sync::mpsc;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Capabilities {
pub buttons: bool,
pub edit_message: bool,
pub images: bool,
pub files: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReplyCtx(pub serde_json::Value);
#[derive(Debug, Clone, PartialEq)]
pub struct MessageRef(pub serde_json::Value);
#[derive(Debug, Clone)]
pub struct InboundMessage {
pub platform: String,
pub chat_id: String,
pub user_id: String,
pub message_id: String,
pub sent_at: chrono::DateTime<chrono::Utc>,
pub text: String,
pub reply_ctx: ReplyCtx,
}
#[derive(Debug, Clone)]
pub struct OutboundMessage {
pub text: String,
}
impl OutboundMessage {
pub fn text(text: impl Into<String>) -> Self {
Self { text: text.into() }
}
}
#[derive(Debug, thiserror::Error)]
pub enum PlatformError {
#[error("{0}")]
Other(String),
}
impl PlatformError {
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}
pub type PlatformResult<T> = std::result::Result<T, PlatformError>;
#[async_trait::async_trait]
pub trait Platform: Send + Sync {
fn name(&self) -> &str;
fn capabilities(&self) -> Capabilities;
async fn start(&self, inbound: mpsc::Sender<InboundMessage>) -> PlatformResult<()>;
async fn reply(&self, ctx: &ReplyCtx, msg: OutboundMessage) -> PlatformResult<MessageRef>;
async fn edit(&self, msg_ref: &MessageRef, new: OutboundMessage) -> PlatformResult<()>;
async fn stop(&self) -> PlatformResult<()>;
}