omni-notify-mcp 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ const COLOR_MAP = { low: 0x6b7280, normal: 0x7c6dfa, high: 0xef4444 };
2
+ export async function sendDiscord(config, message, priority = "normal", title = "Claude Notify") {
3
+ if (!config.enabled)
4
+ return;
5
+ const res = await fetch(config.webhookUrl, {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({
9
+ username: config.username ?? "Claude Notify",
10
+ embeds: [{
11
+ title,
12
+ description: message,
13
+ color: COLOR_MAP[priority] ?? COLOR_MAP.normal,
14
+ timestamp: new Date().toISOString(),
15
+ }],
16
+ }),
17
+ });
18
+ if (!res.ok)
19
+ throw new Error(`Discord ${res.status}: ${await res.text()}`);
20
+ }
@@ -0,0 +1,21 @@
1
+ const PRIORITY_MAP = { low: 2, normal: 3, high: 5 };
2
+ export async function sendNtfy(config, message, priority = "normal", title = "Claude Notify") {
3
+ if (!config.enabled)
4
+ return;
5
+ const base = (config.serverUrl ?? "https://ntfy.sh").replace(/\/$/, "");
6
+ const headers = {
7
+ "Content-Type": "text/plain",
8
+ "Title": title,
9
+ "Priority": String(PRIORITY_MAP[priority] ?? 3),
10
+ "Tags": priority === "high" ? "rotating_light" : "bell",
11
+ };
12
+ if (config.token)
13
+ headers["Authorization"] = `Bearer ${config.token}`;
14
+ const res = await fetch(`${base}/${encodeURIComponent(config.topic)}`, {
15
+ method: "POST",
16
+ headers,
17
+ body: message,
18
+ });
19
+ if (!res.ok)
20
+ throw new Error(`ntfy ${res.status}: ${await res.text()}`);
21
+ }
@@ -0,0 +1,26 @@
1
+ const PRIORITY_MAP = { low: -1, normal: 0, high: 1 };
2
+ export async function sendPushover(config, message, priority = "normal", title = "Claude Notify") {
3
+ if (!config.enabled)
4
+ return;
5
+ const params = new URLSearchParams({
6
+ token: config.appToken,
7
+ user: config.userKey,
8
+ message,
9
+ title,
10
+ priority: String(PRIORITY_MAP[priority] ?? 0),
11
+ sound: config.sound ?? "pushover",
12
+ });
13
+ if (config.device)
14
+ params.set("device", config.device);
15
+ // priority=1 (high) bypasses quiet hours on the device but doesn't require
16
+ // retry/expire like emergency (2). We deliberately avoid emergency mode to
17
+ // prevent infinite retries for agent notifications.
18
+ const res = await fetch("https://api.pushover.net/1/messages.json", {
19
+ method: "POST",
20
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
21
+ body: params.toString(),
22
+ });
23
+ const json = await res.json();
24
+ if (json.status !== 1)
25
+ throw new Error(`Pushover error: ${JSON.stringify(json.errors ?? json)}`);
26
+ }
@@ -0,0 +1,25 @@
1
+ const EMOJI_MAP = { low: "ℹ️", normal: "🔔", high: "🚨" };
2
+ export async function sendSlack(config, message, priority = "normal", title = "Claude Notify") {
3
+ if (!config.enabled)
4
+ return;
5
+ const emoji = EMOJI_MAP[priority] ?? EMOJI_MAP.normal;
6
+ const res = await fetch(config.webhookUrl, {
7
+ method: "POST",
8
+ headers: { "Content-Type": "application/json" },
9
+ body: JSON.stringify({
10
+ text: `${emoji} *${title}*`,
11
+ blocks: [
12
+ {
13
+ type: "section",
14
+ text: { type: "mrkdwn", text: `${emoji} *${title}*\n${message}` },
15
+ },
16
+ {
17
+ type: "context",
18
+ elements: [{ type: "mrkdwn", text: `Priority: ${priority} · <!date^${Math.floor(Date.now() / 1000)}^{time}|now>` }],
19
+ },
20
+ ],
21
+ }),
22
+ });
23
+ if (!res.ok)
24
+ throw new Error(`Slack ${res.status}: ${await res.text()}`);
25
+ }
@@ -0,0 +1,43 @@
1
+ const COLOR_MAP = { low: "Default", normal: "Accent", high: "Attention" };
2
+ export async function sendTeams(config, message, priority = "normal", title = "Claude Notify") {
3
+ if (!config.enabled)
4
+ return;
5
+ const res = await fetch(config.webhookUrl, {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({
9
+ type: "message",
10
+ attachments: [{
11
+ contentType: "application/vnd.microsoft.card.adaptive",
12
+ contentUrl: null,
13
+ content: {
14
+ $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
15
+ type: "AdaptiveCard",
16
+ version: "1.2",
17
+ body: [
18
+ {
19
+ type: "TextBlock",
20
+ size: "Medium",
21
+ weight: "Bolder",
22
+ text: title,
23
+ color: COLOR_MAP[priority] ?? "Default",
24
+ },
25
+ {
26
+ type: "TextBlock",
27
+ text: message,
28
+ wrap: true,
29
+ },
30
+ {
31
+ type: "TextBlock",
32
+ text: `Priority: ${priority} · ${new Date().toLocaleTimeString()}`,
33
+ isSubtle: true,
34
+ size: "Small",
35
+ },
36
+ ],
37
+ },
38
+ }],
39
+ }),
40
+ });
41
+ if (!res.ok)
42
+ throw new Error(`Teams ${res.status}: ${await res.text()}`);
43
+ }
package/dist/ui/server.js CHANGED
@@ -28,6 +28,10 @@ function defaultConfig() {
28
28
  whatsapp: { enabled: false, instanceId: "", apiToken: "", phone: "" },
29
29
  sms: { enabled: false, accountSid: "", authToken: "", from: "", to: "" },
30
30
  email: { enabled: false, to: "" },
31
+ ntfy: { enabled: false, topic: "", serverUrl: "https://ntfy.sh", token: "" },
32
+ discord: { enabled: false, webhookUrl: "", username: "Claude Notify" },
33
+ slack: { enabled: false, webhookUrl: "" },
34
+ teams: { enabled: false, webhookUrl: "" },
31
35
  dnd: {
32
36
  enabled: false, // manual toggle — when true, suppress all non-priority=high notifs
33
37
  schedule: {
@@ -101,11 +105,19 @@ function maskSecrets(config) {
101
105
  c.telegram.token = MASKED;
102
106
  if (c.whatsapp?.apiToken)
103
107
  c.whatsapp.apiToken = MASKED;
108
+ if (c.ntfy?.token)
109
+ c.ntfy.token = MASKED;
110
+ if (c.discord?.webhookUrl)
111
+ c.discord.webhookUrl = MASKED;
112
+ if (c.slack?.webhookUrl)
113
+ c.slack.webhookUrl = MASKED;
114
+ if (c.teams?.webhookUrl)
115
+ c.teams.webhookUrl = MASKED;
104
116
  return c;
105
117
  }
106
118
  function mergePreservingSecrets(existing, update) {
107
119
  const merged = { ...defaultConfig(), ...existing };
108
- for (const section of ["desktop", "telegram", "whatsapp", "sms", "email", "dnd", "idle"]) {
120
+ for (const section of ["desktop", "telegram", "whatsapp", "sms", "email", "ntfy", "discord", "slack", "teams", "dnd", "idle"]) {
109
121
  merged[section] = { ...(merged[section] || {}), ...(update[section] || {}) };
110
122
  }
111
123
  // Nested schedule inside dnd
@@ -125,6 +137,10 @@ function mergePreservingSecrets(existing, update) {
125
137
  guard(["sms", "authToken"]);
126
138
  guard(["telegram", "token"]);
127
139
  guard(["whatsapp", "apiToken"]);
140
+ guard(["ntfy", "token"]);
141
+ guard(["discord", "webhookUrl"]);
142
+ guard(["slack", "webhookUrl"]);
143
+ guard(["teams", "webhookUrl"]);
128
144
  return merged;
129
145
  }
130
146
  const app = express();
@@ -369,6 +385,80 @@ app.post("/api/test/email", async (_req, res) => {
369
385
  res.status(500).json({ error: String(err) });
370
386
  }
371
387
  });
388
+ app.post("/api/test/ntfy", async (_req, res) => {
389
+ const cfg = loadConfig();
390
+ const ntfy = cfg.ntfy ?? {};
391
+ if (!ntfy.topic) {
392
+ res.status(400).json({ error: "Topic is required." });
393
+ return;
394
+ }
395
+ try {
396
+ const base = (ntfy.serverUrl ?? "https://ntfy.sh").replace(/\/$/, "");
397
+ const headers = {
398
+ "Content-Type": "text/plain", "Title": "Claude Notify — test", "Priority": "3", "Tags": "white_check_mark",
399
+ };
400
+ if (ntfy.token)
401
+ headers["Authorization"] = `Bearer ${ntfy.token}`;
402
+ const r = await fetch(`${base}/${encodeURIComponent(ntfy.topic)}`, { method: "POST", headers, body: "Test from Claude Notify — ntfy is working!" });
403
+ if (!r.ok)
404
+ throw new Error(`ntfy ${r.status}: ${await r.text()}`);
405
+ res.json({ ok: true, message: `ntfy notification sent to topic '${ntfy.topic}'` });
406
+ }
407
+ catch (err) {
408
+ res.status(500).json({ error: String(err) });
409
+ }
410
+ });
411
+ app.post("/api/test/discord", async (_req, res) => {
412
+ const cfg = loadConfig();
413
+ const dc = cfg.discord ?? {};
414
+ if (!dc.webhookUrl) {
415
+ res.status(400).json({ error: "Webhook URL is required." });
416
+ return;
417
+ }
418
+ try {
419
+ const r = await fetch(dc.webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: dc.username ?? "Claude Notify", embeds: [{ title: "Claude Notify — test", description: "Test from Claude Notify — Discord is working!", color: 0x7c6dfa, timestamp: new Date().toISOString() }] }) });
420
+ if (!r.ok)
421
+ throw new Error(`Discord ${r.status}: ${await r.text()}`);
422
+ res.json({ ok: true, message: "Discord message sent!" });
423
+ }
424
+ catch (err) {
425
+ res.status(500).json({ error: String(err) });
426
+ }
427
+ });
428
+ app.post("/api/test/slack", async (_req, res) => {
429
+ const cfg = loadConfig();
430
+ const sl = cfg.slack ?? {};
431
+ if (!sl.webhookUrl) {
432
+ res.status(400).json({ error: "Webhook URL is required." });
433
+ return;
434
+ }
435
+ try {
436
+ const r = await fetch(sl.webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: "🔔 *Claude Notify — test*\nTest from Claude Notify — Slack is working!" }) });
437
+ if (!r.ok)
438
+ throw new Error(`Slack ${r.status}: ${await r.text()}`);
439
+ res.json({ ok: true, message: "Slack message sent!" });
440
+ }
441
+ catch (err) {
442
+ res.status(500).json({ error: String(err) });
443
+ }
444
+ });
445
+ app.post("/api/test/teams", async (_req, res) => {
446
+ const cfg = loadConfig();
447
+ const tm = cfg.teams ?? {};
448
+ if (!tm.webhookUrl) {
449
+ res.status(400).json({ error: "Webhook URL is required." });
450
+ return;
451
+ }
452
+ try {
453
+ const r = await fetch(tm.webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ type: "message", attachments: [{ contentType: "application/vnd.microsoft.card.adaptive", contentUrl: null, content: { $schema: "http://adaptivecards.io/schemas/adaptive-card.json", type: "AdaptiveCard", version: "1.2", body: [{ type: "TextBlock", size: "Medium", weight: "Bolder", text: "Claude Notify — test" }, { type: "TextBlock", text: "Test from Claude Notify — Teams is working!", wrap: true }] } }] }) });
454
+ if (!r.ok)
455
+ throw new Error(`Teams ${r.status}: ${await r.text()}`);
456
+ res.json({ ok: true, message: "Teams message sent!" });
457
+ }
458
+ catch (err) {
459
+ res.status(500).json({ error: String(err) });
460
+ }
461
+ });
372
462
  // ── Google ADC auto-setup ─────────────────────────────────────────────────────
373
463
  async function adcEmail() {
374
464
  if (!existsSync(ADC_PATH))
@@ -612,7 +702,14 @@ async function sendNotification(message, priority, client) {
612
702
  // the TTL), they clearly want a reply over that channel, so skip idle gating.
613
703
  const inTelegramConvo = Date.now() - lastTelegramInboundAt < TELEGRAM_CONVO_TTL_MS;
614
704
  let desktopOnlyMode = false;
615
- if (priority !== "high" && !inTelegramConvo && cfg.idle?.enabled !== false) {
705
+ // If the web UI is open and the user is actively watching it, skip remote channels.
706
+ if (priority !== "high" && isUiActivelyOpen()) {
707
+ if (cfg.idle?.alwaysDesktopWhenActive !== false && cfg.desktop?.enabled) {
708
+ desktopOnlyMode = true;
709
+ log("·", "ui", `UI visible — desktop-only`, client);
710
+ }
711
+ }
712
+ if (!desktopOnlyMode && priority !== "high" && !inTelegramConvo && cfg.idle?.enabled !== false) {
616
713
  const idleSecs = getOsIdleSeconds();
617
714
  const threshold = cfg.idle?.thresholdSeconds ?? 120;
618
715
  const userIsActive = idleSecs >= 0 && idleSecs < threshold;
@@ -711,6 +808,107 @@ async function sendNotification(message, priority, client) {
711
808
  to: email.to, subject: "Claude Notify", text: message });
712
809
  });
713
810
  }
811
+ // ntfy
812
+ if (!desktopOnlyMode) {
813
+ const ntfy = cfg.ntfy ?? {};
814
+ if (ntfy.enabled && ntfy.topic) {
815
+ await send("ntfy", async () => {
816
+ const base = (ntfy.serverUrl ?? "https://ntfy.sh").replace(/\/$/, "");
817
+ const priorityMap = { low: 2, normal: 3, high: 5 };
818
+ const headers = {
819
+ "Content-Type": "text/plain",
820
+ "Title": "Claude Notify",
821
+ "Priority": String(priorityMap[priority] ?? 3),
822
+ "Tags": priority === "high" ? "rotating_light" : "bell",
823
+ };
824
+ if (ntfy.token)
825
+ headers["Authorization"] = `Bearer ${ntfy.token}`;
826
+ const r = await fetch(`${base}/${encodeURIComponent(ntfy.topic)}`, {
827
+ method: "POST", headers, body: message,
828
+ });
829
+ if (!r.ok)
830
+ throw new Error(`ntfy ${r.status}: ${await r.text()}`);
831
+ });
832
+ }
833
+ }
834
+ // Discord
835
+ if (!desktopOnlyMode) {
836
+ const dc = cfg.discord ?? {};
837
+ if (dc.enabled && dc.webhookUrl) {
838
+ await send("discord", async () => {
839
+ const colorMap = { low: 0x6b7280, normal: 0x7c6dfa, high: 0xef4444 };
840
+ const r = await fetch(dc.webhookUrl, {
841
+ method: "POST",
842
+ headers: { "Content-Type": "application/json" },
843
+ body: JSON.stringify({
844
+ username: dc.username ?? "Claude Notify",
845
+ embeds: [{
846
+ title: "Claude Notify",
847
+ description: message,
848
+ color: colorMap[priority] ?? colorMap.normal,
849
+ timestamp: new Date().toISOString(),
850
+ }],
851
+ }),
852
+ });
853
+ if (!r.ok)
854
+ throw new Error(`Discord ${r.status}: ${await r.text()}`);
855
+ });
856
+ }
857
+ }
858
+ // Slack
859
+ if (!desktopOnlyMode) {
860
+ const sl = cfg.slack ?? {};
861
+ if (sl.enabled && sl.webhookUrl) {
862
+ await send("slack", async () => {
863
+ const emojiMap = { low: "ℹ️", normal: "🔔", high: "🚨" };
864
+ const emoji = emojiMap[priority] ?? emojiMap.normal;
865
+ const r = await fetch(sl.webhookUrl, {
866
+ method: "POST",
867
+ headers: { "Content-Type": "application/json" },
868
+ body: JSON.stringify({
869
+ text: `${emoji} *Claude Notify*`,
870
+ blocks: [
871
+ { type: "section", text: { type: "mrkdwn", text: `${emoji} *Claude Notify*\n${message}` } },
872
+ { type: "context", elements: [{ type: "mrkdwn", text: `Priority: ${priority}` }] },
873
+ ],
874
+ }),
875
+ });
876
+ if (!r.ok)
877
+ throw new Error(`Slack ${r.status}: ${await r.text()}`);
878
+ });
879
+ }
880
+ }
881
+ // Teams
882
+ if (!desktopOnlyMode) {
883
+ const tm = cfg.teams ?? {};
884
+ if (tm.enabled && tm.webhookUrl) {
885
+ await send("teams", async () => {
886
+ const colorMap = { low: "Default", normal: "Accent", high: "Attention" };
887
+ const r = await fetch(tm.webhookUrl, {
888
+ method: "POST",
889
+ headers: { "Content-Type": "application/json" },
890
+ body: JSON.stringify({
891
+ type: "message",
892
+ attachments: [{
893
+ contentType: "application/vnd.microsoft.card.adaptive",
894
+ contentUrl: null,
895
+ content: {
896
+ $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
897
+ type: "AdaptiveCard", version: "1.2",
898
+ body: [
899
+ { type: "TextBlock", size: "Medium", weight: "Bolder", text: "Claude Notify", color: colorMap[priority] ?? "Default" },
900
+ { type: "TextBlock", text: message, wrap: true },
901
+ { type: "TextBlock", text: `Priority: ${priority}`, isSubtle: true, size: "Small" },
902
+ ],
903
+ },
904
+ }],
905
+ }),
906
+ });
907
+ if (!r.ok)
908
+ throw new Error(`Teams ${r.status}: ${await r.text()}`);
909
+ });
910
+ }
911
+ }
714
912
  return [
715
913
  results.length ? `Sent via: ${results.join(", ")}` : null,
716
914
  errors.length ? `Errors: ${errors.join("; ")}` : null,
@@ -790,6 +988,28 @@ let lastUserMessageId;
790
988
  // goes quiet.
791
989
  let lastTelegramInboundAt = 0;
792
990
  const TELEGRAM_CONVO_TTL_MS = 5 * 60 * 1000;
991
+ // Page visibility: the web UI reports when it becomes visible/hidden so the
992
+ // server can skip external channels while the user is actively watching the UI.
993
+ let uiVisibleAt = 0; // last time UI reported visible
994
+ let uiHiddenAt = 0; // last time UI reported hidden (0 = never seen)
995
+ const UI_VISIBLE_TTL_MS = 30_000; // if no heartbeat for 30s, treat as unknown
996
+ app.post("/api/ui/visibility", (req, res) => {
997
+ const { visible } = req.body ?? {};
998
+ if (visible) {
999
+ uiVisibleAt = Date.now();
1000
+ }
1001
+ else {
1002
+ uiHiddenAt = Date.now();
1003
+ }
1004
+ res.json({ ok: true });
1005
+ });
1006
+ function isUiActivelyOpen() {
1007
+ if (uiVisibleAt === 0)
1008
+ return false; // never reported
1009
+ if (uiHiddenAt > uiVisibleAt)
1010
+ return false; // last report was hidden
1011
+ return Date.now() - uiVisibleAt < UI_VISIBLE_TTL_MS;
1012
+ }
793
1013
  // Session tagging: a session may declare a tag (e.g. "alphawave") when it
794
1014
  // connects to /mcp?tag=alphawave. Telegram messages starting with "@<tag>"
795
1015
  // are routed only to sessions with that exact tag (tag prefix stripped).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-notify-mcp",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "An MCP server that lets AI agents (Claude, Cursor, etc.) reach you on any channel — desktop, Telegram, SMS, email — with two-way ask/reply, real-time inbox push, Do Not Disturb, idle gating, multi-session routing, and a one-page web UI for setup. Zero config code; configure once, agents call notify/ask.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
package/ui/public/app.js CHANGED
@@ -71,6 +71,29 @@ function populateForm() {
71
71
  $("sms-from").value = sms.from ?? "";
72
72
  $("sms-to").value = sms.to ?? "";
73
73
 
74
+ // ntfy
75
+ const ntfy = config.ntfy ?? {};
76
+ $("ntfy-enabled").checked = !!ntfy.enabled;
77
+ $("ntfy-topic").value = ntfy.topic ?? "";
78
+ $("ntfy-server").value = ntfy.serverUrl ?? "https://ntfy.sh";
79
+ $("ntfy-token").value = ntfy.token ?? "";
80
+
81
+ // Discord
82
+ const dc = config.discord ?? {};
83
+ $("discord-enabled").checked = !!dc.enabled;
84
+ $("discord-webhook").value = dc.webhookUrl ?? "";
85
+ $("discord-username").value = dc.username ?? "";
86
+
87
+ // Slack
88
+ const sl = config.slack ?? {};
89
+ $("slack-enabled").checked = !!sl.enabled;
90
+ $("slack-webhook").value = sl.webhookUrl ?? "";
91
+
92
+ // Teams
93
+ const tm = config.teams ?? {};
94
+ $("teams-enabled").checked = !!tm.enabled;
95
+ $("teams-webhook").value = tm.webhookUrl ?? "";
96
+
74
97
  // DND
75
98
  const dnd = config.dnd ?? {};
76
99
  $("dnd-enabled").checked = !!dnd.enabled;
@@ -128,6 +151,22 @@ function updateBadges() {
128
151
  sms.enabled && smsReady ? "ok" : smsReady ? "warn" : sms.accountSid ? "warn" : "idle",
129
152
  sms.enabled && smsReady ? "Configured" : smsReady ? "Disabled" : sms.accountSid ? "Incomplete" : "Not configured");
130
153
 
154
+ const ntfyC = config.ntfy ?? {};
155
+ setBadge("ntfy", ntfyC.enabled && ntfyC.topic ? "ok" : ntfyC.topic ? "warn" : "idle",
156
+ ntfyC.enabled && ntfyC.topic ? "Configured" : ntfyC.topic ? "Disabled" : "Not configured");
157
+
158
+ const dcC = config.discord ?? {};
159
+ setBadge("discord", dcC.enabled && dcC.webhookUrl ? "ok" : dcC.webhookUrl ? "warn" : "idle",
160
+ dcC.enabled && dcC.webhookUrl ? "Configured" : dcC.webhookUrl ? "Disabled" : "Not configured");
161
+
162
+ const slC = config.slack ?? {};
163
+ setBadge("slack", slC.enabled && slC.webhookUrl ? "ok" : slC.webhookUrl ? "warn" : "idle",
164
+ slC.enabled && slC.webhookUrl ? "Configured" : slC.webhookUrl ? "Disabled" : "Not configured");
165
+
166
+ const tmC = config.teams ?? {};
167
+ setBadge("teams", tmC.enabled && tmC.webhookUrl ? "ok" : tmC.webhookUrl ? "warn" : "idle",
168
+ tmC.enabled && tmC.webhookUrl ? "Configured" : tmC.webhookUrl ? "Disabled" : "Not configured");
169
+
131
170
  // DND badge: "Active" (red), "Scheduled" (warn), or "Off" (idle)
132
171
  const dnd = config.dnd ?? {};
133
172
  const sched = dnd.schedule ?? {};
@@ -219,6 +258,18 @@ async function toggleEmailEnabled() {
219
258
  async function toggleSmsEnabled() {
220
259
  await patch({ sms: { enabled: $("sms-enabled").checked } });
221
260
  }
261
+ async function toggleNtfyEnabled() {
262
+ await patch({ ntfy: { enabled: $("ntfy-enabled").checked } });
263
+ }
264
+ async function toggleDiscordEnabled() {
265
+ await patch({ discord: { enabled: $("discord-enabled").checked } });
266
+ }
267
+ async function toggleSlackEnabled() {
268
+ await patch({ slack: { enabled: $("slack-enabled").checked } });
269
+ }
270
+ async function toggleTeamsEnabled() {
271
+ await patch({ teams: { enabled: $("teams-enabled").checked } });
272
+ }
222
273
 
223
274
  async function saveTelegram() {
224
275
  await patch({
@@ -290,6 +341,23 @@ async function saveSms() {
290
341
  clearDirty("sms");
291
342
  }
292
343
 
344
+ async function saveNtfy() {
345
+ await patch({ ntfy: { enabled: $("ntfy-enabled").checked, topic: $("ntfy-topic").value.trim(), serverUrl: $("ntfy-server").value.trim() || "https://ntfy.sh", token: $("ntfy-token").value.trim() } });
346
+ clearDirty("ntfy");
347
+ }
348
+ async function saveDiscord() {
349
+ await patch({ discord: { enabled: $("discord-enabled").checked, webhookUrl: $("discord-webhook").value.trim(), username: $("discord-username").value.trim() || "Claude Notify" } });
350
+ clearDirty("discord");
351
+ }
352
+ async function saveSlack() {
353
+ await patch({ slack: { enabled: $("slack-enabled").checked, webhookUrl: $("slack-webhook").value.trim() } });
354
+ clearDirty("slack");
355
+ }
356
+ async function saveTeams() {
357
+ await patch({ teams: { enabled: $("teams-enabled").checked, webhookUrl: $("teams-webhook").value.trim() } });
358
+ clearDirty("teams");
359
+ }
360
+
293
361
  async function patch(update) {
294
362
  try {
295
363
  const res = await fetch("/api/config", {
@@ -535,6 +603,38 @@ function toast(msg, type = "ok") {
535
603
 
536
604
  function $(id) { return document.getElementById(id); }
537
605
 
606
+ // ── Page visibility reporting ─────────────────────────────────────────────
607
+ // Tell the server when this tab is focused so it can skip external channels
608
+ // while the user is actively watching the UI.
609
+
610
+ function reportVisibility(visible) {
611
+ fetch("/api/ui/visibility", {
612
+ method: "POST",
613
+ headers: { "Content-Type": "application/json" },
614
+ body: JSON.stringify({ visible }),
615
+ }).catch(() => {});
616
+ }
617
+
618
+ let visibilityHeartbeat;
619
+ function startVisibilityHeartbeat() {
620
+ clearInterval(visibilityHeartbeat);
621
+ visibilityHeartbeat = setInterval(() => {
622
+ if (!document.hidden) reportVisibility(true);
623
+ }, 15000);
624
+ }
625
+
626
+ document.addEventListener("visibilitychange", () => {
627
+ reportVisibility(!document.hidden);
628
+ if (!document.hidden) startVisibilityHeartbeat();
629
+ else clearInterval(visibilityHeartbeat);
630
+ });
631
+ window.addEventListener("focus", () => { reportVisibility(true); startVisibilityHeartbeat(); });
632
+ window.addEventListener("blur", () => reportVisibility(false));
633
+
634
+ // Report on load and start heartbeat
635
+ reportVisibility(!document.hidden);
636
+ if (!document.hidden) startVisibilityHeartbeat();
637
+
538
638
  function copyText(el) {
539
639
  const text = el.textContent.replace(" 📋", "").trim();
540
640
  navigator.clipboard.writeText(text).then(() => {
@@ -199,6 +199,139 @@
199
199
  </div>
200
200
  </div>
201
201
 
202
+ <!-- ── ntfy ─────────────────────────────────────────────────── -->
203
+ <div class="card" id="card-ntfy">
204
+ <div class="card-hd">
205
+ <div class="ch-meta">
206
+ <div class="channel-icon ntfy-icon">
207
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
208
+ </div>
209
+ <span class="ch-name">ntfy</span><span class="tag">Push</span>
210
+ </div>
211
+ <span class="badge badge-idle" id="badge-ntfy">Not configured</span>
212
+ </div>
213
+ <div class="card-body">
214
+ <div class="actions">
215
+ <label class="toggle-wrap">
216
+ <input type="checkbox" id="ntfy-enabled" onchange="toggleNtfyEnabled()">
217
+ <span class="toggle"></span>
218
+ </label>
219
+ <span class="toggle-lbl">Enable</span>
220
+ <button class="btn btn-sm btn-primary" id="save-ntfy-btn" onclick="saveNtfy()">Save</button>
221
+ <button class="btn btn-sm btn-ghost" onclick="testChannel('ntfy')">Test</button>
222
+ </div>
223
+ <details class="guide">
224
+ <summary>Set up ntfy (1 min, free, no account needed)</summary>
225
+ <ol>
226
+ <li>Install the <a href="https://ntfy.sh" target="_blank">ntfy app</a> on your phone</li>
227
+ <li>Pick any topic name (e.g. <code>my-claude-alerts-abc123</code>) — keep it secret, it's your auth</li>
228
+ <li>Subscribe to that topic in the app</li>
229
+ <li>Paste the topic below and save</li>
230
+ </ol>
231
+ </details>
232
+ <div class="fg"><label>Topic</label><input type="text" id="ntfy-topic" placeholder="my-claude-alerts-abc123" oninput="markDirty('ntfy')"></div>
233
+ <div class="fg"><label>Server URL</label><input type="text" id="ntfy-server" placeholder="https://ntfy.sh" oninput="markDirty('ntfy')"><span class="hint">Leave default for ntfy.sh, or your self-hosted URL</span></div>
234
+ <div class="fg"><label>Token (optional)</label><input type="password" id="ntfy-token" placeholder="tk_…" oninput="markDirty('ntfy')"><span class="hint">Only needed for private self-hosted servers</span></div>
235
+ </div>
236
+ </div>
237
+
238
+ <!-- ── Discord ───────────────────────────────────────────────── -->
239
+ <div class="card" id="card-discord">
240
+ <div class="card-hd">
241
+ <div class="ch-meta">
242
+ <div class="channel-icon discord-icon">
243
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="12" r="1"/><circle cx="15" cy="12" r="1"/><path d="M7.5 7.5c1-.5 2.5-.5 4.5-.5s3.5 0 4.5.5M7.5 16.5c1 .5 2.5.5 4.5.5s3.5 0 4.5-.5"/><path d="M3 3l4.5 1.5M21 3l-4.5 1.5M3 21l4.5-1.5M21 21l-4.5-1.5"/><path d="M3 3c0 9 0 12 9 15 9-3 9-6 9-15"/></svg>
244
+ </div>
245
+ <span class="ch-name">Discord</span><span class="tag">Webhook</span>
246
+ </div>
247
+ <span class="badge badge-idle" id="badge-discord">Not configured</span>
248
+ </div>
249
+ <div class="card-body">
250
+ <div class="actions">
251
+ <label class="toggle-wrap">
252
+ <input type="checkbox" id="discord-enabled" onchange="toggleDiscordEnabled()">
253
+ <span class="toggle"></span>
254
+ </label>
255
+ <span class="toggle-lbl">Enable</span>
256
+ <button class="btn btn-sm btn-primary" id="save-discord-btn" onclick="saveDiscord()">Save</button>
257
+ <button class="btn btn-sm btn-ghost" onclick="testChannel('discord')">Test</button>
258
+ </div>
259
+ <details class="guide">
260
+ <summary>Create a Discord webhook (1 min)</summary>
261
+ <ol>
262
+ <li>Open your Discord server → pick a channel → Edit Channel</li>
263
+ <li>Integrations → Webhooks → New Webhook → Copy URL</li>
264
+ </ol>
265
+ </details>
266
+ <div class="fg"><label>Webhook URL</label><input type="password" id="discord-webhook" placeholder="https://discord.com/api/webhooks/…" oninput="markDirty('discord')"></div>
267
+ <div class="fg"><label>Bot name (optional)</label><input type="text" id="discord-username" placeholder="Claude Notify" oninput="markDirty('discord')"></div>
268
+ </div>
269
+ </div>
270
+
271
+ <!-- ── Slack ─────────────────────────────────────────────────── -->
272
+ <div class="card" id="card-slack">
273
+ <div class="card-hd">
274
+ <div class="ch-meta">
275
+ <div class="channel-icon slack-icon">
276
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 10c-.83 0-1.5-.67-1.5-1.5v-5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5v5c0 .83-.67 1.5-1.5 1.5z"/><path d="M20.5 10H19V8.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/><path d="M9.5 14c.83 0 1.5.67 1.5 1.5v5c0 .83-.67 1.5-1.5 1.5S8 21.33 8 20.5v-5c0-.83.67-1.5 1.5-1.5z"/><path d="M3.5 14H5v1.5c0 .83-.67 1.5-1.5 1.5S2 16.33 2 15.5 2.67 14 3.5 14z"/><path d="M14 14.5c0-.83.67-1.5 1.5-1.5h5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-5c-.83 0-1.5-.67-1.5-1.5z"/><path d="M15.5 19H14v1.5c0 .83.67 1.5 1.5 1.5s1.5-.67 1.5-1.5-.67-1.5-1.5-1.5z"/><path d="M10 9.5C10 8.67 9.33 8 8.5 8h-5C2.67 8 2 8.67 2 9.5S2.67 11 3.5 11h5c.83 0 1.5-.67 1.5-1.5z"/><path d="M8.5 5H10V3.5C10 2.67 9.33 2 8.5 2S7 2.67 7 3.5 7.67 5 8.5 5z"/></svg>
277
+ </div>
278
+ <span class="ch-name">Slack</span><span class="tag">Webhook</span>
279
+ </div>
280
+ <span class="badge badge-idle" id="badge-slack">Not configured</span>
281
+ </div>
282
+ <div class="card-body">
283
+ <div class="actions">
284
+ <label class="toggle-wrap">
285
+ <input type="checkbox" id="slack-enabled" onchange="toggleSlackEnabled()">
286
+ <span class="toggle"></span>
287
+ </label>
288
+ <span class="toggle-lbl">Enable</span>
289
+ <button class="btn btn-sm btn-primary" id="save-slack-btn" onclick="saveSlack()">Save</button>
290
+ <button class="btn btn-sm btn-ghost" onclick="testChannel('slack')">Test</button>
291
+ </div>
292
+ <details class="guide">
293
+ <summary>Create a Slack webhook (2 min)</summary>
294
+ <ol>
295
+ <li>Go to <a href="https://api.slack.com/apps" target="_blank">api.slack.com/apps</a> → Create New App → From scratch</li>
296
+ <li>Incoming Webhooks → On → Add New Webhook to Workspace → pick channel → Copy URL</li>
297
+ </ol>
298
+ </details>
299
+ <div class="fg"><label>Webhook URL</label><input type="password" id="slack-webhook" placeholder="https://hooks.slack.com/services/…" oninput="markDirty('slack')"></div>
300
+ </div>
301
+ </div>
302
+
303
+ <!-- ── Teams ─────────────────────────────────────────────────── -->
304
+ <div class="card" id="card-teams">
305
+ <div class="card-hd">
306
+ <div class="ch-meta">
307
+ <div class="channel-icon teams-icon">
308
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
309
+ </div>
310
+ <span class="ch-name">Teams</span><span class="tag">Webhook</span>
311
+ </div>
312
+ <span class="badge badge-idle" id="badge-teams">Not configured</span>
313
+ </div>
314
+ <div class="card-body">
315
+ <div class="actions">
316
+ <label class="toggle-wrap">
317
+ <input type="checkbox" id="teams-enabled" onchange="toggleTeamsEnabled()">
318
+ <span class="toggle"></span>
319
+ </label>
320
+ <span class="toggle-lbl">Enable</span>
321
+ <button class="btn btn-sm btn-primary" id="save-teams-btn" onclick="saveTeams()">Save</button>
322
+ <button class="btn btn-sm btn-ghost" onclick="testChannel('teams')">Test</button>
323
+ </div>
324
+ <details class="guide">
325
+ <summary>Create a Teams webhook (2 min)</summary>
326
+ <ol>
327
+ <li>In Teams, go to the channel → ••• → Workflows → "Post to a channel when a webhook request is received"</li>
328
+ <li>Follow the wizard → copy the webhook URL at the end</li>
329
+ </ol>
330
+ </details>
331
+ <div class="fg"><label>Webhook URL</label><input type="password" id="teams-webhook" placeholder="https://…webhook.office.com/…" oninput="markDirty('teams')"></div>
332
+ </div>
333
+ </div>
334
+
202
335
  </div>
203
336
  </section>
204
337
 
@@ -296,6 +296,10 @@ main {
296
296
  .telegram-icon { background: #0d1e2e; color: #38bdf8; }
297
297
  .whatsapp-icon { background: #0d2e1a; color: #4ade80; }
298
298
  .sms-icon { background: #1e0d2e; color: #c084fc; }
299
+ .ntfy-icon { background: #1a2e0d; color: #86efac; }
300
+ .discord-icon { background: #0d0d2e; color: #a5b4fc; }
301
+ .slack-icon { background: #2e2a0d; color: #fbbf24; }
302
+ .teams-icon { background: #0d1e2e; color: #7dd3fc; }
299
303
 
300
304
  /* ── Tags & badges ───────────────────────────────────────────────────────── */
301
305