From e160ee7c06f1e8996eb4dd5d47c76d6f6e539362 Mon Sep 17 00:00:00 2001 From: Prabhu-Kathiresan Date: Fri, 17 Nov 2023 18:10:17 +0530 Subject: [PATCH 1/2] Support send message for email conversation --- packages/freshchat-api/src/index.ts | 8 +++++--- packages/marketplace-models/src/types/PayloadData.ts | 1 + .../rule-engine/src/recommended/actions/send-message.ts | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/freshchat-api/src/index.ts b/packages/freshchat-api/src/index.ts index bf7e2e8e..822a08c9 100644 --- a/packages/freshchat-api/src/index.ts +++ b/packages/freshchat-api/src/index.ts @@ -142,8 +142,10 @@ export default class Freshchat { actorType?: 'agent' | 'bot', actorId?: string, replyParts?: ReplyPart[], + isEmailConversation?: boolean ): AxiosPromise { const postMessageApiUrl = `${this.apiUrl}/conversations/${conversationId}/messages`; + const messagePartType = isEmailConversation ? 'email' : 'text'; return axios.post( postMessageApiUrl, @@ -152,7 +154,7 @@ export default class Freshchat { actor_type: actorType || 'bot', message_parts: [ { - text: { + [messagePartType]: { content: message, }, }, @@ -294,8 +296,8 @@ export default class Freshchat { /** * Send Normal Reply. */ - sendNormalReplyText(conversationId: string, message: string, agentId?: string): AxiosPromise { - return this.postMessage(conversationId, message, 'normal', agentId ? 'agent' : 'bot', agentId); + sendNormalReplyText(conversationId: string, message: string, agentId?: string, isEmailConversation: boolean = false): AxiosPromise { + return this.postMessage(conversationId, message, 'normal', agentId ? 'agent' : 'bot', agentId, undefined, isEmailConversation); } /** Update User API */ diff --git a/packages/marketplace-models/src/types/PayloadData.ts b/packages/marketplace-models/src/types/PayloadData.ts index 63c942c2..08a4cca7 100644 --- a/packages/marketplace-models/src/types/PayloadData.ts +++ b/packages/marketplace-models/src/types/PayloadData.ts @@ -37,6 +37,7 @@ export enum ConversationSource { MobileSDK = 'MOBILE', WebMessenger = 'WEBCHAT', WhatsApp = 'WHATSAPP', + Email = 'EMAIL', } export enum MessageSource { diff --git a/packages/rule-engine/src/recommended/actions/send-message.ts b/packages/rule-engine/src/recommended/actions/send-message.ts index 29ee0115..8ac8951a 100644 --- a/packages/rule-engine/src/recommended/actions/send-message.ts +++ b/packages/rule-engine/src/recommended/actions/send-message.ts @@ -1,4 +1,4 @@ -import { ProductEventPayload } from '@freshworks-jaya/marketplace-models'; +import { ConversationSource, ProductEventPayload } from '@freshworks-jaya/marketplace-models'; import Freshchat from '@freshworks-jaya/freshchat-api'; import { PlaceholdersMap } from '@freshworks-jaya/utilities'; import { Integrations, RuleEngineOptions } from '../../models/rule-engine'; @@ -20,6 +20,7 @@ export default async ( const freshchatApiToken = integrations.freshchatv2.token; const freshchat = new Freshchat(freshchatApiUrl, freshchatApiToken, ruleAlias); const modelProperties = productEventPayload.data.conversation || productEventPayload.data.message; + const isEmailConversation = modelProperties.source === ConversationSource.Email; const conversationId = modelProperties.conversation_id; let generatedPlaceholders: PlaceholdersMap = {}; @@ -37,7 +38,7 @@ export default async ( actionValue as string, combinedPlaceholders, ); - await freshchat.sendNormalReplyText(conversationId, textWithReplacedPlaceholders); + await freshchat.sendNormalReplyText(conversationId, textWithReplacedPlaceholders, undefined, isEmailConversation); } catch (err) { Utils.log( productEventPayload, From 55c15026eb337439f38d387dc555e9de57e5fd70 Mon Sep 17 00:00:00 2001 From: Prabhu-Kathiresan Date: Mon, 20 Nov 2023 11:41:49 +0530 Subject: [PATCH 2/2] update package versions --- packages/freshchat-api/package.json | 2 +- packages/marketplace-models/package.json | 2 +- packages/rule-engine/package.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/freshchat-api/package.json b/packages/freshchat-api/package.json index ba610c11..4bfb998b 100644 --- a/packages/freshchat-api/package.json +++ b/packages/freshchat-api/package.json @@ -1,6 +1,6 @@ { "name": "@freshworks-jaya/freshchat-api", - "version": "0.7.34", + "version": "0.7.35", "description": "Provides simple interface for accessing Freshchat's public APIs", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", diff --git a/packages/marketplace-models/package.json b/packages/marketplace-models/package.json index a8b1d910..95a57705 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.27", + "version": "0.1.28", "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/rule-engine/package.json b/packages/rule-engine/package.json index f1d357fb..8750459c 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.26", + "version": "0.17.27", "description": "Provides methods to process rules in product events in marketplace app", "repository": "git@github.com:freshdesk/jaya-lib.git", "main": "lib/index.js", @@ -44,9 +44,9 @@ "typescript": "^4.3.2" }, "dependencies": { - "@freshworks-jaya/freshchat-api": "0.7.34", + "@freshworks-jaya/freshchat-api": "0.7.35", "@freshworks-jaya/kairos-api": "^0.1.5", - "@freshworks-jaya/marketplace-models": "0.1.27", + "@freshworks-jaya/marketplace-models": "0.1.28", "@freshworks-jaya/utilities": "^1.0.0", "@google-cloud/logging": "^9.3.1", "axios": "^0.21.4",