From d3eac6caf83b6bdff25f218d0be761f7a390a2b3 Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:25:16 +0100 Subject: [PATCH] feat(integrations): ability to add stringified event (#6642) You might want to include entire event, but as a different field. --- src/lib/addons/webhook-definition.ts | 5 +++-- src/lib/addons/webhook.ts | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/addons/webhook-definition.ts b/src/lib/addons/webhook-definition.ts index 30438b1837..b125b8083b 100644 --- a/src/lib/addons/webhook-definition.ts +++ b/src/lib/addons/webhook-definition.ts @@ -86,10 +86,11 @@ const webhookDefinition: IAddonDefinition = { "event": "{{event.type}}", "createdBy": "{{event.createdBy}}", "featureToggle": "{{event.data.name}}", - "timestamp": "{{event.data.createdAt}}" + "timestamp": "{{event.data.createdAt}}", + "json": {{{eventJson}}} }`, description: - "(Optional) You may format the body using a mustache template. If you don't specify anything, the format will similar to the events format (https://docs.getunleash.io/reference/api/legacy/unleash/admin/events)", + "(Optional) You may format the body using a mustache template. If you don't specify anything, the format will similar to the events format (https://docs.getunleash.io/reference/api/legacy/unleash/admin/events). You can use {{{eventJson}}} to include entire serialized event.", type: 'textfield', required: false, sensitive: false, diff --git a/src/lib/addons/webhook.ts b/src/lib/addons/webhook.ts index ed0dede588..1d0e7eec89 100644 --- a/src/lib/addons/webhook.ts +++ b/src/lib/addons/webhook.ts @@ -22,6 +22,8 @@ export default class Webhook extends Addon { parameters; const context = { event, + // Stringify twice to avoid escaping in Mustache + eventJson: JSON.stringify(JSON.stringify(event)), }; let body: string | undefined;