diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index 2c24cab..592221a 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 e973ac1..d064225 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 0000000..e386b26 --- /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 9da5de3..abd711c 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,