1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
// Send a pushover message.
// token, user, and other opts are as specified at https://pushover.net/api
export async function pushover({ token, user, message, title, device, ...opts }) {
try {
const requestBody = new URLSearchParams({
token,
user,
message,
title,
device,
...opts,
});
const response = await fetch("https://api.pushover.net/1/messages.json", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: requestBody,
});
if (!response.ok) {
const errorData = await response.json();
console.error("Pushover API Error:", errorData);
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error sending Pushover message:", error);
throw error;
}
}
1
Next