Skip to content

: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.

feat(workflows): add link and group fields to the push step (#125240)

Daniel Marchuk49a762b7b7bc
diff --git a/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts b/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts
new file mode 100644
index 000000000000..6c09f77e9f19
--- /dev/null
+++ b/nodejs/src/cdp/templates/_destinations/push/push.template.test.ts
@@ -0,0 +1,40 @@
+import { TemplateTester } from '../../test/test-helpers'
+import { template } from './push.template'
+
+describe('push template', () => {
+ // The empty mapping_templates only clears old mappings, and the tester refuses any mapping list.
+ const tester = new TemplateTester({ ...template, mapping_templates: undefined })
+
+ beforeEach(async () => {
+ await tester.beforeEach()
+ })
+
+ it.each([
+ ['nothing set', {}, undefined, undefined],
+ [
+ 'link and group',
+ { link: 'myapp://chat/123', group: 'chat-123' },
+ { link: 'myapp://chat/123', group: 'chat-123' },
+ 'chat-123',
+ ],
+ [
+ 'the link field replaces a link key in custom data',
+ { link: 'https://example.com/a', data: { kind: 'dm', link: 'stale' } },
+ { kind: 'dm', link: 'https://example.com/a' },
+ undefined,
+ ],
+ [
+ 'iOS thread ID wins over the group',
+ { group: 'chat-123', ios_threadId: 'thread-9' },
+ { group: 'chat-123' },
+ 'thread-9',
+ ],
+ ])('%s', async (_name, inputs, expectedData, expectedThreadId) => {
+ const response = await tester.invoke({ channels: [{ $integration_id: 1 }], ...inputs })
+
+ expect(response.error).toBeUndefined()
+ const payload = (response.invocation.queueParameters as any).payload
+ expect(payload.data).toEqual(expectedData)
+ expect(payload.apns?.threadId).toEqual(expectedThreadId)
+ })
+})
diff --git a/nodejs/src/cdp/templates/_destinations/push/push.template.ts b/nodejs/src/cdp/templates/_destinations/push/push.template.ts
index 86e19645d8c4..0c5bb65cec10 100644
--- a/nodejs/src/cdp/templates/_destinations/push/push.template.ts
+++ b/nodejs/src/cdp/templates/_destinations/push/push.template.ts
@@ -17,7 +17,12 @@ let payload := {
}
if (inputs.image) payload.image := inputs.image
-if (inputs.data) payload.data := inputs.data
+
+// 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
+if (inputs.group) data.group := inputs.group
+if (length(keys(data)) > 0) payload.data := data
if (inputs.collapseKey) payload.collapseKey := inputs.collapseKey
if (inputs.ttlSeconds) payload.ttlSeconds := inputs.ttlSeconds
@@ -37,7 +42,11 @@ let apns := {}
if (inputs.ios_sound) apns.sound := inputs.ios_sound
if (inputs.ios_badge != null) apns.badge := inputs.ios_badge
if (inputs.ios_category) apns.category := inputs.ios_category
-if (inputs.ios_threadId) apns.threadId := inputs.ios_threadId
+if (inputs.ios_threadId) {
+ apns.threadId := inputs.ios_threadId
+} else if (inputs.group) {
+ apns.threadId := inputs.group
+}
if (inputs.ios_interruptionLevel) apns.interruptionLevel := inputs.ios_interruptionLevel
if (inputs.ios_subtitle) apns.subtitle := inputs.ios_subtitle
if (inputs.ios_mutableContent) apns.mutableContent := inputs.ios_mutableContent
@@ -106,6 +115,24 @@ if (not res.success) {
required: false,
description: 'URL of an image to display in the notification.',
},
+ {
+ key: 'link',
+ type: 'string',
+ label: 'Link',
+ secret: false,
+ required: false,
+ description:
+ 'Where a tap should take the person, such as myapp://chat/123 or a web URL. Sent to the app as the "link" key in the custom data, for the app to open.',
+ },
+ {
+ key: 'group',
+ type: 'string',
+ label: 'Group',
+ secret: false,
+ required: false,
+ description:
+ 'Notifications with the same group are bundled together, such as one conversation. Used as the iOS thread ID, and sent to the app as the "group" key in the custom data for Android.',
+ },
{
key: 'data',
type: 'json',
diff --git a/nodejs/tests/fixtures/hog-bytecode/108a94138a1116a4bca23d6b53a426d1e45a7ccfedbf18ca16d9239887406ece.json b/nodejs/tests/fixtures/hog-bytecode/108a94138a1116a4bca23d6b53a426d1e45a7ccfedbf18ca16d9239887406ece.json
new file mode 100644
index 000000000000..5541f4d75017
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/108a94138a1116a4bca23d6b53a426d1e45a7ccfedbf18ca16d9239887406ece.json
@@ -0,0 +1 @@
+["_H",1,32,"Notification from ",32,"event",32,"event",1,2,2,"concat",2,38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/113ae2805b409fb8e2c360152bc0ae3489b472494934c4723923b4e577ab2081.json b/nodejs/tests/fixtures/hog-bytecode/113ae2805b409fb8e2c360152bc0ae3489b472494934c4723923b4e577ab2081.json
new file mode 100644
index 000000000000..e349f5d4e22e
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/113ae2805b409fb8e2c360152bc0ae3489b472494934c4723923b4e577ab2081.json
@@ -0,0 +1 @@
+["_H",1,32,"stale",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/15eadf12d1c6dd457d59c7dee873bf669673a36a4004754741580463bfb87e6e.json b/nodejs/tests/fixtures/hog-bytecode/15eadf12d1c6dd457d59c7dee873bf669673a36a4004754741580463bfb87e6e.json
new file mode 100644
index 000000000000..4cae82167d2b
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/15eadf12d1c6dd457d59c7dee873bf669673a36a4004754741580463bfb87e6e.json
@@ -0,0 +1 @@
+["_H",1,32,"myapp://chat/123",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/86e0ce950f00c2bc8e1cbf33c28c3268c2086e771fc8a06607074873433a3293.json b/nodejs/tests/fixtures/hog-bytecode/86e0ce950f00c2bc8e1cbf33c28c3268c2086e771fc8a06607074873433a3293.json
new file mode 100644
index 000000000000..7e67e411ba0f
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/86e0ce950f00c2bc8e1cbf33c28c3268c2086e771fc8a06607074873433a3293.json
@@ -0,0 +1 @@
+["_H",1,32,"title",32,"title",32,"inputs",1,2,32,"body",32,"body",32,"inputs",1,2,42,2,32,"image",32,"inputs",1,2,40,11,36,0,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,1,32,"link",32,"link",32,"inputs",1,2,46,32,"group",32,"inputs",1,2,40,11,36,1,32,"group",32,"group",32,"inputs",1,2,46,33,0,36,1,2,"keys",1,2,"length",1,13,40,7,36,0,32,"data",36,1,46,32,"collapseKey",32,"inputs",1,2,40,11,36,0,32,"collapseKey",32,"collapseKey",32,"inputs",1,2,46,32,"ttlSeconds",32,"inputs",1,2,40,11,36,0,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,0,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,13,36,3,32,"threadId",32,"ios_threadId",32,"inputs",1,2,46,39,19,32,"group",32,"inputs",1,2,40,11,36,3,32,"threadId",32,"group",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,0,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,0,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/8849c0299e1718bc6c1357fb42806e55008e8845437b94bdf278ab5c4117f45c.json b/nodejs/tests/fixtures/hog-bytecode/8849c0299e1718bc6c1357fb42806e55008e8845437b94bdf278ab5c4117f45c.json
new file mode 100644
index 000000000000..071f8a43dd05
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/8849c0299e1718bc6c1357fb42806e55008e8845437b94bdf278ab5c4117f45c.json
@@ -0,0 +1 @@
+["_H",1,32,"thread-9",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/dae532b6cdebca41bbd5dedcf9df819f67abbc114a91bf0ad1875593e421507c.json b/nodejs/tests/fixtures/hog-bytecode/dae532b6cdebca41bbd5dedcf9df819f67abbc114a91bf0ad1875593e421507c.json
new file mode 100644
index 000000000000..6934645c5486
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/dae532b6cdebca41bbd5dedcf9df819f67abbc114a91bf0ad1875593e421507c.json
@@ -0,0 +1 @@
+["_H",1,32,"dm",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/f5fb1f5e8bda109f7a740cdd7256ccdf67129eced6ca525775cccf61b16a5a00.json b/nodejs/tests/fixtures/hog-bytecode/f5fb1f5e8bda109f7a740cdd7256ccdf67129eced6ca525775cccf61b16a5a00.json
new file mode 100644
index 000000000000..f00d75de07b7
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/f5fb1f5e8bda109f7a740cdd7256ccdf67129eced6ca525775cccf61b16a5a00.json
@@ -0,0 +1 @@
+["_H",1,32,"chat-123",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/faeec50448a9617902bccec6614d3d2d89610fed9695650ccd4899c3328c11b8.json b/nodejs/tests/fixtures/hog-bytecode/faeec50448a9617902bccec6614d3d2d89610fed9695650ccd4899c3328c11b8.json
new file mode 100644
index 000000000000..5ffcd1248268
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/faeec50448a9617902bccec6614d3d2d89610fed9695650ccd4899c3328c11b8.json
@@ -0,0 +1 @@
+["_H",1,32,"https://example.com/a",38]