diff --git a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts index 8bfa515ce..79c37d4da 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/blocks/[blockId]/executeWebhook.ts @@ -142,11 +142,15 @@ export const executeWebhook = ...basicAuth, json: contentType !== 'x-www-form-urlencoded' && body - ? safeJsonParse(parseVariables(variables)(body)) + ? safeJsonParse( + parseVariables(variables, { escapeLineBreaks: true })(body) + ) : undefined, form: contentType === 'x-www-form-urlencoded' && body - ? safeJsonParse(parseVariables(variables)(body)) + ? safeJsonParse( + parseVariables(variables, { escapeLineBreaks: true })(body) + ) : undefined, } try { diff --git a/packages/bot-engine/src/services/variable.ts b/packages/bot-engine/src/services/variable.ts index 2f2c1b2ba..365226ae1 100644 --- a/packages/bot-engine/src/services/variable.ts +++ b/packages/bot-engine/src/services/variable.ts @@ -7,7 +7,10 @@ export const stringContainsVariable = (str: string): boolean => export const parseVariables = ( variables: Variable[], - options: { fieldToParse: 'value' | 'id' } = { fieldToParse: 'value' } + options: { fieldToParse?: 'value' | 'id'; escapeLineBreaks?: boolean } = { + fieldToParse: 'value', + escapeLineBreaks: false, + } ) => (text: string | undefined): string => { if (!text || text === '') return '' @@ -17,11 +20,12 @@ export const parseVariables = return matchedVarName === v.name && isDefined(v.value) }) if (!variable) return '' - return ( - (options.fieldToParse === 'value' - ? variable.value?.toString() - : variable.id) || '' - ) + if (options.fieldToParse === 'id') return variable.id + const { value } = variable + if (!value) return '' + if (options.escapeLineBreaks) + return value.toString().replace(/\n/g, '\\n') + return value.toString() }) }