send notification to notifier service instead of handling all possible ways to send stuff directly.

This commit is contained in:
OMGeeky
2024-05-04 00:36:44 +02:00
parent 6cf97bca74
commit 062e02a676
3 changed files with 26 additions and 18 deletions

10
Cargo.lock generated
View File

@@ -3356,8 +3356,8 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "twba-backup-config"
version = "0.1.7"
source = "git+https://github.com/OMGeeky/backup_config.git#fc38fbc800071ca0bddf8d15714b8eb6df17d750"
version = "0.1.8"
source = "git+https://github.com/OMGeeky/backup_config.git#4df6e6ff94e0f221a0cb4eedc276d7403a1f4d21"
dependencies = [
"confique",
"serde",
@@ -3367,8 +3367,8 @@ dependencies = [
[[package]]
name = "twba-common"
version = "0.2.3"
source = "git+https://github.com/OMGeeky/twba.common.git#3e502063cc36b06c0d2aa41bddd89f999f35d6e8"
version = "0.2.4"
source = "git+https://github.com/OMGeeky/twba.common.git#33ffb76e2e65548f849bf05c5747a86c6ae90633"
dependencies = [
"serde",
"tracing",
@@ -3406,7 +3406,7 @@ dependencies = [
[[package]]
name = "twba-uploader"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"chrono",
"futures",

View File

@@ -1,6 +1,6 @@
[package]
name = "twba-uploader"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -85,20 +85,28 @@ impl<USER: EasyString> CustomFlowDelegate<USER> {
);
println!("{}", message);
info!("{}", message);
if let Some(webhook) = &crate::CONF.notifier.webhook_url {
trace!(
"sending notification to webhook: {}...",
&webhook[0..webhook.len().min(20)] // only show first 20 characters of webhook
);
reqwest::Client::new()
.post(webhook)
.json(&NotificationRequest { message })
.send()
.await
.map_err(|e| format!("Error sending request: {:?}", e))?;
}
Self::send_notification(message).await;
Ok(())
}
async fn send_notification(message: String) {
let notifier_url = &crate::CONF.notifier.notifier_url;
trace!("sending notification at: {}...", notifier_url);
let response = reqwest::Client::new()
.post(notifier_url)
.json(&NotificationRequest { message })
.send()
.await
.map_err(|e| format!("Error sending request: {:?}", e));
match response {
Ok(_) => {
trace!("Notification sent successfully");
}
Err(e) => {
error!("Error sending notification: {}", e);
}
}
}
}
#[instrument]
async fn get_auth_code() -> Result<String> {