Buttons on notifications: acknowledge, silence and snooze from the message

- A switch (off by default) under Settings -> Notifications -> Who hears what
- ntfy gets buttons (three for one alert, one link for several); phone push gets two buttons handled by the service worker; Gotify, email and the chat webhook get the link as text; escalation messages carry them too
- Each link is a signed token for the alerts in that one message only, good for 24 hours, for three actions; opening it changes nothing, only a POST acts; everything is audited as "from a notification link"
- Docs updated

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-21 20:42:04 +02:00
1 parent 0277126add
commit aebf3c6ce1
22 files changed
+895 -28

No files matched your search

+13 -1
View File
@@ -22,13 +22,25 @@ self.addEventListener("push", (event) => {
icon: "/icon-192.png",
badge: "/favicon-32.png",
tag: data.tag || undefined,
data: { url: typeof data.url === "string" && data.url.startsWith("/") ? data.url : "/alerts" },
// Buttons (Acknowledge, Silence): a press sends its own address, which is for this alert only, and says how it went.
actions: Array.isArray(data.actions) ? data.actions.filter((a) => a && typeof a.action === "string" && typeof a.title === "string").slice(0, 3).map((a) => ({ action: a.action, title: a.title })) : [],
data: { url: typeof data.url === "string" && data.url.startsWith("/") ? data.url : "/alerts", actions: Array.isArray(data.actions) ? data.actions : [] },
}),
);
});
self.addEventListener("notificationclick", (event) => {
event.notification.close();
const pressed = event.action && ((event.notification.data && event.notification.data.actions) || []).find((a) => a.action === event.action);
if (pressed && typeof pressed.path === "string" && pressed.path.startsWith("/api/alert-actions/")) {
event.waitUntil(
fetch(pressed.path, { method: "POST", headers: { Accept: "application/json" }, credentials: "omit" })
.then((r) => r.json().catch(() => ({})).then((body) => ({ ok: r.ok, message: (body && body.message) || (r.ok ? "Done." : "That didn't work.") })))
.catch(() => ({ ok: false, message: "Couldn't reach Homelab Manager." }))
.then((result) => self.registration.showNotification(result.ok ? pressed.title + ": done" : "Not done", { body: result.message, icon: "/icon-192.png", badge: "/favicon-32.png", tag: "alert-action-result" })),
);
return;
}
const target = new URL((event.notification.data && event.notification.data.url) || "/alerts", self.location.origin).href;
event.waitUntil(
self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((windows) => {