notifica_sdk/
lib.rs

1use std::collections::HashMap;
2
3use log::{info, warn};
4use reqwest::StatusCode;
5use serde::{Deserialize, Serialize};
6use serde_json::json;
7use uuid::Uuid;
8
9pub struct Notifica;
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
12pub struct NotificaBodyEmail {
13    pub target_email: Option<String>,
14    pub target_name: Option<String>,
15    pub sender_name: Option<String>,
16    pub subject: Option<String>,
17    pub params: HashMap<String, String>,
18}
19
20#[derive(Clone, Debug, Serialize, Deserialize)]
21pub struct NotificaBody {
22    pub push: Option<HashMap<String, String>>,
23    pub email: Option<NotificaBodyEmail>,
24}
25
26impl Notifica {
27    pub async fn send_message(body: NotificaBody, event: &str, tenant_id: Uuid) {
28        info!("[NOTIFICA-SDK] Tenant '{tenant_id}' event '{event}'");
29        let client = reqwest::Client::new();
30        let response: reqwest::Response = client
31            .post(format!(
32                "https://notifica.flippi.co/webhook/{tenant_id}/{event}"
33            ))
34            .json(&json!(body))
35            .send()
36            .await
37            .unwrap();
38
39        if response.status() == StatusCode::OK {
40            info!("[NOTIFICA-SDK] Request has been accepted");
41        } else {
42            warn!("[NOTIFICA-SDK] Request hasnt been accepted");
43        }
44    }
45}