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
}
const bodyIsSingleVariable = (body: string) => /{{.+}}/.test(body)
export const executeWebhook =
(typebot: Typebot) =>
async (
@ -143,13 +145,17 @@ export const executeWebhook =
json:
contentType !== 'x-www-form-urlencoded' && body
? safeJsonParse(
parseVariables(variables, { escapeForJson: true })(body)
parseVariables(variables, {
escapeForJson: !bodyIsSingleVariable(body),
})(body)
)
: undefined,
form:
contentType === 'x-www-form-urlencoded' && body
? safeJsonParse(
parseVariables(variables, { escapeForJson: true })(body)
parseVariables(variables, {
escapeForJson: !bodyIsSingleVariable(body),
})(body)
)
: undefined,
}