Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support send message for email conversation #108

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/freshchat-api/package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down
8 changes: 5 additions & 3 deletions packages/freshchat-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export default class Freshchat {
actorType?: 'agent' | 'bot',
actorId?: string,
replyParts?: ReplyPart[],
isEmailConversation?: boolean
): AxiosPromise<Message> {
const postMessageApiUrl = `${this.apiUrl}/conversations/${conversationId}/messages`;
const messagePartType = isEmailConversation ? 'email' : 'text';

return axios.post(
postMessageApiUrl,
Expand All @@ -152,7 +154,7 @@ export default class Freshchat {
actor_type: actorType || 'bot',
message_parts: [
{
text: {
[messagePartType]: {
content: message,
},
},
Expand Down Expand Up @@ -294,8 +296,8 @@ export default class Freshchat {
/**
* Send Normal Reply.
*/
sendNormalReplyText(conversationId: string, message: string, agentId?: string): AxiosPromise<Message> {
return this.postMessage(conversationId, message, 'normal', agentId ? 'agent' : 'bot', agentId);
sendNormalReplyText(conversationId: string, message: string, agentId?: string, isEmailConversation: boolean = false): AxiosPromise<Message> {
return this.postMessage(conversationId, message, 'normal', agentId ? 'agent' : 'bot', agentId, undefined, isEmailConversation);
}

/** Update User API */
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace-models/package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/marketplace-models/src/types/PayloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum ConversationSource {
MobileSDK = 'MOBILE',
WebMessenger = 'WEBCHAT',
WhatsApp = 'WHATSAPP',
Email = 'EMAIL',
}

export enum MessageSource {
Expand Down
6 changes: 3 additions & 3 deletions packages/rule-engine/package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/rule-engine/src/recommended/actions/send-message.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 = {};

Expand All @@ -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,
Expand Down
Loading