Skip to main content

ciab_core/traits/
channel.rs

1use async_trait::async_trait;
2use tokio::sync::mpsc;
3
4use crate::error::CiabResult;
5use crate::types::channel::{ChannelState, InboundMessage};
6
7/// Adapter trait for messaging platform integrations.
8#[async_trait]
9pub trait ChannelAdapter: Send + Sync {
10    /// Human-readable provider name (e.g. "whatsapp", "slack", "webhook").
11    fn provider_name(&self) -> &str;
12
13    /// Start the adapter and return a receiver for inbound messages.
14    async fn start(&self) -> CiabResult<mpsc::Receiver<InboundMessage>>;
15
16    /// Send a message back to the platform.
17    async fn send(&self, recipient_id: &str, content: &str) -> CiabResult<()>;
18
19    /// Current adapter state.
20    fn state(&self) -> ChannelState;
21
22    /// QR code data (WhatsApp pairing).
23    fn qr_code(&self) -> Option<String> {
24        None
25    }
26
27    /// Gracefully shut down the adapter.
28    async fn shutdown(&self) -> CiabResult<()>;
29}