From 928674763a63ba2dc3eafe7ef8bcbf671256ff10 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Wed, 20 Dec 2023 12:59:00 +0530 Subject: [PATCH] chore: Handle boolean type variables --- package.json | 2 +- src/canned.ts | 2 +- src/types/conversation.ts | 2 +- test/canned.test.ts | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 45e3706..2548277 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatwoot/utils", - "version": "0.0.19", + "version": "0.0.20", "description": "Chatwoot utils", "private": false, "license": "MIT", diff --git a/src/canned.ts b/src/canned.ts index e7bbd83..9688b78 100644 --- a/src/canned.ts +++ b/src/canned.ts @@ -111,6 +111,6 @@ export const getUndefinedVariablesInMessage = ({ .trim(); }) .filter(variable => { - return !variables[variable]; + return variables[variable] === undefined; }); }; diff --git a/src/types/conversation.ts b/src/types/conversation.ts index 8795b7f..02ba190 100644 --- a/src/types/conversation.ts +++ b/src/types/conversation.ts @@ -33,7 +33,7 @@ export interface Assignee { } export interface Variables { - [key: string]: string | number; + [key: string]: string | number| boolean } export interface CustomAttributes { diff --git a/test/canned.test.ts b/test/canned.test.ts index 99af828..bac8f5e 100644 --- a/test/canned.test.ts +++ b/test/canned.test.ts @@ -17,6 +17,7 @@ const variables = { 'agent.first_name': 'Samuel', 'agent.last_name': 'Smith', 'agent.email': 'samuel@gmail.com', + 'contact.custom_attribute.cloud_customer': false, }; describe('#replaceVariablesInMessage', () => { @@ -135,12 +136,12 @@ describe('#getMessageVariables', () => { describe('#getUndefinedVariablesInMessage', () => { it('returns the undefined variables', () => { - const message = 'Please dm me at {{contact.twitter}}'; + const message = 'It seems like you are facing issues with {{contact.integration}}, the cloud customer is {{contact.custom_attribute.cloud_customer}}'; expect( getUndefinedVariablesInMessage({ message, variables }).length ).toEqual(1); expect(getUndefinedVariablesInMessage({ message, variables })).toEqual( - expect.arrayContaining(['contact.twitter']) + expect.arrayContaining(['contact.integration']) ); }); it('skip variables in string with code blocks', () => {