From 90bde5670882943859ec919d7896063c2142df82 Mon Sep 17 00:00:00 2001 From: Mars Ultor Date: Tue, 12 Aug 2025 22:46:43 -0500 Subject: [PATCH] link capability added --- src/main.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index e966eac..6edcce2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use reqwest::{Method, RequestBuilder}; use rumqttc::{AsyncClient, Event, MqttOptions, QoS}; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -30,6 +31,8 @@ struct Notification { title: String, body: String, topic: String, + #[serde(skip_serializing_if = "Option::is_none")] + link: Option, } #[tokio::main] @@ -156,16 +159,23 @@ async fn start_notification_daemon( // Send to ntfy.sh let url = format!("https://ntfy.sh/{}", notif.topic); let client = reqwest::Client::new(); - - match client - .post(&url) + let mut rb : RequestBuilder = client.request(Method::POST, &url) .header("Title", ¬if.title) - .body(notif.body) - .send() - .await + .body(notif.body); + if notif.link.is_some() { + rb = rb.header("Actions", format!("view, Open Article, {}, clear=true", notif.link.unwrap())); + } + match rb.build() { - Ok(resp) => { - log::debug!("ntfy.sh status code: {}", resp.status()); + Ok(request) => { + match client.execute(request).await{ + Ok(resp) => { + log::info!("Notification Posted Successfully, {}", resp.status()); + } + Err(e) => { + log::warn!("Failed to send notification: {}", e); + } + } } Err(e) => { log::warn!("Failed to send notification: {}", e);