link capability added

This commit is contained in:
2025-08-12 22:46:43 -05:00
parent 95df8adc12
commit 90bde56708

View File

@@ -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<String>,
}
#[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", &notif.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);