:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): send data-only and silent push notifications (#125244)
Daniel Marchuk38bed0377ac0
diff --git a/nodejs/src/cdp/schema/pushNotification.ts b/nodejs/src/cdp/schema/pushNotification.tsindex 0a85894ac2f2..440129a38de4 100644--- a/nodejs/src/cdp/schema/pushNotification.ts+++ b/nodejs/src/cdp/schema/pushNotification.ts@@ -1,8 +1,11 @@import { z } from 'zod'export const PushNotificationPayloadSchema = z.object({+ // `android_data_only` leaves the notification out on Android so the app draws it, and still shows it on iOS.+ // `silent` shows nothing on any device and only wakes the app with the data.+ delivery: z.enum(['notification', 'android_data_only', 'silent']).optional(),// Common notification fields- title: z.string(),+ title: z.string().optional(),body: z.string().optional(),image: z.string().url().optional(),data: z.record(z.string(), z.string()).optional(),diff --git a/nodejs/src/cdp/services/messaging/message-assets.service.ts b/nodejs/src/cdp/services/messaging/message-assets.service.tsindex 06b7cf8ab1d0..90e0372c9ce1 100644--- a/nodejs/src/cdp/services/messaging/message-assets.service.ts+++ b/nodejs/src/cdp/services/messaging/message-assets.service.ts@@ -91,7 +91,7 @@ const renderPushPreviewHtml = (payload: PushNotificationPayloadType): string =>`<div style="font-size:14px;line-height:1.4;color:#2d2d2d">${escapeHtml(payload.body)}</div>`: ''// nosemgrep: javascript.express.security.injection.raw-html-format.raw-html-format- return `<!doctype html><meta charset="utf-8"><div style="font-family:ui-sans-serif,system-ui,-apple-system,sans-serif;padding:1rem;max-width:420px;margin:1rem auto"><div style="background:#f4f4f5;border-radius:14px;padding:12px 14px"><div style="font-size:15px;font-weight:600;color:#111;margin-bottom:2px">${escapeHtml(payload.title)}</div>${subtitle}${body}${image}</div></div>`+ return `<!doctype html><meta charset="utf-8"><div style="font-family:ui-sans-serif,system-ui,-apple-system,sans-serif;padding:1rem;max-width:420px;margin:1rem auto"><div style="background:#f4f4f5;border-radius:14px;padding:12px 14px"><div style="font-size:15px;font-weight:600;color:#111;margin-bottom:2px">${escapeHtml(payload.title ?? '')}</div>${subtitle}${body}${image}</div></div>`}const oversizedPlaceholderHtml = (bytes: number): string => {@@ -191,6 +191,9 @@ export class MessageAssetsService {return null}const payload = params.payload+ if (payload?.delivery === 'silent') {+ return null+ }// Same rule as the email row: drop only when there is no content to show. A title-less push// still delivered something the recipient saw, so a body alone is worth capturing.if (!payload?.title && !payload?.body) {@@ -216,7 +219,7 @@ export class MessageAssetsService {recipient: recipient.distinctId,// Like a sensitive email's subject, the unrendered title still names the notification without// the values it carried.- subject: sensitive ? sensitivePushTitle(invocation) : payload.title,+ subject: sensitive ? sensitivePushTitle(invocation) : (payload.title ?? ''),status: 'sent',sent_at: isoMicroseconds(new Date()),version: microsecondsSinceEpoch(),diff --git a/nodejs/src/cdp/services/messaging/push-notification.service.test.ts b/nodejs/src/cdp/services/messaging/push-notification.service.test.tsindex 5f2494469569..b583bef614fa 100644--- a/nodejs/src/cdp/services/messaging/push-notification.service.test.ts+++ b/nodejs/src/cdp/services/messaging/push-notification.service.test.ts@@ -338,15 +338,23 @@ describe('PushNotificationService', () => {status: 200,tokens: { '$device_push_subscription_test-project': 'device-token-123' },captured: 'sent',+ delivery: undefined as string | undefined,},{ outcome: 'reached no device', status: 200, tokens: {}, captured: 'nothing' },+ {+ outcome: 'was silent',+ status: 200,+ tokens: { '$device_push_subscription_test-project': 'device-token-123' },+ captured: 'nothing',+ delivery: 'silent',+ },{outcome: 'failed terminally',status: 400,tokens: { '$device_push_subscription_test-project': 'device-token-123' },captured: 'nothing',},- ])('captures a push that $outcome as $captured', async ({ status, tokens, captured }) => {+ ])('captures a push that $outcome as $captured', async ({ status, tokens, captured, delivery }) => {respondWith(status)const invocation = createSendPushNotificationInvocation(Object.fromEntries(@@ -354,6 +362,9 @@ describe('PushNotificationService', () => {))invocation.state.actionId = 'action_push_1'+ if (delivery) {+ ;(invocation.queueParameters as any).payload = { delivery, data: { k: 'v' } }+ }const result = await serviceWithAssets.executeSendPushNotification(invocation)@@ -602,6 +613,59 @@ describe('PushNotificationService', () => {expect(body.message.apns.payload.aps.alert).toEqual({ title: 'T', body: 'B', subtitle: 'Sub' })})+ it.each([+ {+ delivery: 'android_data_only',+ notification: undefined,+ aps: { alert: { title: 'T', body: 'B' }, 'mutable-content': 1 },+ apnsHeaders: undefined,+ },+ {+ delivery: 'silent',+ notification: undefined,+ aps: { 'content-available': 1 },+ apnsHeaders: { 'apns-push-type': 'background', 'apns-priority': '5' },+ },+ {+ delivery: undefined,+ notification: { title: 'T', body: 'B', image: 'https://example.com/i.png' },+ aps: undefined,+ apnsHeaders: undefined,+ },+ ])('builds the FCM message for delivery $delivery', async ({ delivery, notification, aps, apnsHeaders }) => {+ const invocation = createSendPushNotificationInvocation({+ '$device_push_subscription_test-project': encryptedFields.encrypt('fcm-token'),+ })+ invocation.queueParameters = {+ ...invocation.queueParameters,+ payload: {+ delivery,+ title: 'T',+ body: 'B',+ image: 'https://example.com/i.png',+ data: { chat_id: 'c1' },+ android: { priority: 'high', tag: 'chat-c1' },+ },+ } as any+ mockTrackedFetch.mockResolvedValue({+ fetchError: null,+ fetchResponse: { status: 200, text: () => Promise.resolve(''), dump: () => Promise.resolve() },+ fetchDuration: 10,+ })++ await service.executeSendPushNotification(invocation)++ const { message } = parseJSON(mockTrackedFetch.mock.calls[0][0].fetchParams.body)+ expect(message.notification).toEqual(notification)+ // Android draws a notification from `android.notification` too, so data-only must drop it.+ expect(message.android).toEqual(+ delivery ? { priority: 'HIGH' } : { priority: 'HIGH', notification: { tag: 'chat-c1' } }+ )+ expect(message.data.chat_id).toBe('c1')+ expect(message.apns?.payload.aps).toEqual(aps)+ expect(message.apns?.headers).toEqual(apnsHeaders)+ })+it('returns error when integration not found', async () => {const invocation = createSendPushNotificationInvocation({'$device_push_subscription_test-project': encryptedFields.encrypt('device-token-123'),@@ -831,6 +895,34 @@ describe('PushNotificationService', () => {})})+ it('sends a silent push as a background push with no alert, sound or badge', async () => {+ const invocation = createSendPushNotificationInvocation({+ '$device_push_subscription_com.example.app': encryptedFields.encrypt('apns-device-token'),+ })+ invocation.queueParameters = {+ ...invocation.queueParameters,+ payload: {+ delivery: 'silent',+ data: { challenge_id: 'ch1' },+ apns: { sound: 'default', badge: 3, interruptionLevel: 'time-sensitive' },+ },+ } as any+ mockTrackedFetch.mockResolvedValue({+ fetchError: null,+ fetchResponse: { status: 200, text: () => Promise.resolve(''), dump: () => Promise.resolve() },+ fetchDuration: 10,+ })++ const result = await service.executeSendPushNotification(invocation)++ expect(result.metrics).toContainEqual(expect.objectContaining({ metric_name: 'push_sent', count: 1 }))+ const { headers, body } = mockTrackedFetch.mock.calls[0][0].fetchParams+ expect(headers).toMatchObject({ 'apns-push-type': 'background', 'apns-priority': '5' })+ const sent = parseJSON(body)+ expect(sent.aps).toEqual({ 'content-available': 1 })+ expect(sent.challenge_id).toBe('ch1')+ })+it('reuses a cached APNS provider token across sends instead of minting one each time', async () => {const send = (): Promise<any> =>service.executeSendPushNotification(diff --git a/nodejs/src/cdp/services/messaging/push-notification.service.ts b/nodejs/src/cdp/services/messaging/push-notification.service.tsindex e00dbb87d23c..cdda823f2952 100644--- a/nodejs/src/cdp/services/messaging/push-notification.service.ts+++ b/nodejs/src/cdp/services/messaging/push-notification.service.ts@@ -833,10 +833,11 @@ export class PushNotificationService {addLog: ReturnType<typeof createAddLogFunction>): Promise<{ sent: boolean; unregistered?: boolean; message?: string; error?: PushSendError }> {const payload = params.payload+ const silent = payload.delivery === 'silent'const headers: Record<string, string> = {Authorization: `bearer ${apns.jwt}`,'apns-topic': apns.bundleId,- 'apns-push-type': 'alert',+ 'apns-push-type': silent ? 'background' : 'alert',}if (payload.collapseKey) {headers['apns-collapse-id'] = payload.collapseKey@@ -844,7 +845,10 @@ export class PushNotificationService {if (payload.ttlSeconds !== undefined) {headers['apns-expiration'] = String(Math.floor(Date.now() / 1000) + payload.ttlSeconds)}- if (payload.apns?.interruptionLevel) {+ if (silent) {+ // APNs rejects a background push sent at priority 10.+ headers['apns-priority'] = '5'+ } else if (payload.apns?.interruptionLevel) {headers['apns-priority'] = payload.apns.interruptionLevel === 'passive' ? '5' : '10'}@@ -1103,7 +1107,11 @@ export class PushNotificationService {}private buildApnsPayload(payload: PushNotificationPayloadType): Record<string, unknown> {- const alert: Record<string, unknown> = { title: payload.title }+ if (payload.delivery === 'silent') {+ // Apple drops a background push whose `aps` carries anything the user would see or hear.+ return { ...(payload.data ?? {}), aps: { 'content-available': 1 } }+ }+ const alert: Record<string, unknown> = { title: payload.title ?? '' }if (payload.body) {alert.body = payload.body}@@ -1198,17 +1206,20 @@ export class PushNotificationService {}private buildFcmMessage(token: string, payload: PushNotificationPayloadType): Record<string, unknown> {- const notification: Record<string, string> = { title: payload.title }- if (payload.body) {- notification.body = payload.body- }- if (payload.image) {- notification.image = payload.image- }-- const message: Record<string, unknown> = {- token,- notification,+ const delivery = payload.delivery ?? 'notification'+ const message: Record<string, unknown> = { token }++ // Without a notification block Android hands the message to the app's own handler, even in the+ // background, instead of drawing it itself.+ if (delivery === 'notification') {+ const notification: Record<string, string> = { title: payload.title ?? '' }+ if (payload.body) {+ notification.body = payload.body+ }+ if (payload.image) {+ notification.image = payload.image+ }+ message.notification = notification}if (payload.data) {@@ -1247,52 +1258,68 @@ export class PushNotificationService {if (payload.android.clickAction) {androidNotification.click_action = payload.android.clickAction}- if (Object.keys(androidNotification).length > 0) {+ if (delivery === 'notification' && Object.keys(androidNotification).length > 0) {android.notification = androidNotification}}message.android = android}- // APNS overrides (for iOS devices via FCM)- if (payload.apns) {+ if (delivery === 'silent') {+ const headers: Record<string, string> = { 'apns-push-type': 'background', 'apns-priority': '5' }+ if (payload.collapseKey) {+ headers['apns-collapse-id'] = payload.collapseKey+ }+ if (payload.ttlSeconds !== undefined) {+ headers['apns-expiration'] = String(Math.floor(Date.now() / 1000) + payload.ttlSeconds)+ }+ message.apns = { headers, payload: { aps: { 'content-available': 1 } } }+ return { message }+ }++ // APNS overrides (for iOS devices via FCM). Android data-only still shows the notification on iOS,+ // and with no notification block to build it from the alert has to be spelled out here.+ if (payload.apns || delivery === 'android_data_only') {+ const apnsOverrides = payload.apns ?? {}const aps: Record<string, unknown> = {}- if (payload.apns.sound) {- aps.sound = payload.apns.sound+ if (apnsOverrides.sound) {+ aps.sound = apnsOverrides.sound}- if (payload.apns.badge !== undefined) {- aps.badge = payload.apns.badge+ if (apnsOverrides.badge !== undefined) {+ aps.badge = apnsOverrides.badge}- if (payload.apns.category) {- aps.category = payload.apns.category+ if (apnsOverrides.category) {+ aps.category = apnsOverrides.category}- if (payload.apns.threadId) {- aps['thread-id'] = payload.apns.threadId+ if (apnsOverrides.threadId) {+ aps['thread-id'] = apnsOverrides.threadId}- if (payload.apns.interruptionLevel) {- aps['interruption-level'] = payload.apns.interruptionLevel+ if (apnsOverrides.interruptionLevel) {+ aps['interruption-level'] = apnsOverrides.interruptionLevel}- if (payload.apns.relevanceScore !== undefined) {- aps['relevance-score'] = payload.apns.relevanceScore+ if (apnsOverrides.relevanceScore !== undefined) {+ aps['relevance-score'] = apnsOverrides.relevanceScore}- if (payload.apns.subtitle) {+ if (apnsOverrides.subtitle || delivery === 'android_data_only') {// FCM's message.notification has no `subtitle`. For an iOS device delivered via FCM the// subtitle must live in the APNS alert; include title/body so overriding the alert keeps them.aps.alert = {- title: payload.title,+ title: payload.title ?? '',...(payload.body ? { body: payload.body } : {}),- subtitle: payload.apns.subtitle,+ ...(apnsOverrides.subtitle ? { subtitle: apnsOverrides.subtitle } : {}),}}- if (payload.apns.mutableContent) {+ const dataOnlyImage = delivery === 'android_data_only' ? payload.image : undefined+ if (apnsOverrides.mutableContent || dataOnlyImage) {aps['mutable-content'] = 1}- if (payload.apns.targetContentId) {- aps['target-content-id'] = payload.apns.targetContentId+ if (apnsOverrides.targetContentId) {+ aps['target-content-id'] = apnsOverrides.targetContentId}message.apns = {payload: { aps },+ ...(dataOnlyImage ? { fcm_options: { image: dataOnlyImage } } : {}),}// Set collapse ID via APNS header if collapseKey is setdiff --git a/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts b/nodejs/src/cdp/templates/_destinations/push/push.template.test.tsindex 6c09f77e9f19..476dfcfa40ef 100644--- a/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts+++ b/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts@@ -9,6 +9,42 @@ describe('push template', () => {await tester.beforeEach()})+ it.each([+ {+ delivery: undefined,+ payload: { title: 'Hi', body: 'There', image: 'https://example.com/i.png', data: { k: 'v' } },+ },+ {+ delivery: 'notification',+ payload: { title: 'Hi', body: 'There', image: 'https://example.com/i.png', data: { k: 'v' } },+ },+ {+ delivery: 'android_data_only',+ payload: {+ delivery: 'android_data_only',+ title: 'Hi',+ body: 'There',+ image: 'https://example.com/i.png',+ data: { k: 'v' },+ },+ },+ { delivery: 'silent', payload: { delivery: 'silent', data: { k: 'v' } } },+ ])('builds the payload for delivery $delivery', async ({ delivery, payload }) => {+ const response = await tester.invoke({+ distinctId: 'user-1',+ channels: [{ $integration_id: 1 }],+ delivery,+ title: 'Hi',+ body: 'There',+ image: 'https://example.com/i.png',+ data: { k: 'v' },+ })++ expect(response.error).toBeUndefined()+ expect(response.invocation.queueParameters).toMatchObject({ type: 'sendPushNotification', payload })+ expect((response.invocation.queueParameters as any).payload).toEqual(payload)+ })+it.each([['nothing set', {}, undefined, undefined],[diff --git a/nodejs/src/cdp/templates/_destinations/push/push.template.ts b/nodejs/src/cdp/templates/_destinations/push/push.template.tsindex 0c5bb65cec10..5e02ee691786 100644--- a/nodejs/src/cdp/templates/_destinations/push/push.template.ts+++ b/nodejs/src/cdp/templates/_destinations/push/push.template.ts@@ -11,13 +11,15 @@ export const template: HogFunctionTemplate = {category: ['Communication'],code_language: 'hog',code: `-let payload := {- 'title': inputs.title,- 'body': inputs.body-}--if (inputs.image) payload.image := inputs.image+let delivery := inputs.delivery ?? 'notification'+let payload := {}+if (delivery != 'notification') payload.delivery := delivery+if (delivery != 'silent') {+ payload.title := inputs.title ?? ''+ payload.body := inputs.body+ if (inputs.image) payload.image := inputs.image+}// The link and group travel as data so an app that draws its own notifications can read them too.let data := inputs.data ?? {}if (inputs.link) data.link := inputs.link@@ -88,13 +90,28 @@ if (not res.success) {description:'Which channels to send through. Each recipient gets the notification on the device they registered.',},+ {+ key: 'delivery',+ type: 'choice',+ label: 'Delivery',+ choices: [+ { value: 'notification', label: 'Show a notification' },+ { value: 'android_data_only', label: 'Data only on Android, notification on iOS' },+ { value: 'silent', label: 'Silent, show nothing' },+ ],+ secret: false,+ required: false,+ description:+ "Data only and silent pushes go to your app's code instead of the system tray. Put what the app needs in the custom data.",+ default: 'notification',+ },{key: 'title',type: 'string',label: 'Notification title',secret: false,- required: true,- description: 'The title of the push notification.',+ required: false,+ description: 'The title of the push notification. Not used when the push is silent.',default: 'Notification from {event.event}',},{diff --git a/nodejs/tests/fixtures/hog-bytecode/1ca1b5957e53f21fb10a26738da58c2825f2267d4b287e6e67a6a39131f36ded.json b/nodejs/tests/fixtures/hog-bytecode/1ca1b5957e53f21fb10a26738da58c2825f2267d4b287e6e67a6a39131f36ded.jsonnew file mode 100644index 000000000000..0336607b5e11--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/1ca1b5957e53f21fb10a26738da58c2825f2267d4b287e6e67a6a39131f36ded.json@@ -0,0 +1 @@+["_H",1,32,"silent",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/39fb9c323343a57cf07bc0086eec504dcf2c3a4aa596e0150b9be4375347a065.json b/nodejs/tests/fixtures/hog-bytecode/39fb9c323343a57cf07bc0086eec504dcf2c3a4aa596e0150b9be4375347a065.jsonnew file mode 100644index 000000000000..647536c5eb6a--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/39fb9c323343a57cf07bc0086eec504dcf2c3a4aa596e0150b9be4375347a065.json@@ -0,0 +1 @@+["_H",1,32,"delivery",32,"inputs",1,2,47,3,35,32,"notification",42,0,32,"notification",36,0,12,40,7,36,1,32,"delivery",36,0,46,32,"silent",36,0,12,40,46,36,1,32,"title",32,"title",32,"inputs",1,2,47,3,35,32,"",46,36,1,32,"body",32,"body",32,"inputs",1,2,46,32,"image",32,"inputs",1,2,40,11,36,1,32,"image",32,"image",32,"inputs",1,2,46,32,"data",32,"inputs",1,2,40,11,36,1,32,"data",32,"data",32,"inputs",1,2,46,32,"collapseKey",32,"inputs",1,2,40,11,36,1,32,"collapseKey",32,"collapseKey",32,"inputs",1,2,46,32,"ttlSeconds",32,"inputs",1,2,40,11,36,1,32,"ttlSeconds",32,"ttlSeconds",32,"inputs",1,2,46,42,0,32,"android_priority",32,"inputs",1,2,40,11,36,2,32,"priority",32,"android_priority",32,"inputs",1,2,46,32,"android_channelId",32,"inputs",1,2,40,11,36,2,32,"channelId",32,"android_channelId",32,"inputs",1,2,46,32,"android_sound",32,"inputs",1,2,40,11,36,2,32,"sound",32,"android_sound",32,"inputs",1,2,46,32,"android_tag",32,"inputs",1,2,40,11,36,2,32,"tag",32,"android_tag",32,"inputs",1,2,46,32,"android_icon",32,"inputs",1,2,40,11,36,2,32,"icon",32,"android_icon",32,"inputs",1,2,46,32,"android_color",32,"inputs",1,2,40,11,36,2,32,"color",32,"android_color",32,"inputs",1,2,46,32,"android_clickAction",32,"inputs",1,2,40,11,36,2,32,"clickAction",32,"android_clickAction",32,"inputs",1,2,46,33,0,36,2,2,"keys",1,2,"length",1,13,40,7,36,1,32,"android",36,2,46,42,0,32,"ios_sound",32,"inputs",1,2,40,11,36,3,32,"sound",32,"ios_sound",32,"inputs",1,2,46,31,32,"ios_badge",32,"inputs",1,2,12,40,11,36,3,32,"badge",32,"ios_badge",32,"inputs",1,2,46,32,"ios_category",32,"inputs",1,2,40,11,36,3,32,"category",32,"ios_category",32,"inputs",1,2,46,32,"ios_threadId",32,"inputs",1,2,40,11,36,3,32,"threadId",32,"ios_threadId",32,"inputs",1,2,46,32,"ios_interruptionLevel",32,"inputs",1,2,40,11,36,3,32,"interruptionLevel",32,"ios_interruptionLevel",32,"inputs",1,2,46,32,"ios_subtitle",32,"inputs",1,2,40,11,36,3,32,"subtitle",32,"ios_subtitle",32,"inputs",1,2,46,32,"ios_mutableContent",32,"inputs",1,2,40,11,36,3,32,"mutableContent",32,"ios_mutableContent",32,"inputs",1,2,46,33,0,36,3,2,"keys",1,2,"length",1,13,40,7,36,1,32,"apns",36,3,46,32,"channels",32,"inputs",1,2,5,33,0,32,"channels",32,"inputs",1,2,2,"length",1,11,4,2,40,6,32,"No push channel configured. Select at least one channel.",2,"Error",1,49,32,"integrationIds",52,"lambda",1,0,6,36,0,32,"$integration_id",45,38,53,0,32,"channels",32,"inputs",1,2,2,"arrayMap",2,32,"distinctId",32,"distinctId",32,"inputs",1,2,32,"payload",36,1,42,3,2,"sendPushNotification",1,36,4,32,"success",45,5,40,14,32,"Failed to send push notification: ",36,4,32,"error",45,2,"concat",2,2,"Error",1,49,35,35,35,35,35]diff --git a/nodejs/tests/fixtures/hog-bytecode/3bbb101bb13877df2f42807b2f35b0d8fd0a53846c14b7efbf011e2cc588f997.json b/nodejs/tests/fixtures/hog-bytecode/3bbb101bb13877df2f42807b2f35b0d8fd0a53846c14b7efbf011e2cc588f997.jsonnew file mode 100644index 000000000000..93e4fe76dd5e--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/3bbb101bb13877df2f42807b2f35b0d8fd0a53846c14b7efbf011e2cc588f997.json@@ -0,0 +1 @@+["_H",1,32,"delivery",32,"inputs",1,2,47,3,35,32,"notification",42,0,32,"notification",36,0,12,40,7,36,1,32,"delivery",36,0,46,32,"silent",36,0,12,40,46,36,1,32,"title",32,"title",32,"inputs",1,2,47,3,35,32,"",46,36,1,32,"body",32,"body",32,"inputs",1,2,46,32,"image",32,"inputs",1,2,40,11,36,1,32,"image",32,"image",32,"inputs",1,2,46,32,"data",32,"inputs",1,2,47,3,35,42,0,32,"link",32,"inputs",1,2,40,11,36,2,32,"link",32,"link",32,"inputs",1,2,46,32,"group",32,"inputs",1,2,40,11,36,2,32,"group",32,"group",32,"inputs",1,2,46,33,0,36,2,2,"keys",1,2,"length",1,13,40,7,36,1,32,"data",36,2,46,32,"collapseKey",32,"inputs",1,2,40,11,36,1,32,"collapseKey",32,"collapseKey",32,"inputs",1,2,46,32,"ttlSeconds",32,"inputs",1,2,40,11,36,1,32,"ttlSeconds",32,"ttlSeconds",32,"inputs",1,2,46,42,0,32,"android_priority",32,"inputs",1,2,40,11,36,3,32,"priority",32,"android_priority",32,"inputs",1,2,46,32,"android_channelId",32,"inputs",1,2,40,11,36,3,32,"channelId",32,"android_channelId",32,"inputs",1,2,46,32,"android_sound",32,"inputs",1,2,40,11,36,3,32,"sound",32,"android_sound",32,"inputs",1,2,46,32,"android_tag",32,"inputs",1,2,40,11,36,3,32,"tag",32,"android_tag",32,"inputs",1,2,46,32,"android_icon",32,"inputs",1,2,40,11,36,3,32,"icon",32,"android_icon",32,"inputs",1,2,46,32,"android_color",32,"inputs",1,2,40,11,36,3,32,"color",32,"android_color",32,"inputs",1,2,46,32,"android_clickAction",32,"inputs",1,2,40,11,36,3,32,"clickAction",32,"android_clickAction",32,"inputs",1,2,46,33,0,36,3,2,"keys",1,2,"length",1,13,40,7,36,1,32,"android",36,3,46,42,0,32,"ios_sound",32,"inputs",1,2,40,11,36,4,32,"sound",32,"ios_sound",32,"inputs",1,2,46,31,32,"ios_badge",32,"inputs",1,2,12,40,11,36,4,32,"badge",32,"ios_badge",32,"inputs",1,2,46,32,"ios_category",32,"inputs",1,2,40,11,36,4,32,"category",32,"ios_category",32,"inputs",1,2,46,32,"ios_threadId",32,"inputs",1,2,40,13,36,4,32,"threadId",32,"ios_threadId",32,"inputs",1,2,46,39,19,32,"group",32,"inputs",1,2,40,11,36,4,32,"threadId",32,"group",32,"inputs",1,2,46,32,"ios_interruptionLevel",32,"inputs",1,2,40,11,36,4,32,"interruptionLevel",32,"ios_interruptionLevel",32,"inputs",1,2,46,32,"ios_subtitle",32,"inputs",1,2,40,11,36,4,32,"subtitle",32,"ios_subtitle",32,"inputs",1,2,46,32,"ios_mutableContent",32,"inputs",1,2,40,11,36,4,32,"mutableContent",32,"ios_mutableContent",32,"inputs",1,2,46,33,0,36,4,2,"keys",1,2,"length",1,13,40,7,36,1,32,"apns",36,4,46,32,"channels",32,"inputs",1,2,5,33,0,32,"channels",32,"inputs",1,2,2,"length",1,11,4,2,40,6,32,"No push channel configured. Select at least one channel.",2,"Error",1,49,32,"integrationIds",52,"lambda",1,0,6,36,0,32,"$integration_id",45,38,53,0,32,"channels",32,"inputs",1,2,2,"arrayMap",2,32,"distinctId",32,"distinctId",32,"inputs",1,2,32,"payload",36,1,42,3,2,"sendPushNotification",1,36,5,32,"success",45,5,40,14,32,"Failed to send push notification: ",36,5,32,"error",45,2,"concat",2,2,"Error",1,49,35,35,35,35,35,35]diff --git a/nodejs/tests/fixtures/hog-bytecode/4e0551ca0344c628dd853a8f46b89634a7c19f91470349a347818f0e14321cef.json b/nodejs/tests/fixtures/hog-bytecode/4e0551ca0344c628dd853a8f46b89634a7c19f91470349a347818f0e14321cef.jsonnew file mode 100644index 000000000000..fa28ee59b787--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/4e0551ca0344c628dd853a8f46b89634a7c19f91470349a347818f0e14321cef.json@@ -0,0 +1 @@+["_H",1,32,"user-1",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/6605c672448a904c5762d4c8ec57a3ee8205b9b9d27ab9178695707ead7820ec.json b/nodejs/tests/fixtures/hog-bytecode/6605c672448a904c5762d4c8ec57a3ee8205b9b9d27ab9178695707ead7820ec.jsonnew file mode 100644index 000000000000..5469015d6619--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/6605c672448a904c5762d4c8ec57a3ee8205b9b9d27ab9178695707ead7820ec.json@@ -0,0 +1 @@+["_H",1,32,"There",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/6a0bbdc79a44360bb6311c629a40e6d21c0d84eff495905eb3cef585578d1eb5.json b/nodejs/tests/fixtures/hog-bytecode/6a0bbdc79a44360bb6311c629a40e6d21c0d84eff495905eb3cef585578d1eb5.jsonnew file mode 100644index 000000000000..cf25d43d0ddf--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/6a0bbdc79a44360bb6311c629a40e6d21c0d84eff495905eb3cef585578d1eb5.json@@ -0,0 +1 @@+["_H",1,32,"notification",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/79c78c94a847dc44fe6b61d914d3a3fb6e40e659b4e9eeb73d701f98269bd69b.json b/nodejs/tests/fixtures/hog-bytecode/79c78c94a847dc44fe6b61d914d3a3fb6e40e659b4e9eeb73d701f98269bd69b.jsonnew file mode 100644index 000000000000..c3c7603fd80d--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/79c78c94a847dc44fe6b61d914d3a3fb6e40e659b4e9eeb73d701f98269bd69b.json@@ -0,0 +1 @@+["_H",1,32,"Hi",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/8fb5f11f0da651ca99d8819563e20b3ababeb5573386f2ff561ef63343788733.json b/nodejs/tests/fixtures/hog-bytecode/8fb5f11f0da651ca99d8819563e20b3ababeb5573386f2ff561ef63343788733.jsonnew file mode 100644index 000000000000..acba02f07a10--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/8fb5f11f0da651ca99d8819563e20b3ababeb5573386f2ff561ef63343788733.json@@ -0,0 +1 @@+["_H",1,32,"https://example.com/i.png",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/c43783e46c2f30a6868d93a8e2cfa27c1c010a15299c0278f390844b9f245c01.json b/nodejs/tests/fixtures/hog-bytecode/c43783e46c2f30a6868d93a8e2cfa27c1c010a15299c0278f390844b9f245c01.jsonnew file mode 100644index 000000000000..647536c5eb6a--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/c43783e46c2f30a6868d93a8e2cfa27c1c010a15299c0278f390844b9f245c01.json@@ -0,0 +1 @@+["_H",1,32,"delivery",32,"inputs",1,2,47,3,35,32,"notification",42,0,32,"notification",36,0,12,40,7,36,1,32,"delivery",36,0,46,32,"silent",36,0,12,40,46,36,1,32,"title",32,"title",32,"inputs",1,2,47,3,35,32,"",46,36,1,32,"body",32,"body",32,"inputs",1,2,46,32,"image",32,"inputs",1,2,40,11,36,1,32,"image",32,"image",32,"inputs",1,2,46,32,"data",32,"inputs",1,2,40,11,36,1,32,"data",32,"data",32,"inputs",1,2,46,32,"collapseKey",32,"inputs",1,2,40,11,36,1,32,"collapseKey",32,"collapseKey",32,"inputs",1,2,46,32,"ttlSeconds",32,"inputs",1,2,40,11,36,1,32,"ttlSeconds",32,"ttlSeconds",32,"inputs",1,2,46,42,0,32,"android_priority",32,"inputs",1,2,40,11,36,2,32,"priority",32,"android_priority",32,"inputs",1,2,46,32,"android_channelId",32,"inputs",1,2,40,11,36,2,32,"channelId",32,"android_channelId",32,"inputs",1,2,46,32,"android_sound",32,"inputs",1,2,40,11,36,2,32,"sound",32,"android_sound",32,"inputs",1,2,46,32,"android_tag",32,"inputs",1,2,40,11,36,2,32,"tag",32,"android_tag",32,"inputs",1,2,46,32,"android_icon",32,"inputs",1,2,40,11,36,2,32,"icon",32,"android_icon",32,"inputs",1,2,46,32,"android_color",32,"inputs",1,2,40,11,36,2,32,"color",32,"android_color",32,"inputs",1,2,46,32,"android_clickAction",32,"inputs",1,2,40,11,36,2,32,"clickAction",32,"android_clickAction",32,"inputs",1,2,46,33,0,36,2,2,"keys",1,2,"length",1,13,40,7,36,1,32,"android",36,2,46,42,0,32,"ios_sound",32,"inputs",1,2,40,11,36,3,32,"sound",32,"ios_sound",32,"inputs",1,2,46,31,32,"ios_badge",32,"inputs",1,2,12,40,11,36,3,32,"badge",32,"ios_badge",32,"inputs",1,2,46,32,"ios_category",32,"inputs",1,2,40,11,36,3,32,"category",32,"ios_category",32,"inputs",1,2,46,32,"ios_threadId",32,"inputs",1,2,40,11,36,3,32,"threadId",32,"ios_threadId",32,"inputs",1,2,46,32,"ios_interruptionLevel",32,"inputs",1,2,40,11,36,3,32,"interruptionLevel",32,"ios_interruptionLevel",32,"inputs",1,2,46,32,"ios_subtitle",32,"inputs",1,2,40,11,36,3,32,"subtitle",32,"ios_subtitle",32,"inputs",1,2,46,32,"ios_mutableContent",32,"inputs",1,2,40,11,36,3,32,"mutableContent",32,"ios_mutableContent",32,"inputs",1,2,46,33,0,36,3,2,"keys",1,2,"length",1,13,40,7,36,1,32,"apns",36,3,46,32,"channels",32,"inputs",1,2,5,33,0,32,"channels",32,"inputs",1,2,2,"length",1,11,4,2,40,6,32,"No push channel configured. Select at least one channel.",2,"Error",1,49,32,"integrationIds",52,"lambda",1,0,6,36,0,32,"$integration_id",45,38,53,0,32,"channels",32,"inputs",1,2,2,"arrayMap",2,32,"distinctId",32,"distinctId",32,"inputs",1,2,32,"payload",36,1,42,3,2,"sendPushNotification",1,36,4,32,"success",45,5,40,14,32,"Failed to send push notification: ",36,4,32,"error",45,2,"concat",2,2,"Error",1,49,35,35,35,35,35]diff --git a/nodejs/tests/fixtures/hog-bytecode/c95cb5a23644e2a0251c402649f7ba0a2b47421d32692e8f4e9c68f83d62e0b9.json b/nodejs/tests/fixtures/hog-bytecode/c95cb5a23644e2a0251c402649f7ba0a2b47421d32692e8f4e9c68f83d62e0b9.jsonnew file mode 100644index 000000000000..5c042e98925c--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/c95cb5a23644e2a0251c402649f7ba0a2b47421d32692e8f4e9c68f83d62e0b9.json@@ -0,0 +1 @@+["_H",1,32,"android_data_only",38]diff --git a/nodejs/tests/fixtures/hog-bytecode/cbefa7ad3a88f1dab31cff0685f9561c488e34a7d3339250e7538ea68f716ac6.json b/nodejs/tests/fixtures/hog-bytecode/cbefa7ad3a88f1dab31cff0685f9561c488e34a7d3339250e7538ea68f716ac6.jsonnew file mode 100644index 000000000000..3a06623aae74--- /dev/null+++ b/nodejs/tests/fixtures/hog-bytecode/cbefa7ad3a88f1dab31cff0685f9561c488e34a7d3339250e7538ea68f716ac6.json@@ -0,0 +1 @@+["_H",1,32,"v",38]diff --git a/products/workflows/backend/presentation/views/hog_flow.py b/products/workflows/backend/presentation/views/hog_flow.pyindex 7829b45d4ecb..33c404fd8a00 100644--- a/products/workflows/backend/presentation/views/hog_flow.py+++ b/products/workflows/backend/presentation/views/hog_flow.py@@ -673,6 +673,33 @@ _REPLAY_VISION_STEP_SCOPES = ()+def _fill_default_push_title(inputs: Any, input_schema: list[dict[str, Any]] | None) -> None:+ # The title stopped being required so silent pushes can omit it, and the inputs serializer only fills defaults+ # for required inputs. API callers that leave it out of a visible push still get the template's default title.+ if not isinstance(inputs, dict) or "title" in inputs:+ return+ delivery = inputs.get("delivery")+ if isinstance(delivery, dict) and delivery.get("value") == "silent":+ return+ default = next((schema.get("default") for schema in input_schema or [] if schema.get("key") == "title"), None)+ if default is not None:+ inputs["title"] = {"value": default}+++def _validate_push_action(inputs: Any) -> None:+ if not isinstance(inputs, dict):+ return++ def value(key: str) -> Any:+ entry = inputs.get(key)+ return entry.get("value") if isinstance(entry, dict) else None++ delivery = value("delivery") or "notification"+ title = value("title")+ if delivery != "silent" and not (isinstance(title, str) and title.strip()):+ raise serializers.ValidationError({"inputs": {"title": "Add a notification title."}})++def _strip_replay_vision_code(inputs: Any) -> None:# A draft keeps its raw inputs when they fail validation, so client-compiled code or a Liquid template can still# be there. The engine would render those instead of the literal value the access checks read.@@ -2157,6 +2184,8 @@ class HogFlowActionSerializer(serializers.Serializer):else:input_schema = template.inputs_schemainputs = data.get("config", {}).get("inputs", {})+ if template_id == _FIXED_TEMPLATE_IDS["function_push"]:+ _fill_default_push_title(inputs, input_schema)function_config_serializer = HogFlowConfigFunctionInputsSerializer(data={@@ -2206,6 +2235,8 @@ class HogFlowActionSerializer(serializers.Serializer):self._validate_run_scout_action()if strict and template_id == _CLASSIFY_TEMPLATE_ID:self._validate_classify_action(data["config"]["inputs"])+ if strict and template_id == _FIXED_TEMPLATE_IDS["function_push"]:+ _validate_push_action(data["config"]["inputs"])if template_id == _REPLAY_VISION_TEMPLATE_ID:self._validate_replay_vision_action(data["config"].get("inputs") or {}, strict=strict)if template_id == _RUN_SCOUT_TEMPLATE_ID:diff --git a/products/workflows/backend/tests/api/test_hog_flow.py b/products/workflows/backend/tests/api/test_hog_flow.pyindex ac4a0f19adc1..421539358547 100644--- a/products/workflows/backend/tests/api/test_hog_flow.py+++ b/products/workflows/backend/tests/api/test_hog_flow.py@@ -239,6 +239,47 @@ class TestHogFlowAPI(APIBaseTest):assert active.status_code == expected_status, active.json()assert draft.status_code == 201, draft.json()+ @parameterized.expand(+ [+ ("default delivery with a title", None, "Hi", 201),+ ("default delivery without a title", None, "", 400),+ ("blank title", "notification", " ", 400),+ ("android data only without a title", "android_data_only", "", 400),+ ("silent without a title", "silent", "", 201),+ ("default delivery with the title left out", None, None, 201),+ ]+ )+ def test_only_a_silent_push_may_skip_the_title(+ self, _name: str, delivery: str | None, title: str | None, expected_status: int+ ) -> None:+ template = _push_function_template()+ for schema in template["inputs_schema"]:+ if schema["key"] == "title":+ schema["required"] = False+ schema["default"] = "Notification from {event.event}"+ template["inputs_schema"].append({"key": "delivery", "type": "choice", "label": "Delivery", "required": False})+ sync_template_to_db(template)+ provider = Integration.objects.create(team=self.team, kind="firebase", config={})+ inputs: dict[str, Any] = {+ "distinctId": {"value": "{event.distinct_id}"},+ "channels": {"value": [provider.id]},+ }+ if title is not None:+ inputs["title"] = {"value": title}+ if delivery is not None:+ inputs["delivery"] = {"value": delivery}+ hog_flow, _ = self._create_hog_flow_with_action({"template_id": "template-native-push", "inputs": inputs})+ hog_flow["actions"][1]["type"] = "function_push"++ active = self.client.post(f"/api/projects/{self.team.id}/hog_flows", {**hog_flow, "status": "active"})+ draft = self.client.post(f"/api/projects/{self.team.id}/hog_flows", {**hog_flow, "status": "draft"})++ assert active.status_code == expected_status, active.json()+ assert draft.status_code == 201, draft.json()+ if title is None:+ saved_title = active.json()["actions"][1]["config"]["inputs"]["title"]["value"]+ assert saved_title == "Notification from {event.event}"+@patch("products.workflows.backend.presentation.views.hog_flow.publish_resource_edited")def test_emits_resource_edited_on_create_and_update(self, mock_emit):hog_flow, _ = self._create_hog_flow_with_action(diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsxindex 7cb2788dbe9c..86c25fff7192 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowFunctionConfiguration.tsx@@ -253,9 +253,21 @@ export function HogFlowFunctionConfiguration({// fields inline and tuck the platform-specific ones into collapsed sections so the form stays flat.const inputsSchema = filterInputsSchemaForTrigger(templateId, workflow?.trigger, template.inputs_schema ?? [])const isPlatformInput = (key: string): boolean => key.startsWith('android_') || key.startsWith('ios_')- const coreInputsSchema = isPushStep ? inputsSchema.filter((s) => !isPlatformInput(s.key)) : inputsSchema- const androidInputsSchema = isPushStep ? inputsSchema.filter((s) => s.key.startsWith('android_')) : []- const iosInputsSchema = isPushStep ? inputsSchema.filter((s) => s.key.startsWith('ios_')) : []+ const isSilentPush = isPushStep && inputs?.delivery?.value === 'silent'+ const isHiddenForSilentPush = (key: string): boolean => isSilentPush && ['title', 'body', 'image'].includes(key)+ // The template leaves the title optional so a silent push can skip it. Every other push needs one.+ const coreInputsSchema = isPushStep+ ? inputsSchema+ .filter((s) => !isPlatformInput(s.key) && !isHiddenForSilentPush(s.key))+ .map((s) => (s.key === 'title' ? { ...s, required: true } : s))+ : inputsSchema+ const isAndroidDataOnly = isPushStep && ['android_data_only', 'silent'].includes(inputs?.delivery?.value)+ const androidInputsSchema = isPushStep+ ? inputsSchema.filter(+ (s) => s.key.startsWith('android_') && (!isAndroidDataOnly || s.key === 'android_priority')+ )+ : []+ const iosInputsSchema = isPushStep && !isSilentPush ? inputsSchema.filter((s) => s.key.startsWith('ios_')) : []const renderInputs = (schema: typeof inputsSchema): JSX.Element => (<CyclotronJobInputsdiff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.tsindex fb372fb92558..d843b1caeca6 100644--- a/products/workflows/frontend/Workflows/workflowLogic.ts+++ b/products/workflows/frontend/Workflows/workflowLogic.ts@@ -4068,6 +4068,14 @@ export const workflowLogic = kea<workflowLogicType>([channels: 'Select at least one channel to send this notification',}}+ const title = action.config.inputs?.title?.value+ if (+ action.config.inputs?.delivery?.value !== 'silent' &&+ !(typeof title === 'string' && title.trim())+ ) {+ result.valid = false+ result.errors = { ...result.errors, title: 'Add a notification title' }+ }}if (