link capability added
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -1,3 +1,4 @@
|
|||||||
|
use reqwest::{Method, RequestBuilder};
|
||||||
use rumqttc::{AsyncClient, Event, MqttOptions, QoS};
|
use rumqttc::{AsyncClient, Event, MqttOptions, QoS};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -30,6 +31,8 @@ struct Notification {
|
|||||||
title: String,
|
title: String,
|
||||||
body: String,
|
body: String,
|
||||||
topic: String,
|
topic: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
link: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -156,16 +159,23 @@ async fn start_notification_daemon(
|
|||||||
// Send to ntfy.sh
|
// Send to ntfy.sh
|
||||||
let url = format!("https://ntfy.sh/{}", notif.topic);
|
let url = format!("https://ntfy.sh/{}", notif.topic);
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
let mut rb : RequestBuilder = client.request(Method::POST, &url)
|
||||||
match client
|
|
||||||
.post(&url)
|
|
||||||
.header("Title", ¬if.title)
|
.header("Title", ¬if.title)
|
||||||
.body(notif.body)
|
.body(notif.body);
|
||||||
.send()
|
if notif.link.is_some() {
|
||||||
.await
|
rb = rb.header("Actions", format!("view, Open Article, {}, clear=true", notif.link.unwrap()));
|
||||||
|
}
|
||||||
|
match rb.build()
|
||||||
{
|
{
|
||||||
|
Ok(request) => {
|
||||||
|
match client.execute(request).await{
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
log::debug!("ntfy.sh status code: {}", resp.status());
|
log::info!("Notification Posted Successfully, {}", resp.status());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to send notification: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("Failed to send notification: {}", e);
|
log::warn!("Failed to send notification: {}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user