use std::collections::HashMap;
use async_trait::async_trait;
use crate::Result;
use crate::types::{ChatMetadata, NewMessage, RegisteredGroup};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChannelType {
Markdown,
Telegram,
WhatsApp,
Slack,
Signal,
Plain,
}
#[async_trait]
pub trait Channel: Send + Sync {
fn name(&self) -> &str;
fn channel_type(&self) -> ChannelType {
ChannelType::Markdown
}
async fn connect(&self) -> Result<()>;
async fn send_message(&self, jid: &str, text: &str) -> Result<()>;
fn is_connected(&self) -> bool;
fn owns_jid(&self, jid: &str) -> bool;
async fn disconnect(&self) -> Result<()>;
async fn set_typing(&self, _jid: &str, _is_typing: bool) -> Result<()> {
Ok(())
}
async fn on_turn_complete(&self, _jid: &str) -> Result<()> {
Ok(())
}
async fn sync_groups(&self, _force: bool) -> Result<()> {
Ok(())
}
}
#[async_trait]
pub trait ChannelHost: Send + Sync {
async fn on_message(&self, chat_jid: &str, message: NewMessage);
async fn on_chat_metadata(&self, metadata: ChatMetadata);
fn registered_groups(&self) -> HashMap<String, RegisteredGroup>;
async fn register_group(&self, jid: &str, group: RegisteredGroup, persist: bool);
async fn unregister_group(&self, jid: &str) -> bool;
async fn clear_session(&self, jid: &str) -> bool;
fn notify_tasks_changed(&self);
fn queue_status(&self) -> QueueStatus {
QueueStatus::default()
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct QueueStatus {
pub active_containers: usize,
pub max_containers: usize,
pub waiting_groups: usize,
pub active_jids: Vec<String>,
}