apollo/channels/
traits.rs1use async_trait::async_trait;
5use serde::{Deserialize, Serialize};
6use tokio::sync::mpsc;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct IncomingMessage {
11 pub id: String,
12 pub sender_id: String,
13 pub sender_name: Option<String>,
14 pub chat_id: String,
15 pub text: String,
16 pub is_group: bool,
17 pub reply_to: Option<String>,
18 pub timestamp: chrono::DateTime<chrono::Utc>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct OutgoingMessage {
24 pub chat_id: String,
25 pub text: String,
26 pub reply_to: Option<String>,
27}
28
29#[async_trait]
32pub trait Channel: Send + Sync {
33 fn name(&self) -> &str;
35
36 async fn start(&mut self) -> anyhow::Result<mpsc::Receiver<IncomingMessage>>;
38
39 async fn send(&self, message: OutgoingMessage) -> anyhow::Result<Option<String>>;
41
42 async fn send_typing(&self, _chat_id: &str) -> anyhow::Result<()> {
44 Ok(())
45 }
46
47 async fn edit(&self, _chat_id: &str, _message_id: &str, _new_text: &str) -> anyhow::Result<()> {
49 Ok(())
50 }
51
52 fn supports_draft_updates(&self) -> bool {
54 false
55 }
56
57 async fn send_draft(&self, _chat_id: &str, _text: &str) -> anyhow::Result<Option<String>> {
59 Ok(None)
60 }
61
62 async fn update_draft_progress(
64 &self,
65 _chat_id: &str,
66 _message_id: &str,
67 _text: &str,
68 ) -> anyhow::Result<()> {
69 Ok(())
70 }
71
72 async fn finalize_draft(
74 &self,
75 _chat_id: &str,
76 _message_id: &str,
77 _text: &str,
78 ) -> anyhow::Result<()> {
79 Ok(())
80 }
81
82 async fn stop(&mut self) -> anyhow::Result<()>;
84}