From 0078d6da718586ce407c5786cd9dfdf86174610e Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 10 Aug 2023 08:29:50 +0200 Subject: [PATCH] :children_crossing: (webhook) Parse user email instead of test email for sample --- .../webhook/api/getResultExample.ts | 7 ++-- .../webhook/helpers/parseResultExample.ts | 40 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/apps/builder/src/features/blocks/integrations/webhook/api/getResultExample.ts b/apps/builder/src/features/blocks/integrations/webhook/api/getResultExample.ts index 14bc24bf18..4496f0197d 100644 --- a/apps/builder/src/features/blocks/integrations/webhook/api/getResultExample.ts +++ b/apps/builder/src/features/blocks/integrations/webhook/api/getResultExample.ts @@ -61,9 +61,10 @@ export const getResultExample = authenticatedProcedure const linkedTypebots = await fetchLinkedTypebots(typebot, user) return { - resultExample: await parseResultExample( + resultExample: await parseResultExample({ typebot, - linkedTypebots - )(block.groupId), + linkedTypebots, + userEmail: user.email ?? 'test@email.com', + })(block.groupId), } }) diff --git a/apps/builder/src/features/blocks/integrations/webhook/helpers/parseResultExample.ts b/apps/builder/src/features/blocks/integrations/webhook/helpers/parseResultExample.ts index bf47767be8..b94b4b645a 100644 --- a/apps/builder/src/features/blocks/integrations/webhook/helpers/parseResultExample.ts +++ b/apps/builder/src/features/blocks/integrations/webhook/helpers/parseResultExample.ts @@ -12,10 +12,15 @@ import { isInputBlock, byId, isNotDefined } from '@typebot.io/lib' import { parseResultHeader } from '@typebot.io/lib/results' export const parseResultExample = - ( - typebot: Pick, + ({ + typebot, + linkedTypebots, + userEmail, + }: { + typebot: Pick linkedTypebots: (Typebot | PublicTypebot)[] - ) => + userEmail: string + }) => async ( currentGroupId: string ): Promise< @@ -33,7 +38,11 @@ export const parseResultExample = return { message: 'This is a sample result, it has been generated ⬇️', 'Submitted at': new Date().toISOString(), - ...parseResultSample(linkedInputBlocks, header), + ...parseResultSample({ + inputBlocks: linkedInputBlocks, + headerCells: header, + userEmail, + }), } } @@ -84,10 +93,15 @@ const extractLinkedInputBlocks = ).concat(linkedBotInputs.flatMap((l) => l)) } -const parseResultSample = ( - inputBlocks: InputBlock[], +const parseResultSample = ({ + inputBlocks, + headerCells, + userEmail, +}: { + inputBlocks: InputBlock[] headerCells: ResultHeaderCell[] -) => + userEmail: string +}) => headerCells.reduce>( (resultSample, cell) => { const inputBlock = inputBlocks.find((inputBlock) => @@ -101,7 +115,7 @@ const parseResultSample = ( } return resultSample } - const value = getSampleValue(inputBlock) + const value = getSampleValue({ block: inputBlock, userEmail }) return { ...resultSample, [cell.label]: value, @@ -110,7 +124,13 @@ const parseResultSample = ( {} ) -const getSampleValue = (block: InputBlock) => { +const getSampleValue = ({ + block, + userEmail, +}: { + block: InputBlock + userEmail: string +}) => { switch (block.type) { case InputBlockType.CHOICE: return block.options.isMultipleChoice @@ -119,7 +139,7 @@ const getSampleValue = (block: InputBlock) => { case InputBlockType.DATE: return new Date().toUTCString() case InputBlockType.EMAIL: - return 'test@email.com' + return userEmail case InputBlockType.NUMBER: return '20' case InputBlockType.PHONE: