From 37f39b93c245325097cc7f24ec6a729d19c741da Mon Sep 17 00:00:00 2001 From: Andrew Dunn Date: Sat, 24 Oct 2026 20:43:01 -0400 Subject: [PATCH 1/7] feat(api): add optional titleEmoji alert field Alert notification titles always carry a state emoji prefix. Add an optional titleEmoji field on alerts; setting it to false drops the prefix, and unset keeps today's behavior. Exposed through the internal and external alert APIs and documented in the OpenAPI spec. --- .changeset/alert-title-emoji-toggle.md | 7 ++ packages/api/openapi.json | 6 ++ packages/api/src/controllers/alerts.ts | 1 + .../api/src/mcp/tools/alerts/saveAlert.ts | 2 +- packages/api/src/models/alert.ts | 7 ++ .../routers/api/__tests__/alerts.int.test.ts | 51 +++++++++++++++ packages/api/src/routers/api/alerts.ts | 1 + .../external-api/__tests__/alerts.int.test.ts | 40 ++++++++++++ .../api/src/routers/external-api/v2/alerts.ts | 5 ++ .../__tests__/renderAlertTemplate.int.test.ts | 65 +++++++++++++++++++ .../api/src/tasks/checkAlerts/template.ts | 4 +- .../src/utils/__tests__/externalApi.test.ts | 26 ++++++++ packages/api/src/utils/externalApi.ts | 2 + packages/api/src/utils/zod.ts | 1 + packages/app/src/DBSearchPageAlertModal.tsx | 2 + .../src/components/alerts/EditAlertModal.tsx | 3 + .../alerts/EditInlineAlertModal.tsx | 1 + .../alerts/__tests__/EditAlertModal.test.tsx | 10 +++ packages/common-utils/src/types.ts | 2 + 19 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 .changeset/alert-title-emoji-toggle.md diff --git a/.changeset/alert-title-emoji-toggle.md b/.changeset/alert-title-emoji-toggle.md new file mode 100644 index 0000000000..a9ac1100e3 --- /dev/null +++ b/.changeset/alert-title-emoji-toggle.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/api': minor +'@hyperdx/app': minor +'@hyperdx/common-utils': minor +--- + +feat: add optional `titleEmoji` alert field; `false` removes the emoji prefix from notification titles diff --git a/packages/api/openapi.json b/packages/api/openapi.json index f6ea5912f6..7c88712e32 100644 --- a/packages/api/openapi.json +++ b/packages/api/openapi.json @@ -413,6 +413,12 @@ "maxLength": 4096, "example": "Threshold raised from 50 to 100 on 2026-01-15. See [runbook](https://wiki.example.com/runbook)." }, + "titleEmoji": { + "type": "boolean", + "nullable": true, + "description": "Set to false to omit the state emoji prefix from notification titles. Unset, null or true keeps the default prefix.", + "example": false + }, "numConsecutiveWindows": { "type": "integer", "minimum": 1, diff --git a/packages/api/src/controllers/alerts.ts b/packages/api/src/controllers/alerts.ts index 0e8762e48c..ea7a532446 100644 --- a/packages/api/src/controllers/alerts.ts +++ b/packages/api/src/controllers/alerts.ts @@ -299,6 +299,7 @@ export const makeAlert = ( name: alert.name ?? null, message: alert.message ?? null, note: alert.note ?? null, + titleEmoji: alert.titleEmoji ?? null, displayName, tags, diff --git a/packages/api/src/mcp/tools/alerts/saveAlert.ts b/packages/api/src/mcp/tools/alerts/saveAlert.ts index 9c5962026d..2b3d5df0a5 100644 --- a/packages/api/src/mcp/tools/alerts/saveAlert.ts +++ b/packages/api/src/mcp/tools/alerts/saveAlert.ts @@ -56,7 +56,7 @@ export function registerSaveAlert({ 'alert configuration rather than merging it: channels you do not resend are ' + 'removed, omitted name and message are cleared, omitted displayName and tags ' + 'are re-derived from the source, and settings this tool cannot set ' + - '(note, consecutive-window count) are cleared. Omitting both ' + + '(note, consecutive-window count, title emoji) are cleared. Omitting both ' + 'scheduleStartAt and scheduleOffsetMinutes keeps the stored schedule; ' + 'clearing scheduleStartAt without an offset resets the offset to 0. Read the alert with ' + 'clickstack_get_alert first and resend every field you want to keep.', diff --git a/packages/api/src/models/alert.ts b/packages/api/src/models/alert.ts index 3e62d19eab..443192d0f1 100644 --- a/packages/api/src/models/alert.ts +++ b/packages/api/src/models/alert.ts @@ -99,6 +99,9 @@ export interface IAlert { // Freeform note (supports markdown) note?: string | null; + // false drops the state emoji prefix from the notification title + titleEmoji?: boolean | null; + // User-facing name shown in the alerts list and notification titles (when not overridden by name template). // Unset means "derive from the referenced saved search / dashboard tile". displayName?: string | null; @@ -215,6 +218,10 @@ const AlertSchema = new Schema( type: String, required: false, }, + titleEmoji: { + type: Boolean, + required: false, + }, displayName: { type: String, required: false, diff --git a/packages/api/src/routers/api/__tests__/alerts.int.test.ts b/packages/api/src/routers/api/__tests__/alerts.int.test.ts index 8d81390593..9c4b980558 100644 --- a/packages/api/src/routers/api/__tests__/alerts.int.test.ts +++ b/packages/api/src/routers/api/__tests__/alerts.int.test.ts @@ -424,6 +424,57 @@ describe('alerts router', () => { expect(afterClear.body.data.note).toBeNull(); }); + it('round-trips titleEmoji through create, update, and clear', async () => { + const dashboard = await agent + .post('/dashboards') + .send(MOCK_DASHBOARD) + .expect(200); + + const alert = await agent + .post('/alerts') + .send({ + ...makeAlertInput({ + dashboardId: dashboard.body.id, + tileId: dashboard.body.tiles[0].id, + webhookId: webhook._id.toString(), + }), + titleEmoji: false, + }) + .expect(200); + expect(alert.body.data.titleEmoji).toBe(false); + + const single = await agent + .get(`/alerts/${alert.body.data._id}`) + .expect(200); + expect(single.body.data.titleEmoji).toBe(false); + + await agent + .put(`/alerts/${alert.body.data._id}`) + .send({ + ...alert.body.data, + dashboardId: dashboard.body.id, + titleEmoji: true, + }) + .expect(200); + const afterUpdate = await agent + .get(`/alerts/${alert.body.data._id}`) + .expect(200); + expect(afterUpdate.body.data.titleEmoji).toBe(true); + + await agent + .put(`/alerts/${alert.body.data._id}`) + .send({ + ...alert.body.data, + dashboardId: dashboard.body.id, + titleEmoji: null, + }) + .expect(200); + const afterClear = await agent + .get(`/alerts/${alert.body.data._id}`) + .expect(200); + expect(afterClear.body.data.titleEmoji).toBeNull(); + }); + it('round-trips displayName and tags through create, update, and revert', async () => { const dashboard = await agent .post('/dashboards') diff --git a/packages/api/src/routers/api/alerts.ts b/packages/api/src/routers/api/alerts.ts index 3085e3d764..1e673392b8 100644 --- a/packages/api/src/routers/api/alerts.ts +++ b/packages/api/src/routers/api/alerts.ts @@ -113,6 +113,7 @@ const formatAlertResponse = ( 'name', 'message', 'note', + 'titleEmoji', 'createdAt', 'updatedAt', 'executionErrors', diff --git a/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts b/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts index 0d79f5ef43..1a6d1b0109 100644 --- a/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts +++ b/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts @@ -480,6 +480,7 @@ describe('External API Alerts', () => { tags: [], message: 'This is a test alert for format verification', note: null, + titleEmoji: null, numConsecutiveWindows: null, threshold: 123, interval: '15m', @@ -2725,6 +2726,45 @@ describe('External API Alerts', () => { expect(getResponse.body.data.numConsecutiveWindows).toBeNull(); }); }); + + describe('Notification title emoji (titleEmoji)', () => { + it('should default titleEmoji to null when not provided', async () => { + const { alert } = await createTestAlert(); + + expect(alert.titleEmoji).toBeNull(); + }); + + it('should create an alert with titleEmoji false and return it on GET', async () => { + const { alert } = await createTestAlert({ titleEmoji: false }); + + expect(alert.titleEmoji).toBe(false); + + const getResponse = await authRequest( + 'get', + `${ALERTS_BASE_URL}/${alert.id}`, + ).expect(200); + + expect(getResponse.body.data.titleEmoji).toBe(false); + }); + + it('should update an alert to set titleEmoji', async () => { + const { alert, alertInput } = await createTestAlert({ + titleEmoji: false, + }); + + await authRequest('put', `${ALERTS_BASE_URL}/${alert.id}`) + .send({ ...alertInput, titleEmoji: true }) + .expect(200); + + const getResponse = await authRequest( + 'get', + `${ALERTS_BASE_URL}/${alert.id}`, + ).expect(200); + + expect(getResponse.body.data.titleEmoji).toBe(true); + }); + }); + describe('Multiple notification channels', () => { const makeWebhookNamed = async (name: string) => await Webhook.findOneAndUpdate( diff --git a/packages/api/src/routers/external-api/v2/alerts.ts b/packages/api/src/routers/external-api/v2/alerts.ts index 7a23df9d1a..25aa82882c 100644 --- a/packages/api/src/routers/external-api/v2/alerts.ts +++ b/packages/api/src/routers/external-api/v2/alerts.ts @@ -322,6 +322,11 @@ function toInternalAlertInput(body: ExternalAlertInput): InternalAlertInput { * minLength: 1 * maxLength: 4096 * example: "Threshold raised from 50 to 100 on 2026-01-15. See [runbook](https://wiki.example.com/runbook)." + * titleEmoji: + * type: boolean + * nullable: true + * description: Set to false to omit the state emoji prefix from notification titles. Unset, null or true keeps the default prefix. + * example: false * numConsecutiveWindows: * type: integer * minimum: 1 diff --git a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts index c3e09091bc..cc05e994a0 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts @@ -896,6 +896,71 @@ describe('buildAlertMessageTemplateTitle', () => { }); }); + describe('alert.titleEmoji', () => { + const withTitleEmoji = (titleEmoji: boolean) => { + const view = makeSearchView(); + return { + ...view, + alert: { ...view.alert, name: 'Custom title', titleEmoji }, + }; + }; + + it('drops the prefix of a firing alert when false', () => { + const result = buildAlertMessageTemplateTitle({ + view: withTitleEmoji(false), + state: AlertState.ALERT, + }); + + expect(result).toBe('Custom title'); + }); + + it('drops the prefix of a resolved alert when false', () => { + const result = buildAlertMessageTemplateTitle({ + view: withTitleEmoji(false), + state: AlertState.OK, + }); + + expect(result).toBe('Custom title'); + }); + + it('keeps the prefix of a resolved alert when true', () => { + const result = buildAlertMessageTemplateTitle({ + view: withTitleEmoji(true), + state: AlertState.OK, + }); + + expect(result).toBe('✅ Custom title'); + }); + + it('keeps the prefix of a resolved alert when unset', () => { + const view = makeSearchView(); + const result = buildAlertMessageTemplateTitle({ + view: { ...view, alert: { ...view.alert, name: 'Custom title' } }, + state: AlertState.OK, + }); + + expect(result).toBe('✅ Custom title'); + }); + + it('keeps the prefix when true', () => { + const result = buildAlertMessageTemplateTitle({ + view: withTitleEmoji(true), + state: AlertState.ALERT, + }); + + expect(result).toBe('🚨 Custom title'); + }); + + it('keeps the prefix when unset', () => { + const result = buildAlertMessageTemplateTitle({ + view: makeSearchView(), + state: AlertState.ALERT, + }); + + expect(result).toMatch(/^🚨 /); + }); + }); + describe('stored displayName', () => { it('names a saved-search alert', () => { const view = makeSearchView(); diff --git a/packages/api/src/tasks/checkAlerts/template.ts b/packages/api/src/tasks/checkAlerts/template.ts index 5cb3b148b3..e7ca6b79cc 100644 --- a/packages/api/src/tasks/checkAlerts/template.ts +++ b/packages/api/src/tasks/checkAlerts/template.ts @@ -367,8 +367,8 @@ export const buildAlertMessageTemplateTitle = ({ dashboard, }); - // Add emoji prefix based on alert state - const emoji = isAlertResolved(state) ? '✅ ' : '🚨 '; + const emoji = + alert.titleEmoji === false ? '' : isAlertResolved(state) ? '✅ ' : '🚨 '; if (alert.source === AlertSource.SAVED_SEARCH) { if (savedSearch == null) { diff --git a/packages/api/src/utils/__tests__/externalApi.test.ts b/packages/api/src/utils/__tests__/externalApi.test.ts index abbb40da81..197cfca525 100644 --- a/packages/api/src/utils/__tests__/externalApi.test.ts +++ b/packages/api/src/utils/__tests__/externalApi.test.ts @@ -181,6 +181,32 @@ describe('utils/externalApi', () => { }); }); + describe('titleEmoji handling', () => { + it('returns titleEmoji as null when the value is null', () => { + const alert = createAlertDocument({ titleEmoji: null }); + + const translated = translateAlertDocumentToExternalAlert(alert); + + expect(translated.titleEmoji).toBeNull(); + }); + + it('returns titleEmoji as null when the value is undefined', () => { + const alert = createAlertDocument({ titleEmoji: undefined }); + + const translated = translateAlertDocumentToExternalAlert(alert); + + expect(translated.titleEmoji).toBeNull(); + }); + + it('returns titleEmoji when the value is false', () => { + const alert = createAlertDocument({ titleEmoji: false }); + + const translated = translateAlertDocumentToExternalAlert(alert); + + expect(translated.titleEmoji).toBe(false); + }); + }); + describe('numConsecutiveWindows handling', () => { it('returns numConsecutiveWindows as null when the value is null', () => { const alert = createAlertDocument({ numConsecutiveWindows: null }); diff --git a/packages/api/src/utils/externalApi.ts b/packages/api/src/utils/externalApi.ts index 187abd7a24..282a0282d6 100644 --- a/packages/api/src/utils/externalApi.ts +++ b/packages/api/src/utils/externalApi.ts @@ -331,6 +331,7 @@ export type ExternalAlert = { tags: string[]; message?: string | null; note?: string | null; + titleEmoji?: boolean | null; threshold: number; thresholdMax?: number; interval: AlertInterval; @@ -502,6 +503,7 @@ export function translateAlertDocumentToExternalAlert( ...resolveAlertDisplayFields(alertObj, { dashboard, savedSearch }), message: alertObj.message, note: alertObj.note ?? null, + titleEmoji: alertObj.titleEmoji ?? null, threshold: alertObj.threshold, thresholdMax: alertObj.thresholdMax, interval: alertObj.interval, diff --git a/packages/api/src/utils/zod.ts b/packages/api/src/utils/zod.ts index 8ec394afdf..8821bb80d5 100644 --- a/packages/api/src/utils/zod.ts +++ b/packages/api/src/utils/zod.ts @@ -1220,6 +1220,7 @@ const alertBaseSchema = z.object({ name: z.string().min(1).max(512).nullish(), message: z.string().min(1).max(4096).nullish(), note: alertNoteSchema, + titleEmoji: z.boolean().nullish(), displayName: alertDisplayNameSchema, tags: alertTagsSchema, numConsecutiveWindows: z.number().int().min(1).nullish(), diff --git a/packages/app/src/DBSearchPageAlertModal.tsx b/packages/app/src/DBSearchPageAlertModal.tsx index ab748a0312..3b93caa1f3 100644 --- a/packages/app/src/DBSearchPageAlertModal.tsx +++ b/packages/app/src/DBSearchPageAlertModal.tsx @@ -90,6 +90,8 @@ const SavedSearchAlertFormSchema = z // nullish() (not optional()): persisted alerts store this as null, which // optional() would reject. numConsecutiveWindows: z.number().int().min(1).nullish(), + // No control in the UI; declared so a save echoes the stored value. + titleEmoji: z.boolean().nullish(), }) .passthrough() .superRefine(validateAlertScheduleOffsetMinutes) diff --git a/packages/app/src/components/alerts/EditAlertModal.tsx b/packages/app/src/components/alerts/EditAlertModal.tsx index 2d670aa2cd..c1ac7a3ede 100644 --- a/packages/app/src/components/alerts/EditAlertModal.tsx +++ b/packages/app/src/components/alerts/EditAlertModal.tsx @@ -77,6 +77,8 @@ const EditAlertFormSchema = z // nullish() (not optional()): persisted alerts store this as null, which // optional() would reject. numConsecutiveWindows: z.number().int().min(1).nullish(), + // No control in the UI; declared so a save echoes the stored value. + titleEmoji: z.boolean().nullish(), }) .passthrough() .superRefine(validateAlertChannelSelection) @@ -115,6 +117,7 @@ function alertToFormValues(alert: AlertsPageItem): Alert { tags: alert.tags, // Persisted null -> undefined for the NumberInput. numConsecutiveWindows: alert.numConsecutiveWindows ?? undefined, + titleEmoji: alert.titleEmoji, }; if (alert.source === AlertSource.TILE) { diff --git a/packages/app/src/components/alerts/EditInlineAlertModal.tsx b/packages/app/src/components/alerts/EditInlineAlertModal.tsx index 12aecdd0cb..d3bb6bff59 100644 --- a/packages/app/src/components/alerts/EditInlineAlertModal.tsx +++ b/packages/app/src/components/alerts/EditInlineAlertModal.tsx @@ -56,6 +56,7 @@ export function inlineAlertToChartConfig( note: alert.note ?? null, // Persisted null -> undefined for the NumberInput. numConsecutiveWindows: alert.numConsecutiveWindows ?? undefined, + titleEmoji: alert.titleEmoji, }, }; } diff --git a/packages/app/src/components/alerts/__tests__/EditAlertModal.test.tsx b/packages/app/src/components/alerts/__tests__/EditAlertModal.test.tsx index c7054865f1..19b4602b6c 100644 --- a/packages/app/src/components/alerts/__tests__/EditAlertModal.test.tsx +++ b/packages/app/src/components/alerts/__tests__/EditAlertModal.test.tsx @@ -191,6 +191,16 @@ describe('EditAlertModal', () => { ); }); + it('echoes titleEmoji back unchanged on save', async () => { + renderModal({ ...savedSearchAlert, titleEmoji: false }); + + await submitForm(); + + expect(updateAlertMutateAsync).toHaveBeenCalledWith( + expect.objectContaining({ titleEmoji: false }), + ); + }); + it('sends an edited display name in the PUT payload', async () => { renderModal(savedSearchAlert); diff --git a/packages/common-utils/src/types.ts b/packages/common-utils/src/types.ts index f1c006a299..fbd2e18877 100644 --- a/packages/common-utils/src/types.ts +++ b/packages/common-utils/src/types.ts @@ -1116,6 +1116,7 @@ export const AlertBaseObjectSchema = z.object({ name: z.string().min(1).max(512).nullish(), message: z.string().min(1).max(4096).nullish(), note: alertNoteSchema, + titleEmoji: z.boolean().nullish(), displayName: alertDisplayNameSchema, tags: alertTagsSchema, silenced: z @@ -3065,6 +3066,7 @@ export const AlertsPageItemSchema = z.object({ tags: z.array(z.string()), message: z.string().nullish(), note: alertNoteSchema, + titleEmoji: z.boolean().nullish(), createdAt: z.string(), updatedAt: z.string(), history: z.array(AlertHistorySchema), From 65832ae20038001cda973649181e2296eb8a5967 Mon Sep 17 00:00:00 2001 From: Andrew Dunn Date: Sat, 24 Oct 2026 22:44:08 -0400 Subject: [PATCH 2/7] fix(api): carry titleEmoji into the notification view The alert view built for notifications listed its fields explicitly and left titleEmoji out, so the opt-out never reached the title builder. Add it, with an integration test through processAlert. Also drop the unneeded titleEmoji entries from the passthrough form schemas and restore the state-emoji comment in the title builder. --- .../__tests__/checkAlerts.int.test.ts | 84 +++++++++++++++++++ packages/api/src/tasks/checkAlerts/index.ts | 1 + .../api/src/tasks/checkAlerts/template.ts | 5 +- packages/app/src/DBSearchPageAlertModal.tsx | 2 - .../src/components/alerts/EditAlertModal.tsx | 2 - 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts index 8ef7412f5c..3ae2718a3c 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts @@ -2477,6 +2477,90 @@ describe('checkAlerts', () => { ); }); + it('SAVED_SEARCH alert - titleEmoji false drops the emoji from fired and resolved titles', async () => { + const { + team, + webhook, + connection, + source, + savedSearch, + teamWebhooksById, + clickhouseClient, + } = await setupSavedSearchAlertTest(); + + const details = await createAlertDetails( + team, + source, + { + source: AlertSource.SAVED_SEARCH, + channel: { + type: 'webhook', + webhookId: webhook._id.toString(), + }, + interval: '5m', + thresholdType: AlertThresholdType.ABOVE, + threshold: 1, + savedSearchId: savedSearch.id, + titleEmoji: false, + }, + { + taskType: AlertTaskType.SAVED_SEARCH, + savedSearch, + }, + ); + + await bulkInsertLogs([ + { + ServiceName: 'api', + Timestamp: new Date('2023-11-16T22:05:00.000Z'), + SeverityText: 'error', + Body: 'Oh no! Something went wrong!', + }, + { + ServiceName: 'api', + Timestamp: new Date('2023-11-16T22:05:00.000Z'), + SeverityText: 'error', + Body: 'Oh no! Something went wrong!', + }, + ]); + + await processAlertAtTime( + new Date('2023-11-16T22:12:00.000Z'), + details, + clickhouseClient, + connection.id, + alertProvider, + teamWebhooksById, + ); + expect((await Alert.findById(details.alert.id))!.state).toBe('ALERT'); + + await processAlertAtTime( + new Date('2023-11-16T22:20:00.000Z'), + details, + clickhouseClient, + connection.id, + alertProvider, + teamWebhooksById, + ); + expect((await Alert.findById(details.alert.id))!.state).toBe('OK'); + + expect(slack.postMessageToWebhook).toHaveBeenCalledTimes(2); + expect(slack.postMessageToWebhook).toHaveBeenNthCalledWith( + 1, + 'https://hooks.slack.com/services/123', + expect.objectContaining({ + text: 'Alert for "My Search" - 2 lines found', + }), + ); + expect(slack.postMessageToWebhook).toHaveBeenNthCalledWith( + 2, + 'https://hooks.slack.com/services/123', + expect.objectContaining({ + text: expect.not.stringMatching(/🚨|✅/), + }), + ); + }); + // The scheduled alert task and the app search page both go through // `buildSearchChartConfig`, which prepends the Log source's // `tableFilterExpression` (when set) as a SQL filter. This regression diff --git a/packages/api/src/tasks/checkAlerts/index.ts b/packages/api/src/tasks/checkAlerts/index.ts index 17a6b66c35..acbdb0f74e 100644 --- a/packages/api/src/tasks/checkAlerts/index.ts +++ b/packages/api/src/tasks/checkAlerts/index.ts @@ -532,6 +532,7 @@ const fireChannelEvent = async ({ thresholdMax: alert.thresholdMax, thresholdType: alert.thresholdType, tileId: alert.tileId, + titleEmoji: alert.titleEmoji, // Inline alerts: the persisted config, used to build the explorer link // and the default notification title. chartConfig: alert.chartConfig, diff --git a/packages/api/src/tasks/checkAlerts/template.ts b/packages/api/src/tasks/checkAlerts/template.ts index e7ca6b79cc..34da92f2d4 100644 --- a/packages/api/src/tasks/checkAlerts/template.ts +++ b/packages/api/src/tasks/checkAlerts/template.ts @@ -367,8 +367,9 @@ export const buildAlertMessageTemplateTitle = ({ dashboard, }); - const emoji = - alert.titleEmoji === false ? '' : isAlertResolved(state) ? '✅ ' : '🚨 '; + // Add emoji prefix based on alert state, unless the alert opts out + const stateEmoji = isAlertResolved(state) ? '✅ ' : '🚨 '; + const emoji = alert.titleEmoji === false ? '' : stateEmoji; if (alert.source === AlertSource.SAVED_SEARCH) { if (savedSearch == null) { diff --git a/packages/app/src/DBSearchPageAlertModal.tsx b/packages/app/src/DBSearchPageAlertModal.tsx index 3b93caa1f3..ab748a0312 100644 --- a/packages/app/src/DBSearchPageAlertModal.tsx +++ b/packages/app/src/DBSearchPageAlertModal.tsx @@ -90,8 +90,6 @@ const SavedSearchAlertFormSchema = z // nullish() (not optional()): persisted alerts store this as null, which // optional() would reject. numConsecutiveWindows: z.number().int().min(1).nullish(), - // No control in the UI; declared so a save echoes the stored value. - titleEmoji: z.boolean().nullish(), }) .passthrough() .superRefine(validateAlertScheduleOffsetMinutes) diff --git a/packages/app/src/components/alerts/EditAlertModal.tsx b/packages/app/src/components/alerts/EditAlertModal.tsx index c1ac7a3ede..766eb35b69 100644 --- a/packages/app/src/components/alerts/EditAlertModal.tsx +++ b/packages/app/src/components/alerts/EditAlertModal.tsx @@ -77,8 +77,6 @@ const EditAlertFormSchema = z // nullish() (not optional()): persisted alerts store this as null, which // optional() would reject. numConsecutiveWindows: z.number().int().min(1).nullish(), - // No control in the UI; declared so a save echoes the stored value. - titleEmoji: z.boolean().nullish(), }) .passthrough() .superRefine(validateAlertChannelSelection) From ae69d335bd4bb8d67c5f47a67dc19d54a0a3eeaf Mon Sep 17 00:00:00 2001 From: Andrew Dunn Date: Tue, 27 Oct 2026 01:31:46 -0400 Subject: [PATCH 3/7] feat: move the title emoji toggle from the alert to the webhook --- .changeset/alert-title-emoji-toggle.md | 2 +- packages/api/openapi.json | 30 ++++++--- packages/api/src/controllers/alerts.ts | 1 - packages/api/src/controllers/webhook.ts | 27 +++++++- .../api/src/mcp/tools/alerts/saveAlert.ts | 2 +- .../api/src/mcp/tools/alerts/saveWebhook.ts | 12 +++- packages/api/src/models/alert.ts | 7 -- packages/api/src/models/webhook.ts | 6 ++ .../routers/api/__tests__/alerts.int.test.ts | 51 --------------- packages/api/src/routers/api/alerts.ts | 1 - packages/api/src/routers/api/webhooks.ts | 28 ++++++-- .../external-api/__tests__/alerts.int.test.ts | 40 ------------ .../__tests__/webhooks.int.test.ts | 51 +++++++++++++++ .../api/src/routers/external-api/v2/alerts.ts | 5 -- .../src/routers/external-api/v2/webhooks.ts | 46 +++++++++++-- .../__tests__/checkAlerts.int.test.ts | 44 ++++++++----- .../__tests__/renderAlertTemplate.int.test.ts | 65 ------------------- packages/api/src/tasks/checkAlerts/index.ts | 1 - .../api/src/tasks/checkAlerts/template.ts | 14 ++-- .../src/utils/__tests__/externalApi.test.ts | 26 -------- packages/api/src/utils/externalApi.ts | 2 - packages/api/src/utils/zod.ts | 3 +- packages/app/src/api.ts | 6 ++ .../components/TeamSettings/WebhookForm.tsx | 13 +++- .../__tests__/WebhookForm.test.tsx | 17 +++++ .../src/components/alerts/EditAlertModal.tsx | 1 - .../alerts/EditInlineAlertModal.tsx | 1 - .../alerts/__tests__/EditAlertModal.test.tsx | 10 --- packages/common-utils/src/types.ts | 3 +- 29 files changed, 256 insertions(+), 259 deletions(-) diff --git a/.changeset/alert-title-emoji-toggle.md b/.changeset/alert-title-emoji-toggle.md index a9ac1100e3..86158ae7c7 100644 --- a/.changeset/alert-title-emoji-toggle.md +++ b/.changeset/alert-title-emoji-toggle.md @@ -4,4 +4,4 @@ '@hyperdx/common-utils': minor --- -feat: add optional `titleEmoji` alert field; `false` removes the emoji prefix from notification titles +feat: add optional `titleEmoji` webhook option; `false` removes the emoji prefix from notification titles sent through that webhook diff --git a/packages/api/openapi.json b/packages/api/openapi.json index 7c88712e32..83203b68af 100644 --- a/packages/api/openapi.json +++ b/packages/api/openapi.json @@ -413,12 +413,6 @@ "maxLength": 4096, "example": "Threshold raised from 50 to 100 on 2026-01-15. See [runbook](https://wiki.example.com/runbook)." }, - "titleEmoji": { - "type": "boolean", - "nullable": true, - "description": "Set to false to omit the state emoji prefix from notification titles. Unset, null or true keeps the default prefix.", - "example": false - }, "numConsecutiveWindows": { "type": "integer", "minimum": 1, @@ -5833,6 +5827,11 @@ "description": "Webhook description, shown in the UI", "example": "Sends critical alerts to the #incidents channel" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "updatedAt": { "type": "string", "format": "date-time", @@ -5885,6 +5884,11 @@ "description": "Webhook description, shown in the UI", "example": "Routes alerts to incident.io for on-call escalation" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "updatedAt": { "type": "string", "format": "date-time", @@ -5937,6 +5941,11 @@ "description": "Webhook description, shown in the UI", "example": "Forwards alert payloads to an external monitoring service" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "body": { "type": "string", "description": "Optional request body template", @@ -6029,7 +6038,7 @@ "service", "url" ], - "description": "Webhook create/update body. `body`, `headers`, and `queryParams`\nonly take effect for services that issue a templated HTTP request\n(`generic`, `incidentio`). The `slack` service posts a fixed payload\nto its incoming-webhook URL and ignores them, so supplying any of\nthese fields on a `slack` webhook is rejected. `headers` and\n`queryParams` are write-only — they are accepted here but never\nreturned by any read endpoint, so secrets such as auth tokens do\nnot leak. On\nupdate (PUT), omitted readable fields (`description`, `body`) are\ncleared, while omitted `headers`/`queryParams` are preserved —\nsend an explicit `{}` to clear them. Exception: if the destination\n(`url` or `service`) changes, omitted `headers`/`queryParams` are\ncleared rather than preserved, so stored secrets are never forwarded\nto a new destination; re-supply them for the new destination.\n", + "description": "Webhook create/update body. `body`, `headers`, and `queryParams`\nonly take effect for services that issue a templated HTTP request\n(`generic`, `incidentio`). The `slack` service posts a fixed payload\nto its incoming-webhook URL and ignores them, so supplying any of\nthese fields on a `slack` webhook is rejected. `headers` and\n`queryParams` are write-only — they are accepted here but never\nreturned by any read endpoint, so secrets such as auth tokens do\nnot leak. On\nupdate (PUT), omitted readable fields (`description`, `titleEmoji`, `body`) are\ncleared, while omitted `headers`/`queryParams` are preserved —\nsend an explicit `{}` to clear them. Exception: if the destination\n(`url` or `service`) changes, omitted `headers`/`queryParams` are\ncleared rather than preserved, so stored secrets are never forwarded\nto a new destination; re-supply them for the new destination.\n", "properties": { "name": { "type": "string", @@ -6060,6 +6069,11 @@ "description": "Webhook description, shown in the UI.", "example": "Sends critical alerts to the #incidents channel" }, + "titleEmoji": { + "type": "boolean", + "description": "Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix.", + "example": false + }, "body": { "type": "string", "maxLength": 16384, @@ -9184,7 +9198,7 @@ "/api/v2/webhooks/{id}": { "put": { "summary": "Update Webhook", - "description": "Replaces an existing webhook. Readable optional fields\n(`description`, `body`) are a full replace: omitting them clears\nthem. The write-only fields `headers` and `queryParams` are never\nreturned on read, so omitting them preserves the stored values;\nsend an explicit empty object (`{}`) to clear them. Exception: if the\ndestination (`url` or `service`) changes, omitted `headers`/\n`queryParams` are cleared rather than preserved so stored secrets are\nnever forwarded to a new destination.\n", + "description": "Replaces an existing webhook. Readable optional fields\n(`description`, `titleEmoji`, `body`) are a full replace: omitting them clears\nthem. The write-only fields `headers` and `queryParams` are never\nreturned on read, so omitting them preserves the stored values;\nsend an explicit empty object (`{}`) to clear them. Exception: if the\ndestination (`url` or `service`) changes, omitted `headers`/\n`queryParams` are cleared rather than preserved so stored secrets are\nnever forwarded to a new destination.\n", "operationId": "updateWebhook", "tags": [ "Webhooks" diff --git a/packages/api/src/controllers/alerts.ts b/packages/api/src/controllers/alerts.ts index ea7a532446..0e8762e48c 100644 --- a/packages/api/src/controllers/alerts.ts +++ b/packages/api/src/controllers/alerts.ts @@ -299,7 +299,6 @@ export const makeAlert = ( name: alert.name ?? null, message: alert.message ?? null, note: alert.note ?? null, - titleEmoji: alert.titleEmoji ?? null, displayName, tags, diff --git a/packages/api/src/controllers/webhook.ts b/packages/api/src/controllers/webhook.ts index a37f41fcbe..5f5a66b30b 100644 --- a/packages/api/src/controllers/webhook.ts +++ b/packages/api/src/controllers/webhook.ts @@ -11,6 +11,7 @@ export interface WebhookInput { service: WebhookService; url: string; description?: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -22,7 +23,16 @@ export interface WebhookInput { */ export async function createWebhook( team: ObjectId | string, - { name, service, url, description, queryParams, headers, body }: WebhookInput, + { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + }: WebhookInput, ) { validateWebhookConfig({ service, url, body }); @@ -32,6 +42,7 @@ export async function createWebhook( service, url, description, + titleEmoji, queryParams, headers, body, @@ -53,7 +64,16 @@ export type UpdateWebhookResult = export async function updateWebhook( team: ObjectId | string, webhookId: string, - { name, service, url, description, queryParams, headers, body }: WebhookInput, + { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + }: WebhookInput, ): Promise { const existing = await Webhook.findOne({ _id: webhookId, team }); if (existing == null) { @@ -71,6 +91,9 @@ export async function updateWebhook( if (description === undefined) unsetFields.description = 1; else setFields.description = description; + if (titleEmoji === undefined) unsetFields.titleEmoji = 1; + else setFields.titleEmoji = titleEmoji; + if (body === undefined) unsetFields.body = 1; else setFields.body = body; diff --git a/packages/api/src/mcp/tools/alerts/saveAlert.ts b/packages/api/src/mcp/tools/alerts/saveAlert.ts index 2b3d5df0a5..9c5962026d 100644 --- a/packages/api/src/mcp/tools/alerts/saveAlert.ts +++ b/packages/api/src/mcp/tools/alerts/saveAlert.ts @@ -56,7 +56,7 @@ export function registerSaveAlert({ 'alert configuration rather than merging it: channels you do not resend are ' + 'removed, omitted name and message are cleared, omitted displayName and tags ' + 'are re-derived from the source, and settings this tool cannot set ' + - '(note, consecutive-window count, title emoji) are cleared. Omitting both ' + + '(note, consecutive-window count) are cleared. Omitting both ' + 'scheduleStartAt and scheduleOffsetMinutes keeps the stored schedule; ' + 'clearing scheduleStartAt without an offset resets the offset to 0. Read the alert with ' + 'clickstack_get_alert first and resend every field you want to keep.', diff --git a/packages/api/src/mcp/tools/alerts/saveWebhook.ts b/packages/api/src/mcp/tools/alerts/saveWebhook.ts index 3d0e0f801f..5542f47f60 100644 --- a/packages/api/src/mcp/tools/alerts/saveWebhook.ts +++ b/packages/api/src/mcp/tools/alerts/saveWebhook.ts @@ -59,6 +59,14 @@ const mcpSaveWebhookSchema = z.object({ 'Description shown in the UI. On update this is a full replace: ' + 'omitting it clears the stored description.', ), + titleEmoji: z + .boolean() + .optional() + .describe( + 'Set to false to omit the state emoji prefix from notification titles ' + + 'sent through this webhook. On update this is a full replace: ' + + 'omitting it restores the default prefix.', + ), headers: z .record(z.string(), z.string()) .optional() @@ -105,8 +113,8 @@ export function registerSaveWebhook({ 'clickstack_save_alert. For the slack service the url host must end ' + 'in slack.com and headers/queryParams/body are not supported. On ' + 'update, every alert using this webhook sends its next notifications ' + - 'with the new settings, including a changed url. description and body ' + - 'are a full replace (omitting them clears them), while write-only ' + + 'with the new settings, including a changed url. description, titleEmoji and ' + + 'body are a full replace (omitting them clears them), while write-only ' + 'headers/queryParams are preserved when omitted (send {} to clear); ' + 'changing url or service clears omitted headers/queryParams. ' + 'url, headers, and queryParams are never returned.', diff --git a/packages/api/src/models/alert.ts b/packages/api/src/models/alert.ts index 443192d0f1..3e62d19eab 100644 --- a/packages/api/src/models/alert.ts +++ b/packages/api/src/models/alert.ts @@ -99,9 +99,6 @@ export interface IAlert { // Freeform note (supports markdown) note?: string | null; - // false drops the state emoji prefix from the notification title - titleEmoji?: boolean | null; - // User-facing name shown in the alerts list and notification titles (when not overridden by name template). // Unset means "derive from the referenced saved search / dashboard tile". displayName?: string | null; @@ -218,10 +215,6 @@ const AlertSchema = new Schema( type: String, required: false, }, - titleEmoji: { - type: Boolean, - required: false, - }, displayName: { type: String, required: false, diff --git a/packages/api/src/models/webhook.ts b/packages/api/src/models/webhook.ts index c31bf1358c..58a5a87f54 100644 --- a/packages/api/src/models/webhook.ts +++ b/packages/api/src/models/webhook.ts @@ -23,6 +23,8 @@ export interface IWebhook { updatedAt: Date; url?: string; description?: string; + // false drops the state emoji prefix from notification titles + titleEmoji?: boolean; // reminder to serialize/convert the Mongoose model instance to a plain javascript object when using // to strip the additional properties that are related to the Mongoose internal representation -> webhook.headers.toJSON() queryParams?: MongooseMap; @@ -50,6 +52,10 @@ const WebhookSchema = new Schema( type: String, required: false, }, + titleEmoji: { + type: Boolean, + required: false, + }, queryParams: { type: Map, of: String, diff --git a/packages/api/src/routers/api/__tests__/alerts.int.test.ts b/packages/api/src/routers/api/__tests__/alerts.int.test.ts index 9c4b980558..8d81390593 100644 --- a/packages/api/src/routers/api/__tests__/alerts.int.test.ts +++ b/packages/api/src/routers/api/__tests__/alerts.int.test.ts @@ -424,57 +424,6 @@ describe('alerts router', () => { expect(afterClear.body.data.note).toBeNull(); }); - it('round-trips titleEmoji through create, update, and clear', async () => { - const dashboard = await agent - .post('/dashboards') - .send(MOCK_DASHBOARD) - .expect(200); - - const alert = await agent - .post('/alerts') - .send({ - ...makeAlertInput({ - dashboardId: dashboard.body.id, - tileId: dashboard.body.tiles[0].id, - webhookId: webhook._id.toString(), - }), - titleEmoji: false, - }) - .expect(200); - expect(alert.body.data.titleEmoji).toBe(false); - - const single = await agent - .get(`/alerts/${alert.body.data._id}`) - .expect(200); - expect(single.body.data.titleEmoji).toBe(false); - - await agent - .put(`/alerts/${alert.body.data._id}`) - .send({ - ...alert.body.data, - dashboardId: dashboard.body.id, - titleEmoji: true, - }) - .expect(200); - const afterUpdate = await agent - .get(`/alerts/${alert.body.data._id}`) - .expect(200); - expect(afterUpdate.body.data.titleEmoji).toBe(true); - - await agent - .put(`/alerts/${alert.body.data._id}`) - .send({ - ...alert.body.data, - dashboardId: dashboard.body.id, - titleEmoji: null, - }) - .expect(200); - const afterClear = await agent - .get(`/alerts/${alert.body.data._id}`) - .expect(200); - expect(afterClear.body.data.titleEmoji).toBeNull(); - }); - it('round-trips displayName and tags through create, update, and revert', async () => { const dashboard = await agent .post('/dashboards') diff --git a/packages/api/src/routers/api/alerts.ts b/packages/api/src/routers/api/alerts.ts index 1e673392b8..3085e3d764 100644 --- a/packages/api/src/routers/api/alerts.ts +++ b/packages/api/src/routers/api/alerts.ts @@ -113,7 +113,6 @@ const formatAlertResponse = ( 'name', 'message', 'note', - 'titleEmoji', 'createdAt', 'updatedAt', 'executionErrors', diff --git a/packages/api/src/routers/api/webhooks.ts b/packages/api/src/routers/api/webhooks.ts index 4973dff1d8..b0b698d2e3 100644 --- a/packages/api/src/routers/api/webhooks.ts +++ b/packages/api/src/routers/api/webhooks.ts @@ -167,6 +167,7 @@ router.post( body: z.object({ body: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), headers: z .record(webhookHeaderNameSchema, webhookHeaderValueSchema) .optional(), @@ -188,8 +189,16 @@ router.post( if (teamId == null) { return res.sendStatus(403); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; // The unique index is on (team, service, name), so the pre-flight check // must query the same fields — otherwise a name+service collision slips // past this guard and surfaces as an uncaught duplicate-key 500 below. @@ -203,6 +212,7 @@ router.post( service, url, description, + titleEmoji, queryParams, headers, body, @@ -233,6 +243,7 @@ router.put( body: z.object({ body: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), headers: z .record(webhookHeaderNameSchema, webhookHeaderValueSchema) .optional(), @@ -254,8 +265,16 @@ router.put( if (teamId == null) { return res.sendStatus(403); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const { id } = req.params; const existingWebhook = await Webhook.findOne({ @@ -323,6 +342,7 @@ router.put( service, url: resolvedUrl, description, + titleEmoji, body, }; const $unset: Record = {}; diff --git a/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts b/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts index 1a6d1b0109..0d79f5ef43 100644 --- a/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts +++ b/packages/api/src/routers/external-api/__tests__/alerts.int.test.ts @@ -480,7 +480,6 @@ describe('External API Alerts', () => { tags: [], message: 'This is a test alert for format verification', note: null, - titleEmoji: null, numConsecutiveWindows: null, threshold: 123, interval: '15m', @@ -2726,45 +2725,6 @@ describe('External API Alerts', () => { expect(getResponse.body.data.numConsecutiveWindows).toBeNull(); }); }); - - describe('Notification title emoji (titleEmoji)', () => { - it('should default titleEmoji to null when not provided', async () => { - const { alert } = await createTestAlert(); - - expect(alert.titleEmoji).toBeNull(); - }); - - it('should create an alert with titleEmoji false and return it on GET', async () => { - const { alert } = await createTestAlert({ titleEmoji: false }); - - expect(alert.titleEmoji).toBe(false); - - const getResponse = await authRequest( - 'get', - `${ALERTS_BASE_URL}/${alert.id}`, - ).expect(200); - - expect(getResponse.body.data.titleEmoji).toBe(false); - }); - - it('should update an alert to set titleEmoji', async () => { - const { alert, alertInput } = await createTestAlert({ - titleEmoji: false, - }); - - await authRequest('put', `${ALERTS_BASE_URL}/${alert.id}`) - .send({ ...alertInput, titleEmoji: true }) - .expect(200); - - const getResponse = await authRequest( - 'get', - `${ALERTS_BASE_URL}/${alert.id}`, - ).expect(200); - - expect(getResponse.body.data.titleEmoji).toBe(true); - }); - }); - describe('Multiple notification channels', () => { const makeWebhookNamed = async (name: string) => await Webhook.findOneAndUpdate( diff --git a/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts b/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts index 60ec86ef90..b5370a7b50 100644 --- a/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts +++ b/packages/api/src/routers/external-api/__tests__/webhooks.int.test.ts @@ -331,6 +331,27 @@ describe('External API v2 Webhooks', () => { .expect(401); }); + it('should round-trip titleEmoji through create and list', async () => { + const response = await authRequest('post', WEBHOOKS_BASE_URL) + .send({ ...MOCK_SLACK_WEBHOOK, titleEmoji: false }) + .expect(200); + expect(response.body.data.titleEmoji).toBe(false); + + const stored = await Webhook.findById(response.body.data.id).lean(); + expect(stored?.titleEmoji).toBe(false); + + const list = await authRequest('get', WEBHOOKS_BASE_URL).expect(200); + expect(list.body.data[0].titleEmoji).toBe(false); + }); + + it('should leave titleEmoji unset when not provided', async () => { + const response = await authRequest('post', WEBHOOKS_BASE_URL) + .send(MOCK_SLACK_WEBHOOK) + .expect(200); + + expect(response.body.data).not.toHaveProperty('titleEmoji'); + }); + it('should create a Slack webhook and never return sensitive fields', async () => { const response = await authRequest('post', WEBHOOKS_BASE_URL) .send(MOCK_GENERIC_WEBHOOK) @@ -635,6 +656,36 @@ describe('External API v2 Webhooks', () => { expect(stored?.description).toBeUndefined(); }); + it('should set titleEmoji on update and clear it when omitted', async () => { + const created = await Webhook.create({ + ...MOCK_SLACK_WEBHOOK, + team: team._id, + }); + const base = { + name: MOCK_SLACK_WEBHOOK.name, + service: WebhookService.Slack, + url: MOCK_SLACK_WEBHOOK.url, + }; + + const set = await authRequest( + 'put', + `${WEBHOOKS_BASE_URL}/${created._id}`, + ) + .send({ ...base, titleEmoji: false }) + .expect(200); + expect(set.body.data.titleEmoji).toBe(false); + expect((await Webhook.findById(created._id).lean())?.titleEmoji).toBe( + false, + ); + + await authRequest('put', `${WEBHOOKS_BASE_URL}/${created._id}`) + .send(base) + .expect(200); + expect( + (await Webhook.findById(created._id).lean())?.titleEmoji, + ).toBeUndefined(); + }); + it('should preserve omitted queryParams when the destination is unchanged', async () => { const created = await Webhook.create({ ...MOCK_GENERIC_WEBHOOK, diff --git a/packages/api/src/routers/external-api/v2/alerts.ts b/packages/api/src/routers/external-api/v2/alerts.ts index 25aa82882c..7a23df9d1a 100644 --- a/packages/api/src/routers/external-api/v2/alerts.ts +++ b/packages/api/src/routers/external-api/v2/alerts.ts @@ -322,11 +322,6 @@ function toInternalAlertInput(body: ExternalAlertInput): InternalAlertInput { * minLength: 1 * maxLength: 4096 * example: "Threshold raised from 50 to 100 on 2026-01-15. See [runbook](https://wiki.example.com/runbook)." - * titleEmoji: - * type: boolean - * nullable: true - * description: Set to false to omit the state emoji prefix from notification titles. Unset, null or true keeps the default prefix. - * example: false * numConsecutiveWindows: * type: integer * minimum: 1 diff --git a/packages/api/src/routers/external-api/v2/webhooks.ts b/packages/api/src/routers/external-api/v2/webhooks.ts index 479334e13e..61ce85274e 100644 --- a/packages/api/src/routers/external-api/v2/webhooks.ts +++ b/packages/api/src/routers/external-api/v2/webhooks.ts @@ -135,6 +135,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: "Sends critical alerts to the #incidents channel" + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * updatedAt: * type: string * format: date-time @@ -175,6 +179,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: Routes alerts to incident.io for on-call escalation + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * updatedAt: * type: string * format: date-time @@ -215,6 +223,10 @@ function formatExternalWebhook( * type: string * description: Webhook description, shown in the UI * example: Forwards alert payloads to an external monitoring service + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * body: * type: string * description: Optional request body template @@ -379,7 +391,7 @@ router.get( * `queryParams` are write-only — they are accepted here but never * returned by any read endpoint, so secrets such as auth tokens do * not leak. On - * update (PUT), omitted readable fields (`description`, `body`) are + * update (PUT), omitted readable fields (`description`, `titleEmoji`, `body`) are * cleared, while omitted `headers`/`queryParams` are preserved — * send an explicit `{}` to clear them. Exception: if the destination * (`url` or `service`) changes, omitted `headers`/`queryParams` are @@ -407,6 +419,10 @@ router.get( * maxLength: 2048 * description: Webhook description, shown in the UI. * example: "Sends critical alerts to the #incidents channel" + * titleEmoji: + * type: boolean + * description: Set to false to omit the state emoji prefix from notification titles sent through this webhook. Unset or true keeps the default prefix. + * example: false * body: * type: string * maxLength: 16384 @@ -611,14 +627,23 @@ router.post( return res.status(403).json({ message: 'Forbidden' }); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const webhook = await createWebhook(teamId, { name, service, url, description, + titleEmoji, queryParams, headers, body, @@ -647,7 +672,7 @@ router.post( * summary: Update Webhook * description: | * Replaces an existing webhook. Readable optional fields - * (`description`, `body`) are a full replace: omitting them clears + * (`description`, `titleEmoji`, `body`) are a full replace: omitting them clears * them. The write-only fields `headers` and `queryParams` are never * returned on read, so omitting them preserves the stored values; * send an explicit empty object (`{}`) to clear them. Exception: if the @@ -721,14 +746,23 @@ router.put( return res.status(403).json({ message: 'Forbidden' }); } - const { name, service, url, description, queryParams, headers, body } = - req.body; + const { + name, + service, + url, + description, + titleEmoji, + queryParams, + headers, + body, + } = req.body; const result = await updateWebhook(teamId, req.params.id, { name, service, url, description, + titleEmoji, queryParams, headers, body, diff --git a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts index 3ae2718a3c..972411b891 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts @@ -2477,16 +2477,27 @@ describe('checkAlerts', () => { ); }); - it('SAVED_SEARCH alert - titleEmoji false drops the emoji from fired and resolved titles', async () => { + it('SAVED_SEARCH alert - titleEmoji is applied per webhook on fired and resolved titles', async () => { const { team, webhook, connection, source, savedSearch, - teamWebhooksById, clickhouseClient, - } = await setupSavedSearchAlertTest(); + } = await setupSavedSearchAlertTest({ + webhookSettings: { titleEmoji: false } as IWebhook, + }); + const emojiWebhook = await new Webhook({ + team: team._id, + service: 'slack', + url: 'https://hooks.slack.com/services/456', + name: 'Emoji Webhook', + }).save(); + const teamWebhooksById = new Map([ + [webhook._id.toString(), webhook], + [emojiWebhook._id.toString(), emojiWebhook], + ]); const details = await createAlertDetails( team, @@ -2501,7 +2512,7 @@ describe('checkAlerts', () => { thresholdType: AlertThresholdType.ABOVE, threshold: 1, savedSearchId: savedSearch.id, - titleEmoji: false, + message: '@webhook-Emoji_Webhook', }, { taskType: AlertTaskType.SAVED_SEARCH, @@ -2544,21 +2555,22 @@ describe('checkAlerts', () => { ); expect((await Alert.findById(details.alert.id))!.state).toBe('OK'); - expect(slack.postMessageToWebhook).toHaveBeenCalledTimes(2); - expect(slack.postMessageToWebhook).toHaveBeenNthCalledWith( - 1, + const textsFor = (url: string) => + (slack.postMessageToWebhook as jest.Mock).mock.calls + .filter(([calledUrl]) => calledUrl === url) + .map(([, payload]) => payload.text); + + const [plainFired, plainResolved] = textsFor( 'https://hooks.slack.com/services/123', - expect.objectContaining({ - text: 'Alert for "My Search" - 2 lines found', - }), ); - expect(slack.postMessageToWebhook).toHaveBeenNthCalledWith( - 2, - 'https://hooks.slack.com/services/123', - expect.objectContaining({ - text: expect.not.stringMatching(/🚨|✅/), - }), + expect(plainFired).toBe('Alert for "My Search" - 2 lines found'); + expect(plainResolved).toMatch(/^Alert for "My Search"/); + + const [emojiFired, emojiResolved] = textsFor( + 'https://hooks.slack.com/services/456', ); + expect(emojiFired).toBe('🚨 Alert for "My Search" - 2 lines found'); + expect(emojiResolved).toMatch(/^✅ Alert for "My Search"/); }); // The scheduled alert task and the app search page both go through diff --git a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts index cc05e994a0..c3e09091bc 100644 --- a/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts +++ b/packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts @@ -896,71 +896,6 @@ describe('buildAlertMessageTemplateTitle', () => { }); }); - describe('alert.titleEmoji', () => { - const withTitleEmoji = (titleEmoji: boolean) => { - const view = makeSearchView(); - return { - ...view, - alert: { ...view.alert, name: 'Custom title', titleEmoji }, - }; - }; - - it('drops the prefix of a firing alert when false', () => { - const result = buildAlertMessageTemplateTitle({ - view: withTitleEmoji(false), - state: AlertState.ALERT, - }); - - expect(result).toBe('Custom title'); - }); - - it('drops the prefix of a resolved alert when false', () => { - const result = buildAlertMessageTemplateTitle({ - view: withTitleEmoji(false), - state: AlertState.OK, - }); - - expect(result).toBe('Custom title'); - }); - - it('keeps the prefix of a resolved alert when true', () => { - const result = buildAlertMessageTemplateTitle({ - view: withTitleEmoji(true), - state: AlertState.OK, - }); - - expect(result).toBe('✅ Custom title'); - }); - - it('keeps the prefix of a resolved alert when unset', () => { - const view = makeSearchView(); - const result = buildAlertMessageTemplateTitle({ - view: { ...view, alert: { ...view.alert, name: 'Custom title' } }, - state: AlertState.OK, - }); - - expect(result).toBe('✅ Custom title'); - }); - - it('keeps the prefix when true', () => { - const result = buildAlertMessageTemplateTitle({ - view: withTitleEmoji(true), - state: AlertState.ALERT, - }); - - expect(result).toBe('🚨 Custom title'); - }); - - it('keeps the prefix when unset', () => { - const result = buildAlertMessageTemplateTitle({ - view: makeSearchView(), - state: AlertState.ALERT, - }); - - expect(result).toMatch(/^🚨 /); - }); - }); - describe('stored displayName', () => { it('names a saved-search alert', () => { const view = makeSearchView(); diff --git a/packages/api/src/tasks/checkAlerts/index.ts b/packages/api/src/tasks/checkAlerts/index.ts index acbdb0f74e..17a6b66c35 100644 --- a/packages/api/src/tasks/checkAlerts/index.ts +++ b/packages/api/src/tasks/checkAlerts/index.ts @@ -532,7 +532,6 @@ const fireChannelEvent = async ({ thresholdMax: alert.thresholdMax, thresholdType: alert.thresholdType, tileId: alert.tileId, - titleEmoji: alert.titleEmoji, // Inline alerts: the persisted config, used to build the explorer link // and the default notification title. chartConfig: alert.chartConfig, diff --git a/packages/api/src/tasks/checkAlerts/template.ts b/packages/api/src/tasks/checkAlerts/template.ts index 34da92f2d4..4a0b967b1f 100644 --- a/packages/api/src/tasks/checkAlerts/template.ts +++ b/packages/api/src/tasks/checkAlerts/template.ts @@ -265,6 +265,9 @@ export const isAlertResolved = (state?: AlertState): boolean => { return state === AlertState.OK; }; +const stateTitleEmoji = (state?: AlertState): string => + isAlertResolved(state) ? '✅ ' : '🚨 '; + /** * Formats the value to match the decimal precision of the threshold. * This ensures consistent display of numbers in alert messages. @@ -367,9 +370,8 @@ export const buildAlertMessageTemplateTitle = ({ dashboard, }); - // Add emoji prefix based on alert state, unless the alert opts out - const stateEmoji = isAlertResolved(state) ? '✅ ' : '🚨 '; - const emoji = alert.titleEmoji === false ? '' : stateEmoji; + // Add emoji prefix based on alert state + const emoji = stateTitleEmoji(state); if (alert.source === AlertSource.SAVED_SEARCH) { if (savedSearch == null) { @@ -740,7 +742,11 @@ export const renderAlertTemplate = async ({ populatedChannel: channel, message: { hdxLink: buildAlertMessageTemplateHdxLink(alertProvider, view), - title, + // The shared title carries the state emoji; a webhook can opt out. + title: + channel.channel.titleEmoji === false + ? title.slice(stateTitleEmoji(state).length) + : title, body: renderedBody, state, startTime: view.startTime.getTime(), diff --git a/packages/api/src/utils/__tests__/externalApi.test.ts b/packages/api/src/utils/__tests__/externalApi.test.ts index 197cfca525..abbb40da81 100644 --- a/packages/api/src/utils/__tests__/externalApi.test.ts +++ b/packages/api/src/utils/__tests__/externalApi.test.ts @@ -181,32 +181,6 @@ describe('utils/externalApi', () => { }); }); - describe('titleEmoji handling', () => { - it('returns titleEmoji as null when the value is null', () => { - const alert = createAlertDocument({ titleEmoji: null }); - - const translated = translateAlertDocumentToExternalAlert(alert); - - expect(translated.titleEmoji).toBeNull(); - }); - - it('returns titleEmoji as null when the value is undefined', () => { - const alert = createAlertDocument({ titleEmoji: undefined }); - - const translated = translateAlertDocumentToExternalAlert(alert); - - expect(translated.titleEmoji).toBeNull(); - }); - - it('returns titleEmoji when the value is false', () => { - const alert = createAlertDocument({ titleEmoji: false }); - - const translated = translateAlertDocumentToExternalAlert(alert); - - expect(translated.titleEmoji).toBe(false); - }); - }); - describe('numConsecutiveWindows handling', () => { it('returns numConsecutiveWindows as null when the value is null', () => { const alert = createAlertDocument({ numConsecutiveWindows: null }); diff --git a/packages/api/src/utils/externalApi.ts b/packages/api/src/utils/externalApi.ts index 282a0282d6..187abd7a24 100644 --- a/packages/api/src/utils/externalApi.ts +++ b/packages/api/src/utils/externalApi.ts @@ -331,7 +331,6 @@ export type ExternalAlert = { tags: string[]; message?: string | null; note?: string | null; - titleEmoji?: boolean | null; threshold: number; thresholdMax?: number; interval: AlertInterval; @@ -503,7 +502,6 @@ export function translateAlertDocumentToExternalAlert( ...resolveAlertDisplayFields(alertObj, { dashboard, savedSearch }), message: alertObj.message, note: alertObj.note ?? null, - titleEmoji: alertObj.titleEmoji ?? null, threshold: alertObj.threshold, thresholdMax: alertObj.thresholdMax, interval: alertObj.interval, diff --git a/packages/api/src/utils/zod.ts b/packages/api/src/utils/zod.ts index 8821bb80d5..f4510fb74e 100644 --- a/packages/api/src/utils/zod.ts +++ b/packages/api/src/utils/zod.ts @@ -1220,7 +1220,6 @@ const alertBaseSchema = z.object({ name: z.string().min(1).max(512).nullish(), message: z.string().min(1).max(4096).nullish(), note: alertNoteSchema, - titleEmoji: z.boolean().nullish(), displayName: alertDisplayNameSchema, tags: alertTagsSchema, numConsecutiveWindows: z.number().int().min(1).nullish(), @@ -1277,6 +1276,7 @@ const baseWebhookSchema = { name: z.string(), url: z.string().optional(), description: z.string().optional(), + titleEmoji: z.boolean().optional(), updatedAt: z.string(), createdAt: z.string(), }; @@ -1380,6 +1380,7 @@ export const externalWebhookCreateSchema = z service: z.nativeEnum(WebhookService), url: z.string().url().max(MAX_WEBHOOK_URL_LENGTH), description: z.string().max(MAX_WEBHOOK_DESCRIPTION_LENGTH).optional(), + titleEmoji: z.boolean().optional(), queryParams: z .record(webhookQueryParamKeySchema, webhookQueryParamValueSchema) .refine(m => Object.keys(m).length <= MAX_WEBHOOK_QUERY_PARAMS, { diff --git a/packages/app/src/api.ts b/packages/app/src/api.ts index 34a49630c2..5271dcfdb2 100644 --- a/packages/app/src/api.ts +++ b/packages/app/src/api.ts @@ -628,6 +628,7 @@ const api = { url: string; name: string; description: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -638,6 +639,7 @@ const api = { url, name, description, + titleEmoji, queryParams, headers, body, @@ -649,6 +651,7 @@ const api = { service, url, description, + titleEmoji, queryParams: queryParams || {}, headers: headers || {}, body, @@ -670,6 +673,7 @@ const api = { url: string; name: string; description: string; + titleEmoji?: boolean; queryParams?: Record; headers?: Record; body?: string; @@ -681,6 +685,7 @@ const api = { url, name, description, + titleEmoji, queryParams, headers, body, @@ -692,6 +697,7 @@ const api = { service, url, description, + titleEmoji, queryParams: queryParams || {}, headers: headers || {}, body, diff --git a/packages/app/src/components/TeamSettings/WebhookForm.tsx b/packages/app/src/components/TeamSettings/WebhookForm.tsx index 4aac573677..c5d609ad8d 100644 --- a/packages/app/src/components/TeamSettings/WebhookForm.tsx +++ b/packages/app/src/components/TeamSettings/WebhookForm.tsx @@ -16,6 +16,7 @@ import { isValidSlackUrl } from '@hyperdx/common-utils/dist/validation'; import { Alert, Button, + Checkbox, Code, Group, Radio, @@ -89,6 +90,7 @@ type WebhookForm = { url: string; service: WebhookService; description?: string; + titleEmoji: boolean; body?: string; headers?: string; }; @@ -114,6 +116,7 @@ export function WebhookForm({ name: webhook?.name || '', url: webhook?.url || '', description: webhook?.description || '', + titleEmoji: webhook?.titleEmoji !== false, body: webhook?.body || '', headers: webhook?.headers ? JSON.stringify(webhook.headers, null, 2) : '', }, @@ -127,6 +130,7 @@ export function WebhookForm({ name: webhook.name, url: webhook.url, description: webhook.description, + titleEmoji: webhook.titleEmoji !== false, body: webhook.body, headers: webhook.headers ? JSON.stringify(webhook.headers, null, 2) @@ -214,7 +218,8 @@ export function WebhookForm({ }; const onSubmit: SubmitHandler = async values => { - const { service, name, url, description, body, headers } = values; + const { service, name, url, description, titleEmoji, body, headers } = + values; try { // Parse headers JSON if provided (API will validate the content) @@ -246,6 +251,7 @@ export function WebhookForm({ name, url, description: description || '', + titleEmoji, body: defaultBody, headers: parsedHeaders, }; @@ -379,6 +385,11 @@ export function WebhookForm({ error={form.formState.errors.description?.message} {...form.register('description')} /> + {service === WebhookService.Generic && [