pakem/core/notification/
mod.rs1use async_trait::async_trait;
2use serde_json::Value;
3
4#[async_trait]
6pub trait Notification: Send + Sync {
7 fn subject(&self) -> String {
9 "Notification from Lumina".to_string()
10 }
11
12 fn to_mail(&self) -> Option<(String, Value)> {
14 None
15 }
16
17 fn to_database(&self) -> Option<Value> {
19 None
20 }
21
22 fn to_whatsapp(&self) -> Option<String> {
24 None
25 }
26}
27
28pub struct Notify;
30
31impl Notify {
32 pub async fn send<N>(
34 req: &crate::core::request::Request,
35 to_email: &str,
36 notification: N,
37 ) -> Result<(), String>
38 where
39 N: Notification,
40 {
41 if let Some((template, data)) = notification.to_mail() {
42 req.mail()
43 .to(to_email)
44 .subject(¬ification.subject())
45 .send(&template, data)
46 .await?;
47 }
48 Ok(())
49 }
50}