Skip to main content

aagt_core/infra/
notification.rs

1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use crate::error::Result;
4
5/// Notification channel types
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename_all = "snake_case")]
8pub enum NotifyChannel {
9    /// Send an email
10    Email,
11    /// Send via Telegram
12    Telegram,
13    /// Send via Discord
14    Discord,
15    /// Send to a generic Webhook
16    Webhook { url: String },
17    /// Log to console/file
18    Log,
19}
20
21/// Trait for sending notifications
22/// 
23/// Implement this trait to connect the Agent to external communication systems
24/// like Telegram bots, Discord webhooks, or email servers.
25#[async_trait]
26pub trait Notifier: Send + Sync {
27    /// Send a notification
28    async fn notify(&self, channel: NotifyChannel, message: &str) -> Result<()>;
29}
30
31/// A no-op notifier that logs to tracing
32pub struct LogNotifier;
33
34#[async_trait]
35impl Notifier for LogNotifier {
36    async fn notify(&self, channel: NotifyChannel, message: &str) -> Result<()> {
37        let channel_name = match channel {
38            NotifyChannel::Email => "Email",
39            NotifyChannel::Telegram => "Telegram",
40            NotifyChannel::Discord => "Discord",
41            NotifyChannel::Webhook { .. } => "Webhook",
42            NotifyChannel::Log => "Log",
43        };
44        tracing::info!("[Notification via {}]: {}", channel_name, message);
45        Ok(())
46    }
47}