pub mod discord;
pub mod matrix;
use async_trait::async_trait;
#[derive(Debug, Clone)]
pub struct IncomingMessage {
pub id: String,
pub sender: String,
pub content: String,
pub room_id: String,
pub timestamp: u64,
pub thread_id: Option<String>,
}
#[derive(Debug, Clone)]
pub struct OutgoingMessage {
pub content: String,
pub room_id: String,
pub thread_id: Option<String>,
}
impl OutgoingMessage {
pub fn new(content: impl Into<String>, room_id: impl Into<String>) -> Self {
Self {
content: content.into(),
room_id: room_id.into(),
thread_id: None,
}
}
}
#[async_trait]
pub trait Channel: Send + Sync {
fn name(&self) -> &str;
async fn send(&self, message: &OutgoingMessage) -> anyhow::Result<()>;
async fn listen(&self, tx: tokio::sync::mpsc::Sender<IncomingMessage>) -> anyhow::Result<()>;
async fn start_typing(&self, _room_id: &str) -> anyhow::Result<()> {
Ok(())
}
async fn stop_typing(&self, _room_id: &str) -> anyhow::Result<()> {
Ok(())
}
}