From 655a11bcf91b41f338fa014595c930b9f20906dc Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Wed, 4 Sep 2024 11:19:55 +0530 Subject: [PATCH] channel changes --- packages/rule-engine/package.json | 2 +- packages/rule-engine/src/models/rule.ts | 1 + .../recommended/conditions/channel-type.ts | 21 +++++++++++++++++++ packages/rule-engine/src/recommended/index.ts | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 packages/rule-engine/src/recommended/conditions/channel-type.ts diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index 2c24cab0..592221a7 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.18.3", + "version": "0.18.6-beta-1", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", diff --git a/packages/rule-engine/src/models/rule.ts b/packages/rule-engine/src/models/rule.ts index e973ac1c..d0642250 100644 --- a/packages/rule-engine/src/models/rule.ts +++ b/packages/rule-engine/src/models/rule.ts @@ -78,6 +78,7 @@ export enum ConditionKey { UserName = 'USER_NAME', UserPhone = 'USER_PHONE', UserProperty = 'USER_PROPERTY', + ChannelType = 'CHANNEL_TYPE' } export enum ConditionOperator { After = 'AFTER', diff --git a/packages/rule-engine/src/recommended/conditions/channel-type.ts b/packages/rule-engine/src/recommended/conditions/channel-type.ts new file mode 100644 index 00000000..e386b26d --- /dev/null +++ b/packages/rule-engine/src/recommended/conditions/channel-type.ts @@ -0,0 +1,21 @@ +import { ProductEventData } from '@freshworks-jaya/marketplace-models'; +import { Condition } from '../../models/rule'; +import { Utils } from '../../Utils'; +import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; + +export default ( + condition: Condition, + productEventData: ProductEventData, + integrations: Integrations, + options: RuleEngineOptions, + ruleAlias: string, +): Promise => { + return Utils.evaluateCondition( + condition.operator, + productEventData?.conversation?.source || productEventData?.message?.source ||'', + condition.value as string, + integrations, + options, + ruleAlias, + ); +}; diff --git a/packages/rule-engine/src/recommended/index.ts b/packages/rule-engine/src/recommended/index.ts index 9da5de3b..abd711c2 100644 --- a/packages/rule-engine/src/recommended/index.ts +++ b/packages/rule-engine/src/recommended/index.ts @@ -86,6 +86,7 @@ import conditionCallStatus from './conditions/call-status'; import conditionCallType from './conditions/call-type'; import conditionConversationProperty from './conditions/conversation-property'; import conditionEmailBody from './conditions/email-body'; +import conditionChannelType from './conditions/channel-type'; // Import all dynamic placeholders import dynamicPlaceholderAverageWaitTime from './dynamic-placeholders/average-wait-time'; @@ -145,6 +146,7 @@ const recommendedPlugins: RulePlugin[] = [ [ConditionKey.CallStatus]: conditionCallStatus, [ConditionKey.CallType]: conditionCallType, [ConditionKey.EmailBody]: conditionEmailBody, + [ConditionKey.ChannelType]: conditionChannelType, }, dynamicPlaceholders: { 'conversation.url': dynamicPlaceholderConversationUrl,