From 519723b2d895bea93abcc5ec005f6ce81d617c7d Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 8 Apr 2022 06:30:36 -0500 Subject: [PATCH] =?UTF-8?q?feat(engine):=20=E2=99=BF=EF=B8=8F=20Lowercase?= =?UTF-8?q?=20resiliency=20on=20"contains"=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/bot-engine/src/services/logic.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/bot-engine/src/services/logic.ts b/packages/bot-engine/src/services/logic.ts index e53d618c24d..2233765071f 100644 --- a/packages/bot-engine/src/services/logic.ts +++ b/packages/bot-engine/src/services/logic.ts @@ -88,19 +88,22 @@ const executeCondition = ( const executeComparison = (variables: Variable[]) => (comparison: Comparison) => { if (!comparison?.variableId) return false - const inputValue = + const inputValue = ( variables.find((v) => v.id === comparison.variableId)?.value ?? '' - const value = parseVariables(variables)(comparison.value) + ) + .toString() + .trim() + const value = parseVariables(variables)(comparison.value).toString().trim() if (isNotDefined(value)) return false switch (comparison.comparisonOperator) { case ComparisonOperators.CONTAINS: { - return inputValue.toString().includes(value.toString()) + return inputValue.toLowerCase().includes(value.toLowerCase()) } case ComparisonOperators.EQUAL: { - return inputValue.toString() === value.toString() + return inputValue === value } case ComparisonOperators.NOT_EQUAL: { - return inputValue.toString() !== value.toString() + return inputValue !== value } case ComparisonOperators.GREATER: { return parseFloat(inputValue) >= parseFloat(value)