2
0

fix: remove json escape for single variable body

Closes #110
This commit is contained in:
Baptiste Arnaud
2022-07-09 08:11:08 +02:00
parent 9839f5c132
commit d6aa6e7c75

View File

@ -84,6 +84,8 @@ const prepareWebhookAttributes = (
return webhook return webhook
} }
const bodyIsSingleVariable = (body: string) => /{{.+}}/.test(body)
export const executeWebhook = export const executeWebhook =
(typebot: Typebot) => (typebot: Typebot) =>
async ( async (
@ -143,13 +145,17 @@ export const executeWebhook =
json: json:
contentType !== 'x-www-form-urlencoded' && body contentType !== 'x-www-form-urlencoded' && body
? safeJsonParse( ? safeJsonParse(
parseVariables(variables, { escapeForJson: true })(body) parseVariables(variables, {
escapeForJson: !bodyIsSingleVariable(body),
})(body)
) )
: undefined, : undefined,
form: form:
contentType === 'x-www-form-urlencoded' && body contentType === 'x-www-form-urlencoded' && body
? safeJsonParse( ? safeJsonParse(
parseVariables(variables, { escapeForJson: true })(body) parseVariables(variables, {
escapeForJson: !bodyIsSingleVariable(body),
})(body)
) )
: undefined, : undefined,
} }