From 17020c8fef6e2371926308228cf97fa30a3e078d Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 14 Feb 2023 16:45:35 +0100 Subject: [PATCH] :bug: (bot) Still parse variable ID in code if has no value --- apps/viewer/src/features/variables/utils.ts | 9 ++++++--- packages/bot-engine/src/features/variables/utils.ts | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/viewer/src/features/variables/utils.ts b/apps/viewer/src/features/variables/utils.ts index 854882754..4033986b7 100644 --- a/apps/viewer/src/features/variables/utils.ts +++ b/apps/viewer/src/features/variables/utils.ts @@ -24,10 +24,13 @@ export const parseVariables = if (!text || text === '') return '' return text.replace(/\{\{(.*?)\}\}/g, (_, fullVariableString) => { const matchedVarName = fullVariableString.replace(/{{|}}/g, '') - const variable = variables.find((v) => { - return matchedVarName === v.name && isDefined(v.value) + const variable = variables.find((variable) => { + return ( + matchedVarName === variable.name && + (options.fieldToParse === 'id' || isDefined(variable.value)) + ) }) as VariableWithValue | undefined - if (!variable || variable.value === null) return '' + if (!variable) return '' if (options.fieldToParse === 'id') return variable.id const { value } = variable if (options.escapeForJson) return jsonParse(value) diff --git a/packages/bot-engine/src/features/variables/utils.ts b/packages/bot-engine/src/features/variables/utils.ts index 52d4d4f18..a15482b94 100644 --- a/packages/bot-engine/src/features/variables/utils.ts +++ b/packages/bot-engine/src/features/variables/utils.ts @@ -16,10 +16,13 @@ export const parseVariables = if (!text || text === '') return '' return text.replace(/\{\{(.*?)\}\}/g, (_, fullVariableString) => { const matchedVarName = fullVariableString.replace(/{{|}}/g, '') - const variable = variables.find((v) => { - return matchedVarName === v.name && isDefined(v.value) + const variable = variables.find((variable) => { + return ( + matchedVarName === variable.name && + (options.fieldToParse === 'id' || isDefined(variable.value)) + ) }) as VariableWithValue | undefined - if (!variable || variable.value === null) return '' + if (!variable) return '' if (options.fieldToParse === 'id') return variable.id const { value } = variable if (options.escapeForJson) return jsonParse(value)