From 8f30afe892b9112844358e77dc43d7423f8020cd Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Tue, 19 Sep 2023 11:17:58 +0530 Subject: [PATCH 1/9] extended logging and sla bug fix --- packages/rule-engine/package.json | 2 +- packages/rule-engine/src/RuleProcessor.ts | 18 ++++++++++++++---- .../transcript-conv-entire-html.ts | 13 +++++++++++++ ...conv-entire-includes-private-system-html.ts | 13 +++++++++++++ ...conv-entire-includes-private-system-text.ts | 13 +++++++++++++ .../transcript-conv-entire-text.ts | 13 +++++++++++++ .../transcript-conv-since-last-resolve-html.ts | 13 +++++++++++++ ...ast-resolve-includes-private-system-html.ts | 13 +++++++++++++ ...ast-resolve-includes-private-system-text.ts | 13 +++++++++++++ .../transcript-conv-since-last-resolve-text.ts | 13 +++++++++++++ .../transcript-paytm-conv-entire-html.ts | 13 +++++++++++++ .../trigger-actions/first-sla-breach.ts | 3 ++- .../trigger-actions/next-sla-breach.ts | 3 ++- 13 files changed, 136 insertions(+), 7 deletions(-) diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index c3ca6669..fb41d40c 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.21-beta-1", + "version": "0.17.22-beta-07", "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/RuleProcessor.ts b/packages/rule-engine/src/RuleProcessor.ts index 261342d1..6b53cd2a 100644 --- a/packages/rule-engine/src/RuleProcessor.ts +++ b/packages/rule-engine/src/RuleProcessor.ts @@ -71,9 +71,14 @@ export class RuleProcessor { public static isTriggerActorMatch(actor: TriggerActor, productEventData: ProductEventData): boolean { const triggerActorFunc = ruleConfig.triggerActors && ruleConfig.triggerActors[actor.type]; - if (triggerActorFunc) { - return triggerActorFunc(productEventData, actor); + try { + if (triggerActorFunc) { + return triggerActorFunc(productEventData, actor); + } + } catch (error) { + throw new Error('Invalid trigger actor : ' + JSON.stringify(actor)); } + throw new Error('Invalid trigger actor'); } @@ -83,9 +88,14 @@ export class RuleProcessor { public static isTriggerActionMatch(action: TriggerAction, event: Event, productEventData: ProductEventData): boolean { const triggerActionFunc = ruleConfig.triggerActions && ruleConfig.triggerActions[action.type]; - if (triggerActionFunc) { - return triggerActionFunc(event, productEventData, action); + try { + if (triggerActionFunc) { + return triggerActionFunc(event, productEventData, action); + } + } catch (error) { + throw new Error('Invalid trigger action : ' + action.type); } + throw new Error('Invalid trigger action'); } diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts index 526f42b4..468d92c8 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts @@ -43,7 +43,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptEntireHtml, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts index 7c5d5aa3..10dc2f35 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts @@ -39,7 +39,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptEntirePrivateSystemHtml, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts index e986d046..b4be5e12 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts @@ -40,7 +40,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptEntirePrivateSystemText, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts index 88824772..fb63f596 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts @@ -44,7 +44,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptEntireText, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts index 498cd7e3..c172b5c3 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts @@ -44,7 +44,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptLastResolveHtml, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts index 44913ad1..7ef75277 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts @@ -40,7 +40,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptLastResolvePrivateSystemHtml, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts index 94c040b1..a493fff4 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts @@ -41,7 +41,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptLastResolvePrivateSystemText, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts index f4244a81..f0256aee 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts @@ -45,7 +45,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptLastResolveText, }, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts index af5e3471..386a6e11 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts @@ -44,7 +44,20 @@ export default ( { error: { data: err?.response?.data, + err, headers: err?.response?.headers, + payload: { + appConvoId: modelProperties.conversation_id, + appDomain: `https://${productEventPayload.domain}`, + appId: modelProperties.app_id, + options: { + isIncludeFreshchatLink: false, + messagesLimit: options.isUseStaticIP + ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP + : Constants.MAX_MESSAGES_TRANSCRIPT, + timezoneOffset: integrations.timezoneOffset, + }, + }, }, errorType: ErrorTypes.TranscriptEntireHtml, }, diff --git a/packages/rule-engine/src/recommended/trigger-actions/first-sla-breach.ts b/packages/rule-engine/src/recommended/trigger-actions/first-sla-breach.ts index 2fa5487d..9dd4b6af 100644 --- a/packages/rule-engine/src/recommended/trigger-actions/first-sla-breach.ts +++ b/packages/rule-engine/src/recommended/trigger-actions/first-sla-breach.ts @@ -5,7 +5,8 @@ export default (productEvent: Event, productEventData: ProductEventData, trigger return ( productEvent === Event.ConversationUpdate && !!productEventData.changes.model_changes && - productEventData.changes.model_changes.sla_breach[1] && + !!productEventData.changes.model_changes?.sla_breach && + !!productEventData.changes.model_changes?.sla_breach[1] && productEventData.conversation.response_due_type === 'FIRST_RESPONSE_DUE' ); }; diff --git a/packages/rule-engine/src/recommended/trigger-actions/next-sla-breach.ts b/packages/rule-engine/src/recommended/trigger-actions/next-sla-breach.ts index 95ff7493..4162f817 100644 --- a/packages/rule-engine/src/recommended/trigger-actions/next-sla-breach.ts +++ b/packages/rule-engine/src/recommended/trigger-actions/next-sla-breach.ts @@ -5,7 +5,8 @@ export default (productEvent: Event, productEventData: ProductEventData, trigger return ( productEvent === Event.ConversationUpdate && !!productEventData.changes.model_changes && - productEventData.changes.model_changes.sla_breach[1] && + !!productEventData.changes.model_changes?.sla_breach && + !!productEventData.changes.model_changes?.sla_breach[1] && productEventData.conversation.response_due_type === 'RESPONSE_DUE' ); }; From 80a3f08cb384d404f9664268385672acd64334b5 Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Thu, 5 Oct 2023 09:21:48 +0530 Subject: [PATCH 2/9] bug bash fixes --- packages/marketplace-models/package.json | 2 +- .../src/types/PayloadData.ts | 4 ++ packages/rule-engine/package.json | 4 +- packages/rule-engine/src/Utils.ts | 18 +++++++++ packages/rule-engine/src/models/rule.ts | 7 ++++ .../src/recommended/actions/trigger-api.ts | 38 ++++++++++++++++++- .../src/recommended/conditions/email-body.ts | 23 +++++++++++ .../transcript-conv-entire-html.ts | 1 + ...onv-entire-includes-private-system-html.ts | 1 + ...onv-entire-includes-private-system-text.ts | 1 + .../transcript-conv-entire-text.ts | 1 + ...transcript-conv-since-last-resolve-html.ts | 1 + ...st-resolve-includes-private-system-html.ts | 1 + ...st-resolve-includes-private-system-text.ts | 1 + ...transcript-conv-since-last-resolve-text.ts | 1 + .../transcript-paytm-conv-entire-html.ts | 1 + packages/rule-engine/src/recommended/index.ts | 2 + 17 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 packages/rule-engine/src/recommended/conditions/email-body.ts diff --git a/packages/marketplace-models/package.json b/packages/marketplace-models/package.json index 4901bfad..c70d9aff 100644 --- a/packages/marketplace-models/package.json +++ b/packages/marketplace-models/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/marketplace-models", - "version": "0.1.21", + "version": "0.1.23-beta-01", "description": "Provides type definitions for models in marketplace product events", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", diff --git a/packages/marketplace-models/src/types/PayloadData.ts b/packages/marketplace-models/src/types/PayloadData.ts index c2481dcf..e94b5ac9 100644 --- a/packages/marketplace-models/src/types/PayloadData.ts +++ b/packages/marketplace-models/src/types/PayloadData.ts @@ -121,6 +121,10 @@ export interface MessagePart { collection?: { sub_parts: MessagePart[]; }; + email?: { + content: string; + subject: string; + }; image?: { url: string }; quick_reply_button?: { custom_reply_text?: string; diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index fb41d40c..3eefb39f 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.22-beta-07", + "version": "0.17.22-beta-13", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -46,7 +46,7 @@ "dependencies": { "@freshworks-jaya/freshchat-api": "0.7.33-beta-1.0", "@freshworks-jaya/kairos-api": "^0.1.5", - "@freshworks-jaya/marketplace-models": "0.1.21", + "@freshworks-jaya/marketplace-models": "0.1.23-beta-01", "@freshworks-jaya/utilities": "^1.0.0", "@google-cloud/logging": "^9.3.1", "axios": "^0.21.4", diff --git a/packages/rule-engine/src/Utils.ts b/packages/rule-engine/src/Utils.ts index 93e4a904..8d877c94 100644 --- a/packages/rule-engine/src/Utils.ts +++ b/packages/rule-engine/src/Utils.ts @@ -135,6 +135,24 @@ export class Utils { return messageContent; } + /** + * Gets a concatenated string of messageParts with type 'text'. + */ + public static getMessagePartsEmailContent(messageParts: MessagePart[]): string { + let messageContent = ''; + + if (messageParts && messageParts.length) { + messageContent = messageParts + .filter((messagePart) => messagePart.email) + .map((messagePart) => { + return messagePart.email && messagePart.email.content; + }) + .join(' '); + } + + return messageContent; + } + public static processHanldebars(value: string, placeholders: PlaceholdersMap): string { let processedString = ''; let isError = false; diff --git a/packages/rule-engine/src/models/rule.ts b/packages/rule-engine/src/models/rule.ts index 0aae0bcd..8dc8c406 100644 --- a/packages/rule-engine/src/models/rule.ts +++ b/packages/rule-engine/src/models/rule.ts @@ -63,6 +63,7 @@ export enum ConditionKey { CallStatus = 'CALL_STATUS', CallType = 'CALL_TYPE', Channel = 'CHANNEL', + EmailBody = 'EMAIL_BODY', LabelCategoryName = 'LABEL_CATEGORY_NAME', LabelSubcategoryName = 'LABEL_SUBCATEGORY_NAME', MessageText = 'MESSAGE_TEXT', @@ -165,6 +166,12 @@ export interface TriggerWebhookValue { password: string; username: string; }; + castArray?: [ + { + key: string; + type: string; + }, + ]; content?: string; contentType?: WebhookContentType; customHeaders?: string; diff --git a/packages/rule-engine/src/recommended/actions/trigger-api.ts b/packages/rule-engine/src/recommended/actions/trigger-api.ts index ec5a6d5e..2a66fff4 100644 --- a/packages/rule-engine/src/recommended/actions/trigger-api.ts +++ b/packages/rule-engine/src/recommended/actions/trigger-api.ts @@ -1,6 +1,7 @@ import { ProductEventPayload } from '@freshworks-jaya/marketplace-models'; import { requestAxiosWrapper } from '@freshworks-jaya/marketplace-models/lib/services/request'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; +import { set, get } from 'lodash'; import { Api, JsonArray, @@ -56,6 +57,8 @@ const replacePlaceholdersInObject = (jsonMap: JsonMap | JsonArray, combinedPlace (json as JsonMap)[key] = Utils.processHandlebarsAndReplacePlaceholders(value as string, combinedPlaceholders); } else if (_.isObject(value) || _.isArray(value)) { traverseObject(value as JsonArray | JsonMap); + } else if (_.isInteger(value)) { + (json as JsonMap)[key] = Number(value); } }); })(jsonMap); @@ -168,8 +171,34 @@ const handleContentTypeHeader = ( } return { data, headers }; +}; + +const handleFieldTypeCast = (config: TriggerWebhookValue, replacedData: string) => { + const data = replacedData ? JSON.parse(replacedData) : {}; + + if (config?.castArray?.length) { + const castArray = config?.castArray; + + for (let i = 0; i < castArray.length; ++i) { + const { key, type } = castArray[i]; + + switch (type) { + case 'boolean': + set(data, key, Boolean(get(data, key))); + break; + case 'number': + set(data, key, Number(get(data, key))); + break; + case 'string': + default: + set(data, key, String(data[key])); + break; + } + } + } -} + return JSON.stringify(data); +}; export default async ( integrations: Integrations, @@ -209,6 +238,13 @@ export default async ( const dateBeforeTrigger = new Date(); let webhookResponse; + // Cast API content to specific type + try { + axiosRequestConfig.data = handleFieldTypeCast(triggerApi.config, axiosRequestConfig.data); + } catch (err) { + return Promise.reject('Failed to type cast dynamic placeholders map'); + } + try { // Step 6: Make the API call webhookResponse = await requestAxiosWrapper(axiosRequestConfig, { diff --git a/packages/rule-engine/src/recommended/conditions/email-body.ts b/packages/rule-engine/src/recommended/conditions/email-body.ts new file mode 100644 index 00000000..32bbe136 --- /dev/null +++ b/packages/rule-engine/src/recommended/conditions/email-body.ts @@ -0,0 +1,23 @@ +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 => { + const modelProperties = productEventData.conversation || productEventData.message; + + return Utils.evaluateCondition( + condition.operator, + Utils.getMessagePartsEmailContent((modelProperties.messages && modelProperties.messages[0].message_parts) || []), + condition.value as string, + integrations, + options, + ruleAlias, + ); +}; diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts index 468d92c8..aec333df 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts @@ -49,6 +49,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts index 10dc2f35..7e0d97dd 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts @@ -45,6 +45,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts index b4be5e12..c58f54de 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts @@ -46,6 +46,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts index fb63f596..a9231f49 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts @@ -50,6 +50,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts index c172b5c3..4179c9dc 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts @@ -50,6 +50,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts index 7ef75277..a9a70252 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts @@ -46,6 +46,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts index a493fff4..508dac74 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts @@ -47,6 +47,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts index f0256aee..85079273 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts @@ -51,6 +51,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts index 386a6e11..f76c39e9 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts @@ -50,6 +50,7 @@ export default ( appConvoId: modelProperties.conversation_id, appDomain: `https://${productEventPayload.domain}`, appId: modelProperties.app_id, + freshchatApiToken, options: { isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP diff --git a/packages/rule-engine/src/recommended/index.ts b/packages/rule-engine/src/recommended/index.ts index 99e5de93..4a21b7f7 100644 --- a/packages/rule-engine/src/recommended/index.ts +++ b/packages/rule-engine/src/recommended/index.ts @@ -74,6 +74,7 @@ import conditionLabelSubcategoryName from './conditions/label-subcategory-name'; import conditionSLAName from './conditions/sla-name'; import conditionCallStatus from './conditions/call-status'; import conditionCallType from './conditions/call-type'; +import conditionEmailBody from './conditions/email-body'; // Import all dynamic placeholders import dynamicPlaceholderAverageWaitTime from './dynamic-placeholders/average-wait-time'; @@ -129,6 +130,7 @@ const recommendedPlugins: RulePlugin[] = [ [ConditionKey.SLAName]: conditionSLAName, [ConditionKey.CallStatus]: conditionCallStatus, [ConditionKey.CallType]: conditionCallType, + [ConditionKey.EmailBody]: conditionEmailBody, }, dynamicPlaceholders: { 'conversation.url': dynamicPlaceholderConversationUrl, From 99f474e2d1c4a16e353914bad4a08b77425b57c9 Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Fri, 6 Oct 2023 16:01:09 +0530 Subject: [PATCH 3/9] logging payload update --- packages/rule-engine/src/TimerRuleEngine.ts | 25 ++++++------------- packages/rule-engine/src/index.ts | 14 ++++++++++- .../recommended/actions/assign-to-agent.ts | 7 ++---- .../recommended/actions/assign-to-group.ts | 7 ++---- .../actions/create-freshdesk-ticket.ts | 7 ++---- .../src/recommended/actions/reopen.ts | 7 ++---- .../src/recommended/actions/resolve.ts | 7 ++---- .../recommended/actions/send-email-anyone.ts | 7 ++---- .../recommended/actions/send-email-user.ts | 7 ++---- .../src/recommended/actions/send-message.ts | 7 ++---- .../recommended/actions/send-private-note.ts | 7 ++---- .../recommended/actions/send-quickreply.ts | 7 ++---- .../src/recommended/actions/trigger-api.ts | 6 ++--- .../actions/unassign-then-reassign-group.ts | 7 ++---- .../actions/update-conversation-property.ts | 6 ++--- .../src/recommended/actions/update-status.ts | 7 ++---- .../recommended/actions/update-user-email.ts | 7 ++---- .../actions/update-user-first-name.ts | 7 ++---- .../actions/update-user-last-name.ts | 7 ++---- .../recommended/actions/update-user-phone.ts | 7 ++---- .../actions/update-user-property.ts | 7 ++---- .../transcript-conv-entire-html.ts | 6 ----- ...onv-entire-includes-private-system-html.ts | 6 ----- ...onv-entire-includes-private-system-text.ts | 6 ----- .../transcript-conv-entire-text.ts | 6 ----- ...transcript-conv-since-last-resolve-html.ts | 6 ----- ...st-resolve-includes-private-system-html.ts | 6 ----- ...st-resolve-includes-private-system-text.ts | 6 ----- ...transcript-conv-since-last-resolve-text.ts | 6 ----- .../transcript-paytm-conv-entire-html.ts | 6 ----- 30 files changed, 58 insertions(+), 166 deletions(-) diff --git a/packages/rule-engine/src/TimerRuleEngine.ts b/packages/rule-engine/src/TimerRuleEngine.ts index 530fd148..485eb1d1 100644 --- a/packages/rule-engine/src/TimerRuleEngine.ts +++ b/packages/rule-engine/src/TimerRuleEngine.ts @@ -2,6 +2,7 @@ import Kairos, { KairosSchedule, KairosScheduleOptions } from '@freshworks-jaya/ import { Event, ProductEventPayload, ProductEventData, ModelProperties } from '@freshworks-jaya/marketplace-models'; import { ActionExecutor } from './ActionExecutor'; import { + AnyJson, Api, CustomPlaceholdersMap, Rule, @@ -150,10 +151,7 @@ export class TimerRuleEngine { integrations, ErrorCodes.KairosError, { - error: { - data: err?.response?.data, - responseHeaders: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.KairosBulkCreateSchedules, jobIds: schedulesToCreate.map((schedule) => schedule.jobId), }, @@ -200,10 +198,7 @@ export class TimerRuleEngine { integrations, ErrorCodes.KairosError, { - error: { - data: err?.response?.data, - responseHeaders: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.KairosDeleteCompletedSchedule, jobId: externalEventPayload.data?.jobId, }, @@ -338,16 +333,13 @@ export class TimerRuleEngine { ); return Promise.resolve(); }, - (err) => { + (err: AnyJson) => { Utils.log( payload, integrations, ErrorCodes.KairosError, { - error: { - data: err?.response?.data, - responseHeaders: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.KairosCreteScheduleToDelayInvalidation, jobId: createScheduleJobId, }, @@ -372,16 +364,13 @@ export class TimerRuleEngine { ); return Promise.resolve(); }, - (err) => { + (err: AnyJson) => { Utils.log( payload, integrations, ErrorCodes.KairosError, { - error: { - data: err?.response?.data, - responseHeaders: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.KairosDeleteInvalidatedSchedules, jobIds: jobsToDelete, }, diff --git a/packages/rule-engine/src/index.ts b/packages/rule-engine/src/index.ts index 769ffcfe..3f9154d2 100644 --- a/packages/rule-engine/src/index.ts +++ b/packages/rule-engine/src/index.ts @@ -6,13 +6,16 @@ import { KairosCredentials, } from './models/rule-engine'; -import { Api, CustomPlaceholdersMap, Rule } from './models/rule'; +import { AnyJson, Api, CustomPlaceholdersMap, Rule } from './models/rule'; import { RulePlugin } from './models/plugin'; import { RuleProcessor } from './RuleProcessor'; import { ActionExecutor } from './ActionExecutor'; import { TimerRuleEngine } from './TimerRuleEngine'; import ruleConfig from './RuleConfig'; import recommendedPlugins from './recommended/index'; +import { Utils } from './Utils'; +import { ErrorCodes } from './models/error-codes'; +import { LogSeverity } from './services/GoogleCloudLogging'; export * from './models/rule'; export * from './models/rule-engine'; @@ -82,6 +85,15 @@ export class RuleEngine { ); } } catch (err) { + Utils.log( + payload, + integrations, + ErrorCodes.FreshchatAction, + { + error: err as AnyJson, + }, + LogSeverity.ALERT, + ); return Promise.reject(err); } diff --git a/packages/rule-engine/src/recommended/actions/assign-to-agent.ts b/packages/rule-engine/src/recommended/actions/assign-to-agent.ts index 47a70d44..db3ec324 100644 --- a/packages/rule-engine/src/recommended/actions/assign-to-agent.ts +++ b/packages/rule-engine/src/recommended/actions/assign-to-agent.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -63,10 +63,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatAssignAgent, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/assign-to-group.ts b/packages/rule-engine/src/recommended/actions/assign-to-group.ts index b03d0786..a1fbc05a 100644 --- a/packages/rule-engine/src/recommended/actions/assign-to-group.ts +++ b/packages/rule-engine/src/recommended/actions/assign-to-group.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -56,10 +56,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatAssignGroup, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/create-freshdesk-ticket.ts b/packages/rule-engine/src/recommended/actions/create-freshdesk-ticket.ts index a4ece81b..a049030a 100644 --- a/packages/rule-engine/src/recommended/actions/create-freshdesk-ticket.ts +++ b/packages/rule-engine/src/recommended/actions/create-freshdesk-ticket.ts @@ -6,7 +6,7 @@ import Freshchat, { User as FreshchatUser } from '@freshworks-jaya/freshchat-api import { Utils as FreshchatUtils } from '@freshworks-jaya/freshchat-api/lib/Utils'; import { isUsernameGenerated } from '@freshworks-jaya/utilities'; import { Utils } from '../../Utils'; -import { Api, WebhookRequestType } from '../../models/rule'; +import { AnyJson, Api, WebhookRequestType } from '../../models/rule'; import { ErrorCodes } from '../../models/error-codes'; import Constants from '../Constants'; @@ -193,10 +193,7 @@ export default async ( ); } catch (err) { Utils.log(productEventPayload, integrations, ErrorCodes.FreshdeskTicket, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, }); return Promise.reject('Error creating freshdesk ticket'); } diff --git a/packages/rule-engine/src/recommended/actions/reopen.ts b/packages/rule-engine/src/recommended/actions/reopen.ts index 18c8a15d..3aa7a904 100644 --- a/packages/rule-engine/src/recommended/actions/reopen.ts +++ b/packages/rule-engine/src/recommended/actions/reopen.ts @@ -2,7 +2,7 @@ import { ConversationStatus, ProductEventPayload } from '@freshworks-jaya/market import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { Utils } from '../../Utils'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -30,10 +30,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatReopenConversation, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/resolve.ts b/packages/rule-engine/src/recommended/actions/resolve.ts index 8c729515..6020dd21 100644 --- a/packages/rule-engine/src/recommended/actions/resolve.ts +++ b/packages/rule-engine/src/recommended/actions/resolve.ts @@ -2,7 +2,7 @@ import { ConversationStatus, ProductEventPayload } from '@freshworks-jaya/market import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { Utils } from '../../Utils'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -30,10 +30,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatResolveConversation, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/send-email-anyone.ts b/packages/rule-engine/src/recommended/actions/send-email-anyone.ts index 04b1f6a8..6d44b0c2 100644 --- a/packages/rule-engine/src/recommended/actions/send-email-anyone.ts +++ b/packages/rule-engine/src/recommended/actions/send-email-anyone.ts @@ -1,7 +1,7 @@ import { ProductEventPayload } from '@freshworks-jaya/marketplace-models'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import axios from 'axios'; -import { Api, SendEmailAnyoneValue } from '../../models/rule'; +import { AnyJson, Api, SendEmailAnyoneValue } from '../../models/rule'; import { Utils } from '../../Utils'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { ErrorCodes } from '../../models/error-codes'; @@ -87,10 +87,7 @@ export default async ( ); } catch (err) { Utils.log(productEventPayload, integrations, ErrorCodes.SendEmail, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, }); return Promise.reject('Failed to setup dynamic placeholders'); } diff --git a/packages/rule-engine/src/recommended/actions/send-email-user.ts b/packages/rule-engine/src/recommended/actions/send-email-user.ts index d6a888d0..9ab51f82 100644 --- a/packages/rule-engine/src/recommended/actions/send-email-user.ts +++ b/packages/rule-engine/src/recommended/actions/send-email-user.ts @@ -3,7 +3,7 @@ import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import Freshchat from '@freshworks-jaya/freshchat-api'; import axios from 'axios'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { Utils } from '../../Utils'; import { ErrorCodes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -88,10 +88,7 @@ export default async ( ); } catch (err) { Utils.log(productEventPayload, integrations, ErrorCodes.SendEmail, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, }); return Promise.reject('Error sending conversation as html via email'); } diff --git a/packages/rule-engine/src/recommended/actions/send-message.ts b/packages/rule-engine/src/recommended/actions/send-message.ts index 85f8787e..29ee0115 100644 --- a/packages/rule-engine/src/recommended/actions/send-message.ts +++ b/packages/rule-engine/src/recommended/actions/send-message.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatSendMessage, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/send-private-note.ts b/packages/rule-engine/src/recommended/actions/send-private-note.ts index 91a6c27d..d423ee5e 100644 --- a/packages/rule-engine/src/recommended/actions/send-private-note.ts +++ b/packages/rule-engine/src/recommended/actions/send-private-note.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -48,10 +48,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatSendPrivateNote, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/send-quickreply.ts b/packages/rule-engine/src/recommended/actions/send-quickreply.ts index 97c3df1c..63f66bd2 100644 --- a/packages/rule-engine/src/recommended/actions/send-quickreply.ts +++ b/packages/rule-engine/src/recommended/actions/send-quickreply.ts @@ -1,7 +1,7 @@ import { ProductEventPayload } from '@freshworks-jaya/marketplace-models'; import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; -import { Api, QuickReplyValue } from '../../models/rule'; +import { AnyJson, Api, QuickReplyValue } from '../../models/rule'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Utils } from '../../Utils'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; @@ -63,10 +63,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatSendQuickReply, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/trigger-api.ts b/packages/rule-engine/src/recommended/actions/trigger-api.ts index 2a66fff4..ebe6a3aa 100644 --- a/packages/rule-engine/src/recommended/actions/trigger-api.ts +++ b/packages/rule-engine/src/recommended/actions/trigger-api.ts @@ -3,6 +3,7 @@ import { requestAxiosWrapper } from '@freshworks-jaya/marketplace-models/lib/ser import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { set, get } from 'lodash'; import { + AnyJson, Api, JsonArray, JsonMap, @@ -270,10 +271,7 @@ export default async ( } catch (err) { Utils.log(productEventPayload, integrations, ErrorCodes.TriggerAPIError, { apiName: triggerApi.name, - error: { - code: err.code, - message: err.message, - }, + error: err as AnyJson, }); return Promise.reject('Trigger webhook failure'); } diff --git a/packages/rule-engine/src/recommended/actions/unassign-then-reassign-group.ts b/packages/rule-engine/src/recommended/actions/unassign-then-reassign-group.ts index 680150db..2e5de73b 100644 --- a/packages/rule-engine/src/recommended/actions/unassign-then-reassign-group.ts +++ b/packages/rule-engine/src/recommended/actions/unassign-then-reassign-group.ts @@ -2,7 +2,7 @@ import { ConversationStatus, ProductEventPayload } from '@freshworks-jaya/market import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { Utils } from '../../Utils'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -40,10 +40,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUnassignThenReassign, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-conversation-property.ts b/packages/rule-engine/src/recommended/actions/update-conversation-property.ts index 476fe6cc..50b8d48f 100644 --- a/packages/rule-engine/src/recommended/actions/update-conversation-property.ts +++ b/packages/rule-engine/src/recommended/actions/update-conversation-property.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api, PropertiesConditionValue, JsonMap } from '../../models/rule'; +import { Api, PropertiesConditionValue, JsonMap, AnyJson } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -57,9 +57,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err as JsonMap, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdateProperty, properties: err as JsonMap, propertyKey: convPropertiesActionValue.propertyKey, diff --git a/packages/rule-engine/src/recommended/actions/update-status.ts b/packages/rule-engine/src/recommended/actions/update-status.ts index 011303b6..34dd15f3 100644 --- a/packages/rule-engine/src/recommended/actions/update-status.ts +++ b/packages/rule-engine/src/recommended/actions/update-status.ts @@ -2,7 +2,7 @@ import { ConversationStatus, ProductEventPayload } from '@freshworks-jaya/market import Freshchat from '@freshworks-jaya/freshchat-api'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { Utils } from '../../Utils'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatReopenConversation, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-user-email.ts b/packages/rule-engine/src/recommended/actions/update-user-email.ts index 4592a6ac..72ddc795 100644 --- a/packages/rule-engine/src/recommended/actions/update-user-email.ts +++ b/packages/rule-engine/src/recommended/actions/update-user-email.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdateEmail, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-user-first-name.ts b/packages/rule-engine/src/recommended/actions/update-user-first-name.ts index bb2e14cf..6d33bfec 100644 --- a/packages/rule-engine/src/recommended/actions/update-user-first-name.ts +++ b/packages/rule-engine/src/recommended/actions/update-user-first-name.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdateFirstName, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-user-last-name.ts b/packages/rule-engine/src/recommended/actions/update-user-last-name.ts index ddd1f3a9..91f2e2c4 100644 --- a/packages/rule-engine/src/recommended/actions/update-user-last-name.ts +++ b/packages/rule-engine/src/recommended/actions/update-user-last-name.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdateLastName, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-user-phone.ts b/packages/rule-engine/src/recommended/actions/update-user-phone.ts index c6ef3ea3..a8298363 100644 --- a/packages/rule-engine/src/recommended/actions/update-user-phone.ts +++ b/packages/rule-engine/src/recommended/actions/update-user-phone.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api } from '../../models/rule'; +import { AnyJson, Api } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -44,10 +44,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdatePhone, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/actions/update-user-property.ts b/packages/rule-engine/src/recommended/actions/update-user-property.ts index 8252b222..e11cf733 100644 --- a/packages/rule-engine/src/recommended/actions/update-user-property.ts +++ b/packages/rule-engine/src/recommended/actions/update-user-property.ts @@ -3,7 +3,7 @@ import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; import { Utils } from '../../Utils'; -import { Api, PropertiesConditionValue } from '../../models/rule'; +import { AnyJson, Api, PropertiesConditionValue } from '../../models/rule'; import { ErrorCodes, ErrorTypes } from '../../models/error-codes'; import { LogSeverity } from '../../services/GoogleCloudLogging'; @@ -52,10 +52,7 @@ export default async ( integrations, ErrorCodes.FreshchatAction, { - error: { - data: err?.response?.data, - headers: err?.response?.headers, - }, + error: err as AnyJson, errorType: ErrorTypes.FreshchatUpdateProperty, }, LogSeverity.ERROR, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts index aec333df..9c3678be 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-html.ts @@ -42,16 +42,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts index 7e0d97dd..ed8f378b 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-html.ts @@ -38,16 +38,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts index c58f54de..befed41f 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-includes-private-system-text.ts @@ -39,16 +39,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts index a9231f49..be2bc5c5 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-entire-text.ts @@ -43,16 +43,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts index 4179c9dc..77093e13 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-html.ts @@ -43,16 +43,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts index a9a70252..12dfd15c 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-html.ts @@ -39,16 +39,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts index 508dac74..85c04505 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text.ts @@ -40,16 +40,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts index 85079273..00bb4534 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-conv-since-last-resolve-text.ts @@ -44,16 +44,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, diff --git a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts index f76c39e9..2020d092 100644 --- a/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts +++ b/packages/rule-engine/src/recommended/dynamic-placeholders/transcript-paytm-conv-entire-html.ts @@ -43,16 +43,10 @@ export default ( ErrorCodes.FreshchatPlaceholder, { error: { - data: err?.response?.data, err, - headers: err?.response?.headers, payload: { - appConvoId: modelProperties.conversation_id, - appDomain: `https://${productEventPayload.domain}`, - appId: modelProperties.app_id, freshchatApiToken, options: { - isIncludeFreshchatLink: false, messagesLimit: options.isUseStaticIP ? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP : Constants.MAX_MESSAGES_TRANSCRIPT, From 1ff8980791afd5446c2f9e7a01f0e9597de0be3f Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 9 Oct 2023 08:13:04 +0530 Subject: [PATCH 4/9] new version update --- packages/rule-engine/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index c4ea78fa..489c2539 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.24", + "version": "0.17.25", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -46,7 +46,7 @@ "dependencies": { "@freshworks-jaya/freshchat-api": "0.7.33-beta-09", "@freshworks-jaya/kairos-api": "^0.1.5", - "@freshworks-jaya/marketplace-models": "0.1.24", + "@freshworks-jaya/marketplace-models": "0.1.25", "@freshworks-jaya/utilities": "^1.0.0", "@google-cloud/logging": "^9.3.1", "axios": "^0.21.4", From c08bb0b252f267451316a00c4b06f2c063833d60 Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 9 Oct 2023 08:13:35 +0530 Subject: [PATCH 5/9] new version --- packages/marketplace-models/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/marketplace-models/package.json b/packages/marketplace-models/package.json index e31529e7..c703f9e2 100644 --- a/packages/marketplace-models/package.json +++ b/packages/marketplace-models/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/marketplace-models", - "version": "0.1.24", + "version": "0.1.25", "description": "Provides type definitions for models in marketplace product events", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", From a053ec7ae1a2b9bc30f4c7a765e0080a553c604f Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 16 Oct 2023 09:10:07 +0530 Subject: [PATCH 6/9] bug fix and extend logging --- packages/rule-engine/package.json | 2 +- packages/rule-engine/src/ActionExecutor.ts | 13 ++++++++++++- packages/rule-engine/src/RuleProcessor.ts | 19 ++++++++++++++++--- .../rule-engine/src/models/error-codes.ts | 2 ++ .../rule-engine/src/models/rule-engine.ts | 1 + .../src/recommended/actions/trigger-api.ts | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index 489c2539..9ff4a632 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.25", + "version": "0.17.25-beta-01", "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/ActionExecutor.ts b/packages/rule-engine/src/ActionExecutor.ts index c7693966..668d78d7 100644 --- a/packages/rule-engine/src/ActionExecutor.ts +++ b/packages/rule-engine/src/ActionExecutor.ts @@ -11,13 +11,15 @@ import { LabelCategory, LabelSubcategory, } from '@freshworks-jaya/marketplace-models'; -import { Action, Api, CustomPlaceholdersMap } from './models/rule'; +import { Action, AnyJson, Api, CustomPlaceholdersMap } from './models/rule'; import { Integrations, RuleEngineOptions } from './models/rule-engine'; import ruleConfig from './RuleConfig'; import { isUsernameGenerated, PlaceholdersMap, capitalizeAll } from '@freshworks-jaya/utilities'; import { Utils } from './Utils'; import Freshchat from '@freshworks-jaya/freshchat-api'; import { AxiosResponse } from 'axios'; +import { APITraceCodes } from './models/error-codes'; +import { LogSeverity } from './services/GoogleCloudLogging'; export class ActionExecutor { /** @@ -206,6 +208,15 @@ export class ActionExecutor { // Error while executing an action // Queietly suppressing it so that next action can be executed // So, doing nothing here + if (options.enableLogger) { + Utils.log( + productEventPayload, + integrations, + APITraceCodes.ACTION_HANDLER_ERROR, + err as AnyJson, + LogSeverity.NOTICE, + ); + } } } diff --git a/packages/rule-engine/src/RuleProcessor.ts b/packages/rule-engine/src/RuleProcessor.ts index 6b53cd2a..8c012654 100644 --- a/packages/rule-engine/src/RuleProcessor.ts +++ b/packages/rule-engine/src/RuleProcessor.ts @@ -1,10 +1,13 @@ // Simple library to process the rules -import { Event } from '@freshworks-jaya/marketplace-models'; +import { Event, ProductEventPayload } from '@freshworks-jaya/marketplace-models'; import { ProductEventData } from '@freshworks-jaya/marketplace-models'; -import { Block, Condition, MatchType, Rule, Trigger, TriggerAction, TriggerActor } from './models/rule'; +import { AnyJson, Block, Condition, MatchType, Rule, Trigger, TriggerAction, TriggerActor } from './models/rule'; import { Integrations, RuleEngineOptions } from './models/rule-engine'; import { Promise } from 'bluebird'; import ruleConfig from './RuleConfig'; +import { Utils } from './Utils'; +import { APITraceCodes } from './models/error-codes'; +import { LogSeverity } from './services/GoogleCloudLogging'; export class RuleProcessor { /** @@ -206,7 +209,17 @@ export class RuleProcessor { await this.isRuleMatching(event, productEventData, currentRule, integrations, options); firstMatchingRule = currentRule; break; - } catch (err) {} + } catch (err) { + if (options.enableLogger) { + Utils.log( + productEventData as unknown as ProductEventPayload, + integrations, + APITraceCodes.FIRST_MATCHING_RULE, + err as AnyJson, + LogSeverity.NOTICE, + ); + } + } } } return firstMatchingRule ? Promise.resolve(firstMatchingRule) : Promise.reject('no matching rule'); diff --git a/packages/rule-engine/src/models/error-codes.ts b/packages/rule-engine/src/models/error-codes.ts index ca03886f..d9d41c0f 100644 --- a/packages/rule-engine/src/models/error-codes.ts +++ b/packages/rule-engine/src/models/error-codes.ts @@ -40,8 +40,10 @@ export enum ErrorTypes { } export enum APITraceCodes { + ACTION_HANDLER_ERROR = 'ACTION_HANDLER_ERROR', CREATE_SCHEDULE_SUCCESS = 'CREATE_SCHEDULE_SUCCESS', DELAY_SCHEDULE_CREATION = 'DELAY_SCHEDULE_CREATION', EXECUTE_SCHEDULE_SUCCESS = 'EXECUTE_SCHEDULE_SUCCESS', + FIRST_MATCHING_RULE = 'FIRST_MATCHING_RULE', INVALIDATE_SCHEDULE_SUCCESS = 'INVALIDATE_SCHEDULE_SUCCESS', } diff --git a/packages/rule-engine/src/models/rule-engine.ts b/packages/rule-engine/src/models/rule-engine.ts index 6b7abdaa..d6aeab52 100644 --- a/packages/rule-engine/src/models/rule-engine.ts +++ b/packages/rule-engine/src/models/rule-engine.ts @@ -3,6 +3,7 @@ import { RequestProxy } from '@freshworks-jaya/marketplace-models/lib/services/r import { GoogleCloudLoggingConfig } from '../services/GoogleCloudLogging'; export interface RuleEngineOptions { + enableLogger: boolean; // this is to be enabled only for debugging, should be disabled afterwards isSchedulerEnabled: boolean; isUseStaticIP: boolean; maxProductEventDelay: number; diff --git a/packages/rule-engine/src/recommended/actions/trigger-api.ts b/packages/rule-engine/src/recommended/actions/trigger-api.ts index ebe6a3aa..962edf33 100644 --- a/packages/rule-engine/src/recommended/actions/trigger-api.ts +++ b/packages/rule-engine/src/recommended/actions/trigger-api.ts @@ -192,7 +192,7 @@ const handleFieldTypeCast = (config: TriggerWebhookValue, replacedData: string) break; case 'string': default: - set(data, key, String(data[key])); + set(data, key, String(get(data, key))); break; } } From 3c5bc8ccc09adbdb1fd92d5e9cf6ca5f66ac5c3d Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 16 Oct 2023 10:57:45 +0530 Subject: [PATCH 7/9] test case update --- packages/rule-engine/test/index.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/rule-engine/test/index.test.ts b/packages/rule-engine/test/index.test.ts index c3d565fe..024398ee 100644 --- a/packages/rule-engine/test/index.test.ts +++ b/packages/rule-engine/test/index.test.ts @@ -199,6 +199,7 @@ describe('RuleEngine test', () => { [], {}, { + enableLogger: false, isSchedulerEnabled: false, isUseStaticIP: false, maxProductEventDelay: 30000, @@ -222,6 +223,7 @@ describe('RuleEngine test', () => { [], {}, { + enableLogger: false, isSchedulerEnabled: false, isUseStaticIP: false, maxProductEventDelay: 30000, @@ -243,6 +245,7 @@ describe('RuleEngine test', () => { [], {}, { + enableLogger: false, isSchedulerEnabled: false, isUseStaticIP: false, maxProductEventDelay: 30000, From b069555ce312f230941cf9ab23a040eaca20265b Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 16 Oct 2023 11:01:20 +0530 Subject: [PATCH 8/9] test case update --- packages/rule-engine/src/models/rule-engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rule-engine/src/models/rule-engine.ts b/packages/rule-engine/src/models/rule-engine.ts index d6aeab52..54bc3671 100644 --- a/packages/rule-engine/src/models/rule-engine.ts +++ b/packages/rule-engine/src/models/rule-engine.ts @@ -3,7 +3,7 @@ import { RequestProxy } from '@freshworks-jaya/marketplace-models/lib/services/r import { GoogleCloudLoggingConfig } from '../services/GoogleCloudLogging'; export interface RuleEngineOptions { - enableLogger: boolean; // this is to be enabled only for debugging, should be disabled afterwards + enableLogger?: boolean; // this is to be enabled only for debugging, should be disabled afterwards isSchedulerEnabled: boolean; isUseStaticIP: boolean; maxProductEventDelay: number; From 2f11b4b8f4d2009eeef362267ba9a999db32da93 Mon Sep 17 00:00:00 2001 From: ShashaankKrishnatray Date: Mon, 16 Oct 2023 11:01:56 +0530 Subject: [PATCH 9/9] version update --- packages/rule-engine/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rule-engine/package.json b/packages/rule-engine/package.json index 9ff4a632..6f51ee7d 100644 --- a/packages/rule-engine/package.json +++ b/packages/rule-engine/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/rule-engine", - "version": "0.17.25-beta-01", + "version": "0.17.25-beta-02", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js",