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 pub request: Option<HashMap<String, String>>,
25}
26
27impl Notifica {
28 pub async fn send_message(body: NotificaBody, event: &str, tenant_id: Uuid) {
29 info!("[NOTIFICA-SDK] Tenant '{tenant_id}' event '{event}'");
30 let client = reqwest::Client::new();
31 let response: reqwest::Response = client
32 .post(format!(
33 "https://notifica.flippi.co/webhook/{tenant_id}/{event}"
34 ))
35 .json(&json!(body))
36 .send()
37 .await
38 .unwrap();
39
40 if response.status() == StatusCode::OK {
41 info!("[NOTIFICA-SDK] Request has been accepted");
42 } else {
43 warn!("[NOTIFICA-SDK] Request hasnt been accepted");
44 }
45 }
46}