From 3bbaf670a2d888fa245e4b2409e39aea997ca171 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sun, 24 Dec 2023 11:02:48 +0100 Subject: [PATCH] :children_crossing: (webhook) Improve header and query params parsing --- .../blocks/[blockId]/executeWebhook.ts | 16 +--------------- .../integrations/webhook/executeWebhookBlock.ts | 8 +++++--- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts index 008da50be..c5428a5ba 100644 --- a/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts +++ b/apps/viewer/src/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts @@ -1,5 +1,4 @@ import { - KeyValue, PublicTypebot, ResultValues, Typebot, @@ -28,6 +27,7 @@ import { } from '@typebot.io/schemas/features/blocks/integrations/webhook/constants' import { getBlockById } from '@typebot.io/lib/getBlockById' import { + convertKeyValueTableToObject, longReqTimeoutWhitelist, longRequestTimeout, responseDefaultTimeout, @@ -280,20 +280,6 @@ const getBodyContent = : body ?? undefined } -const convertKeyValueTableToObject = ( - keyValues: KeyValue[] | undefined, - variables: Variable[] -) => { - if (!keyValues) return - return keyValues.reduce((object, item) => { - if (!item.key) return {} - return { - ...object, - [item.key]: parseVariables(variables)(item.value ?? ''), - } - }, {}) -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any const safeJsonParse = (json: string): { data: any; isJson: boolean } => { try { diff --git a/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts b/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts index a592154cc..a91d6b057 100644 --- a/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts +++ b/packages/bot-engine/blocks/integrations/webhook/executeWebhookBlock.ts @@ -265,16 +265,18 @@ const getBodyContent = async ({ : body ?? undefined } -const convertKeyValueTableToObject = ( +export const convertKeyValueTableToObject = ( keyValues: KeyValue[] | undefined, variables: Variable[] ) => { if (!keyValues) return return keyValues.reduce((object, item) => { - if (!item.key) return {} + const key = parseVariables(variables)(item.key) + const value = parseVariables(variables)(item.value) + if (isEmpty(key) || isEmpty(value)) return object return { ...object, - [item.key]: parseVariables(variables)(item.value ?? ''), + [key]: value, } }, {}) }