#![allow(dead_code)]
use anyhow::Result;
use serde::{Deserialize, Serialize};
pub mod telegram;
pub mod whatsapp;
pub mod listener;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MessagingProvider {
Telegram,
WhatsApp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessagingConfig {
pub enabled: bool,
pub provider: MessagingProvider,
pub telegram_bot_token: Option<String>,
pub whatsapp_api_key: Option<String>,
pub whatsapp_phone_number: Option<String>,
pub allowed_chat_ids: Vec<String>,
pub commands_enabled: bool,
pub status_notifications: bool,
}
impl Default for MessagingConfig {
fn default() -> Self {
Self {
enabled: false,
provider: MessagingProvider::Telegram,
telegram_bot_token: None,
whatsapp_api_key: None,
whatsapp_phone_number: None,
allowed_chat_ids: Vec::new(),
commands_enabled: true,
status_notifications: false,
}
}
}
pub struct MessagingManager {
config: MessagingConfig,
}
impl MessagingManager {
pub fn new(config: MessagingConfig) -> Result<Self> {
Ok(Self { config })
}
pub fn is_enabled(&self) -> bool {
self.config.enabled &&
(self.config.telegram_bot_token.is_some() || self.config.whatsapp_api_key.is_some())
}
pub async fn send_telegram_message(&self, chat_id: &str, text: &str) -> Result<()> {
if let Some(token) = &self.config.telegram_bot_token {
telegram::send_message(token, chat_id, text).await?;
}
Ok(())
}
pub async fn send_whatsapp_message(&self, phone: &str, text: &str) -> Result<()> {
if let (Some(key), Some(from_phone)) = (&self.config.whatsapp_api_key, &self.config.whatsapp_phone_number) {
whatsapp::send_message(key, from_phone, phone, text).await?;
}
Ok(())
}
pub async fn send_status(&self, status: &str) -> Result<()> {
if !self.is_enabled() {
return Ok(());
}
for chat_id in &self.config.allowed_chat_ids {
match self.config.provider {
MessagingProvider::Telegram => {
self.send_telegram_message(chat_id, status).await?;
}
MessagingProvider::WhatsApp => {
self.send_whatsapp_message(chat_id, status).await?;
}
}
}
Ok(())
}
pub fn get_help_text(&self) -> String {
r#"📱 Available Commands:
/status - Get i-self status
/suggestions - View AI suggestions
/activity - View current activity
/screenshot - Take screenshot
/help - Show this help
Configure via:
- Telegram: Set TELEGRAM_BOT_TOKEN
- WhatsApp: Set WHATSAPP_API_KEY and WHATSAPP_PHONE"#.to_string()
}
}