add webhook
This commit is contained in:
parent
6b16402126
commit
a91d8eebf4
5 changed files with 56 additions and 3 deletions
|
@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue