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) => {
+1
View File
@@ -562,6 +562,7 @@ export interface AppSettings {
healthChecks: HealthCheckSettings;
digest: DigestSettings;
signIn: SignInSettings;
alertActions: { enabled: boolean };
profilePictures: ProfilePictureSettings;
monthlyReport: MonthlyReportSettings;
}
@@ -0,0 +1,71 @@
import { useEffect, useState } from "react";
import { api } from "../../api/client";
import { readableError } from "../../utils/errors";
import { toast } from "../../utils/toast";
/**
* Buttons on notifications: Acknowledge, Silence for an hour and Snooze until tomorrow, pressed from the message itself without signing in. Its own switch, saved at once (it is not
* part of the page's Save, since it is not a notification setting so much as a way of acting on one).
*/
export default function AlertActionsCard() {
const [enabled, setEnabled] = useState<boolean | null>(null);
const [busy, setBusy] = useState(false);
useEffect(() => {
let alive = true;
api.settings
.get()
.then((res) => alive && setEnabled(res.settings.alertActions?.enabled ?? false))
.catch(() => alive && setEnabled(false));
return () => {
alive = false;
};
}, []);
async function change(value: boolean) {
setBusy(true);
try {
await api.settings.update({ alertActions: { enabled: value } });
setEnabled(value);
toast.success(value ? "Notifications now carry buttons." : "Buttons on notifications are switched off; their links stop working.");
} catch (err) {
toast.error(readableError(err));
} finally {
setBusy(false);
}
}
return (
<div className="card mt-3">
<div className="card-header">
<h3 className="card-title">Buttons on notifications</h3>
</div>
<div className="card-body">
<p className="text-secondary">
Let a notification itself carry <strong>Acknowledge</strong>, <strong>Silence for an hour</strong> and <strong>Snooze until tomorrow</strong> — as buttons on an ntfy message or a phone push, and as a link in an email, a Gotify message or the chat
webhook — so a problem can be dealt with from the lock screen, without opening the app or signing in.
</p>
<label className="form-check mb-3">
<input type="checkbox" className="form-check-input" checked={enabled === true} disabled={enabled === null || busy} onChange={(e) => void change(e.target.checked)} />
<span className="form-check-label">Put buttons on notifications</span>
</label>
<ul className="text-secondary small mb-3">
<li>
<strong>Each link is for the alerts in that one message and can do only those three things.</strong> It cannot read anything, change a setting or reach any other part of the app, and it stops working after
24 hours.
</li>
<li>
<strong>Anyone who can read the notification can press its buttons</strong> while it lasts. That is fine for a private ntfy topic, a Gotify server of your own, your own phone or your own inbox; it is not for a
public ntfy.sh topic or a chat channel with guests in it.
</li>
<li>Opening a link never does anything — a link preview or a mail scanner is harmless; only pressing a button acts. Everything it does is in the audit log as <em>from a notification link</em>, with where it came from.</li>
<li>
Messages about <em>one</em> alert get buttons (ntfy: three; a phone push: two); messages about several get one link to a page that lists them. A message held for quiet hours is sent without them. Changing the
<code> SESSION_SECRET</code> ends every link at once; switching this off does too.
</li>
<li>The links are built from the address people reach this app at (<code>APP_BASE_URL</code>); it has to be one your phone can open.</li>
</ul>
</div>
</div>
);
}
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { useSearchParams } from "react-router-dom";
import AlertActionsCard from "./AlertActionsCard";
import {
api,
type AppSettings,
@@ -879,6 +880,7 @@ export default function NotificationSettings() {
onEscalation={setEscalation}
channelsOn={{ gotify: gotify.enabled && gotifyComplete, ntfy: ntfy.enabled && ntfyComplete, smtp: smtp.enabled && smtpComplete, webhook: webhook.enabled && webhookComplete, webPush: webPush.enabled }}
/>
<AlertActionsCard />
</div>
{/* ── When ── */}