add webhook

This commit is contained in:
JMARyA 2024-03-17 18:17:36 +01:00
parent 6b16402126
commit a91d8eebf4
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 56 additions and 3 deletions

View file

@ -77,4 +77,14 @@ impl Config {
let token = settings.get("token")?.as_str()?.to_string();
Some(GotifySettings { host, token })
}
pub fn webhook_config(&self) -> Option<String> {
Some(
self.root
.get("notify")?
.get("webhook")?
.as_str()?
.to_string(),
)
}
}

View file

@ -1,12 +1,28 @@
use crate::config;
use crate::config::Config;
use actix_web::web::Data;
use actix_web::web::{self, Data};
use log::info;
pub async fn notify(msg: &str, title: &str, config: Data<Config>) {
if let Some(gotify) = config.gotify_config() {
gotify_notification(msg, title, gotify).await;
}
if let Some(webhook) = config.webhook_config() {
info!("Sending webhook notification");
let request =
serde_json::json!({
"instance": config.name(),
"title": title,
"msg": msg
});
let client = reqwest::blocking::Client::new();
client
.post(webhook)
.json(&request)
.send()
.expect("Failed to send webhook request");
}
}
async fn gotify_notification(msg: &str, title: &str, config: config::GotifySettings) {