fix(webhook): send milestone notifications with SUPPRESS_NOTIFICATIONS flag
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m7s
CI / Lint, Build & Test (pull_request) Successful in 1m9s

Adds flags: 4096 (MessageFlags.SUPPRESS_NOTIFICATIONS) to the Discord
webhook payload so milestone announcements appear in the channel without
triggering desktop or mobile push notifications. Closes #41.
This commit is contained in:
2026-03-09 20:00:06 -07:00
committed by Naomi Carrigan
parent a36c8e72a5
commit 8fa36f2757
2 changed files with 12 additions and 2 deletions
+10 -1
View File
@@ -9,6 +9,12 @@ import { logger } from "./logger.js";
const discordApi = "https://discord.com/api/v10"; const discordApi = "https://discord.com/api/v10";
/**
* Discord MessageFlags.SUPPRESS_NOTIFICATIONS — messages are delivered without
* triggering desktop or mobile push notifications.
*/
const suppressNotifications = 4096;
/** /**
* Grants the apotheosis Discord role to the given player if configured. * Grants the apotheosis Discord role to the given player if configured.
* Fails silently so role grant errors do not affect the game action. * Fails silently so role grant errors do not affect the game action.
@@ -85,7 +91,10 @@ const postMilestoneWebhook = async(
try { try {
await fetch(webhookUrl, { await fetch(webhookUrl, {
body: JSON.stringify({ content }), body: JSON.stringify({
content: content,
flags: suppressNotifications,
}),
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
method: "POST", method: "POST",
}); });
+2 -1
View File
@@ -97,9 +97,10 @@ describe("webhook service", () => {
await postMilestoneWebhook("user123", "prestige", counts); await postMilestoneWebhook("user123", "prestige", counts);
const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit]; const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit];
expect(url).toBe("https://discord.com/webhook/abc"); expect(url).toBe("https://discord.com/webhook/abc");
const body = JSON.parse(options.body as string) as { content: string }; const body = JSON.parse(options.body as string) as { content: string; flags: number };
expect(body.content).toContain("<@user123>"); expect(body.content).toContain("<@user123>");
expect(body.content).toContain("prestiged"); expect(body.content).toContain("prestiged");
expect(body.flags).toBe(4096);
}); });
it("posts transcendence message correctly", async () => { it("posts transcendence message correctly", async () => {