From 91b771110aa1ff941d2076396d04ee98974c184b Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 22 Sep 2022 16:23:05 +0300 Subject: [PATCH 1/9] send message to user before sending system close message --- app.json | 2 +- endpoints/IncomingEndpoint.ts | 2 +- handler/ExecuteLivechatBlockActionHandler.ts | 2 +- handler/OnAgentUnassignedHandler.ts | 11 ++++++++--- handler/PostMessageSentHandler.ts | 2 +- lib/Helper.ts | 2 ++ lib/Room.ts | 16 ++++++++++++---- lib/SynchronousHandover.ts | 3 ++- lib/payloadAction.ts | 7 +++++-- lib/responseParameters.ts | 4 ++-- lib/sendEventToDialogFlow.ts | 3 +++ package-lock.json | 4 ++-- 12 files changed, 40 insertions(+), 18 deletions(-) diff --git a/app.json b/app.json index 5a8fc5d..6052f5d 100644 --- a/app.json +++ b/app.json @@ -19,5 +19,5 @@ "IPostLivechatRoomClosed", "IUIKitLivechatInteractionHandler" ], - "commitHash": "69de13511e790a02257140867ae181511241c394" + "commitHash": "b447f82fa635eb76438a67b340a339dd35f3f8c6" } \ No newline at end of file diff --git a/endpoints/IncomingEndpoint.ts b/endpoints/IncomingEndpoint.ts index a697c12..b3785b3 100644 --- a/endpoints/IncomingEndpoint.ts +++ b/endpoints/IncomingEndpoint.ts @@ -52,7 +52,7 @@ export class IncomingEndpoint extends ApiEndpoint { const room = (await read.getRoomReader().getById(sessionId)) as ILivechatRoom; switch (action) { case EndpointActionNames.CLOSE_CHAT: - await closeChat(modify, read, sessionId); + await closeChat(modify, read, sessionId, this.app); break; case EndpointActionNames.HANDOVER: const { actionData: { targetDepartment = '' } = {} } = endpointContent; diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 4239528..352308f 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -64,7 +64,7 @@ export class ExecuteLivechatBlockActionHandler { break; case ActionIds.CLOSE_CHAT: - await closeChat(this.modify, this.read, rid); + await closeChat(this.modify, this.read, rid, this.app); break; default: await createLivechatMessage(this.app, rid, this.read, this.modify, { text: value }, visitor); diff --git a/handler/OnAgentUnassignedHandler.ts b/handler/OnAgentUnassignedHandler.ts index 4e0d654..8662b06 100644 --- a/handler/OnAgentUnassignedHandler.ts +++ b/handler/OnAgentUnassignedHandler.ts @@ -6,6 +6,7 @@ import { IRoomCustomField } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { removeBotTypingListener } from '../lib//BotTyping'; import { createMessage } from '../lib/Message'; +import { sendCloseChatMessage } from '../lib/Room'; import { cancelAllSessionMaintenanceJobForSession } from '../lib/Scheduler'; import { agentConfigExists, getLivechatAgentConfig } from '../lib/Settings'; @@ -28,7 +29,10 @@ export class OnAgentUnassignedHandler { await createMessage(livechatRoom.id, this.read, this.modify, { text: offlineMessage }, this.app); if (livechatRoom.isOpen) { - await closeChat(this.modify, this.read, rid); + await closeChat(this.modify, this.read, rid, this.app); + } + else { + await sendCloseChatMessage(this.read, this.modify, this.app, rid); } } @@ -36,7 +40,7 @@ export class OnAgentUnassignedHandler { } } -export const closeChat = async (modify: IModify, read: IRead, rid: string) => { +export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp) => { await cancelAllSessionMaintenanceJobForSession(modify, rid); const room = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { @@ -50,7 +54,8 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string) => { const DialogflowBotUsername = room.servedBy.username; await removeBotTypingListener(modify, rid, DialogflowBotUsername); - const closeChatMessage = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); + const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); + await sendCloseChatMessage(read, modify, app, rid); const result = await modify .getUpdater() diff --git a/handler/PostMessageSentHandler.ts b/handler/PostMessageSentHandler.ts index 155c9ee..734ac99 100644 --- a/handler/PostMessageSentHandler.ts +++ b/handler/PostMessageSentHandler.ts @@ -72,7 +72,7 @@ export class PostMessageSentHandler { if (text === Message.CUSTOMER_IDLE_TIMEOUT) { await this.handleClosedByVisitor(rid, this.read); - await closeChat(this.modify, this.read, rid); + await closeChat(this.modify, this.read, rid, this.app); return; } diff --git a/lib/Helper.ts b/lib/Helper.ts index aa875bb..39842d0 100644 --- a/lib/Helper.ts +++ b/lib/Helper.ts @@ -1,3 +1,4 @@ + import { Base64 } from '../enum/Dialogflow'; export const getError = (error) => { @@ -65,3 +66,4 @@ export const escapeRegExp = (str: string): string => { }; export const stringifyError = (error: Error): string => JSON.stringify(error, Object.getOwnPropertyNames(error)); + diff --git a/lib/Room.ts b/lib/Room.ts index eb1f917..bd01e13 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -75,7 +75,7 @@ export const updateRoomLogData = async (rid: string, data: IRoomCustomField, rea }; // eslint-disable-next-line @typescript-eslint/no-unused-vars -export const closeChat = async (modify: IModify, read: IRead, rid: string, _persistence?: IPersistence) => { +export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, _persistence?: IPersistence) => { const room: ILivechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { throw new Error(Logs.INVALID_ROOM_ID); @@ -92,8 +92,8 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string, _pers const DialogflowBotUsername = room.servedBy.username; await removeBotTypingListener(modify, rid, DialogflowBotUsername); - const closeChatMessage = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); - + const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); + await sendCloseChatMessage(read, modify, app, rid); const result = await modify .getUpdater() .getLivechatUpdater() @@ -103,6 +103,14 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string, _pers } }; +export const sendCloseChatMessage = async (read: IRead, modify: IModify, app: IApp, rid: string) => { + const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); + // const closeChatMessage = 'ds'; + if (closeChatMessage?.length > 0) { + await createMessage(rid, read, modify, { text: closeChatMessage }, app); + } +} + export const performHandover = async ( app: IApp, modify: IModify, @@ -153,7 +161,7 @@ export const performHandover = async ( await createMessage(rid, read, modify, { text: offlineMessage }, app); } await removeBotTypingIndicator(); - await closeChat(modify, read, rid); + await closeChat(modify, read, rid, app); }; // Fill livechatTransferData.targetDepartment param if required diff --git a/lib/SynchronousHandover.ts b/lib/SynchronousHandover.ts index 92dac17..2e25384 100644 --- a/lib/SynchronousHandover.ts +++ b/lib/SynchronousHandover.ts @@ -6,7 +6,7 @@ import { AppSetting } from '../config/Settings'; import { IImageBlockExtended } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { createMessage } from '../lib/Message'; -import { performHandover, updateRoomCustomFields } from './Room'; +import { performHandover, sendCloseChatMessage, updateRoomCustomFields } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const incFallbackIntentAndSendResponse = async ( @@ -42,6 +42,7 @@ export const incFallbackIntentAndSendResponse = async ( console.error(Logs.EMPTY_HANDOVER_DEPARTMENT); const serviceUnavailable: string = await getLivechatAgentConfig(read, sessionId, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(sessionId, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, sessionId); return; } diff --git a/lib/payloadAction.ts b/lib/payloadAction.ts index d6ddb69..c235d47 100644 --- a/lib/payloadAction.ts +++ b/lib/payloadAction.ts @@ -25,7 +25,7 @@ import { setQueuedMessage, updatePersistentData, } from '../lib/Persistence'; -import { closeChat, performHandover, updateRoomCustomFields } from '../lib/Room'; +import { closeChat, performHandover, sendCloseChatMessage, updateRoomCustomFields } from '../lib/Room'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; import { getLivechatAgentConfig } from './Settings'; @@ -77,7 +77,7 @@ export const handlePayloadActions = async ( } else if (actionName === ActionIds.CLOSE_CHAT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (livechatRoom && livechatRoom.isOpen) { - await closeChat(modify, read, rid); + await closeChat(modify, read, rid, app); } } else if (actionName === ActionIds.NEW_WELCOME_EVENT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; @@ -115,6 +115,7 @@ export const handlePayloadActions = async ( console.error(error); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, rid); return; } } else if (actionName === ActionIds.CHANGE_LANGUAGE_CODE) { @@ -148,6 +149,7 @@ const sendChangeLanguageEvent = async (app: IApp, read: IRead, modify: IModify, console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, rid); return; } }; @@ -210,6 +212,7 @@ export const sendWelcomeEventToDialogFlow = async ( console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, rid); return; } }; diff --git a/lib/responseParameters.ts b/lib/responseParameters.ts index 40f4b80..5c3adae 100644 --- a/lib/responseParameters.ts +++ b/lib/responseParameters.ts @@ -7,6 +7,7 @@ import { getError } from '../lib/Helper'; import { getRoomAssoc, retrieveDataByAssociation, updatePersistentData } from '../lib/Persistence'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; +import { sendCloseChatMessage } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const handleParameters = async ( @@ -42,9 +43,8 @@ const sendChangeLanguageEvent = async (app: IApp, read: IRead, modify: IModify, } catch (error) { console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); - await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - + await sendCloseChatMessage(read, modify, app, rid); return; } }; diff --git a/lib/sendEventToDialogFlow.ts b/lib/sendEventToDialogFlow.ts index 82bab38..2faff11 100644 --- a/lib/sendEventToDialogFlow.ts +++ b/lib/sendEventToDialogFlow.ts @@ -7,6 +7,7 @@ import { getError } from '../lib/Helper'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; import { getRoomAssoc, retrieveDataByAssociation } from './Persistence'; +import { sendCloseChatMessage } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const sendEventToDialogFlow = async ( @@ -22,6 +23,7 @@ export const sendEventToDialogFlow = async ( console.error(Logs.INVALID_EVENT_DATA); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, rid); return; } try { @@ -38,6 +40,7 @@ export const sendEventToDialogFlow = async ( console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); + await sendCloseChatMessage(read, modify, app, rid); return; } }; diff --git a/package-lock.json b/package-lock.json index 6701bdd..7b4eb88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1022,7 +1022,7 @@ "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", "dev": true }, "lodash.merge": { @@ -1646,7 +1646,7 @@ "stack-trace": { "version": "0.0.10", "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", - "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=", "dev": true }, "string-width": { From d036be146784ca79f84f0b2cae50f3cd518cf5a9 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 22 Sep 2022 16:23:46 +0300 Subject: [PATCH 2/9] minor fixes --- handler/OnAgentUnassignedHandler.ts | 3 +-- lib/Helper.ts | 2 -- lib/Room.ts | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/handler/OnAgentUnassignedHandler.ts b/handler/OnAgentUnassignedHandler.ts index 8662b06..742837a 100644 --- a/handler/OnAgentUnassignedHandler.ts +++ b/handler/OnAgentUnassignedHandler.ts @@ -30,8 +30,7 @@ export class OnAgentUnassignedHandler { await createMessage(livechatRoom.id, this.read, this.modify, { text: offlineMessage }, this.app); if (livechatRoom.isOpen) { await closeChat(this.modify, this.read, rid, this.app); - } - else { + } else { await sendCloseChatMessage(this.read, this.modify, this.app, rid); } } diff --git a/lib/Helper.ts b/lib/Helper.ts index 39842d0..aa875bb 100644 --- a/lib/Helper.ts +++ b/lib/Helper.ts @@ -1,4 +1,3 @@ - import { Base64 } from '../enum/Dialogflow'; export const getError = (error) => { @@ -66,4 +65,3 @@ export const escapeRegExp = (str: string): string => { }; export const stringifyError = (error: Error): string => JSON.stringify(error, Object.getOwnPropertyNames(error)); - diff --git a/lib/Room.ts b/lib/Room.ts index bd01e13..0a52072 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -109,7 +109,7 @@ export const sendCloseChatMessage = async (read: IRead, modify: IModify, app: IA if (closeChatMessage?.length > 0) { await createMessage(rid, read, modify, { text: closeChatMessage }, app); } -} +}; export const performHandover = async ( app: IApp, From 3bbad293d592a44a28f8f49ffbfaeb14610b2701 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 22 Sep 2022 17:59:06 +0300 Subject: [PATCH 3/9] Changed sent close chat system message --- app.json | 2 +- endpoints/IncomingEndpoint.ts | 4 ++-- enum/Dialogflow.ts | 11 ++++++++++ handler/ExecuteLivechatBlockActionHandler.ts | 3 ++- handler/OnAgentUnassignedHandler.ts | 11 +++++----- handler/PostMessageSentHandler.ts | 4 ++-- lib/Room.ts | 23 +++++++++++--------- lib/SynchronousHandover.ts | 6 ++--- lib/payloadAction.ts | 11 +++++----- lib/responseParameters.ts | 6 ++--- lib/sendEventToDialogFlow.ts | 8 +++---- 11 files changed, 52 insertions(+), 37 deletions(-) diff --git a/app.json b/app.json index 6052f5d..e14d25a 100644 --- a/app.json +++ b/app.json @@ -19,5 +19,5 @@ "IPostLivechatRoomClosed", "IUIKitLivechatInteractionHandler" ], - "commitHash": "b447f82fa635eb76438a67b340a339dd35f3f8c6" + "commitHash": "d036be146784ca79f84f0b2cae50f3cd518cf5a9" } \ No newline at end of file diff --git a/endpoints/IncomingEndpoint.ts b/endpoints/IncomingEndpoint.ts index b3785b3..367097d 100644 --- a/endpoints/IncomingEndpoint.ts +++ b/endpoints/IncomingEndpoint.ts @@ -1,7 +1,7 @@ import { HttpStatusCode, IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { ApiEndpoint, IApiEndpointInfo, IApiRequest, IApiResponse } from '@rocket.chat/apps-engine/definition/api'; import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; -import { DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow'; +import { CloseChatDescription, DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow'; import { EndpointActionNames, IActionsEndpointContent } from '../enum/Endpoints'; import { Headers, Response } from '../enum/Http'; import { Logs } from '../enum/Logs'; @@ -52,7 +52,7 @@ export class IncomingEndpoint extends ApiEndpoint { const room = (await read.getRoomReader().getById(sessionId)) as ILivechatRoom; switch (action) { case EndpointActionNames.CLOSE_CHAT: - await closeChat(modify, read, sessionId, this.app); + await closeChat(modify, read, sessionId, this.app, CloseChatDescription.CLOSED_BY_VISITOR); break; case EndpointActionNames.HANDOVER: const { actionData: { targetDepartment = '' } = {} } = endpointContent; diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 38b8fdf..95d1af8 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -148,3 +148,14 @@ export enum Message { CLOSED_BY_VISITOR = 'Closed by visitor', CUSTOMER_IDLE_TIMEOUT = 'customer_idle_timeout', } + +export enum CloseChatDescription { + CLOSED_BY_VISITOR = 'Closed by visitor', + CUSTOMER_IDLE_TIMEOUT = 'Customer Timeout', + INVALID_TARGET_DEPARTMENT = 'Escalation failed due to invalid target department', + SAME_TARGET_DEPARTMENT = 'Escalation failed due to same target department', + LIVEAGENT_BOT_OFFLINE_OR_DISABLED = 'Escalation failed due to liveagent bot offline or disabled', + NETWORK_OR_APP_ERROR = 'Escalation failed due to network or app error', + AGENT_UNASSIGNED = 'Agent is unassigned', + INVALID_EVENT_DATA = "Invalid Dialogflow event data" +} diff --git a/handler/ExecuteLivechatBlockActionHandler.ts b/handler/ExecuteLivechatBlockActionHandler.ts index 352308f..41033d3 100644 --- a/handler/ExecuteLivechatBlockActionHandler.ts +++ b/handler/ExecuteLivechatBlockActionHandler.ts @@ -6,6 +6,7 @@ import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/ import { IUser } from '@rocket.chat/apps-engine/definition/users'; import { AppSetting, DefaultMessage } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; +import { CloseChatDescription } from '../enum/Dialogflow'; import { createLivechatMessage, createMessage, deleteAllActionBlocks } from '../lib/Message'; import { closeChat, performHandover } from '../lib/Room'; import { getLivechatAgentConfig } from '../lib/Settings'; @@ -64,7 +65,7 @@ export class ExecuteLivechatBlockActionHandler { break; case ActionIds.CLOSE_CHAT: - await closeChat(this.modify, this.read, rid, this.app); + await closeChat(this.modify, this.read, rid, this.app, CloseChatDescription.CLOSED_BY_VISITOR); break; default: await createLivechatMessage(this.app, rid, this.read, this.modify, { text: value }, visitor); diff --git a/handler/OnAgentUnassignedHandler.ts b/handler/OnAgentUnassignedHandler.ts index 742837a..c66b787 100644 --- a/handler/OnAgentUnassignedHandler.ts +++ b/handler/OnAgentUnassignedHandler.ts @@ -1,8 +1,8 @@ import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { ILivechatEventContext, ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; -import { AppSetting, DefaultMessage } from '../config/Settings'; -import { IRoomCustomField } from '../enum/Dialogflow'; +import { AppSetting } from '../config/Settings'; +import { CloseChatDescription, IRoomCustomField } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { removeBotTypingListener } from '../lib//BotTyping'; import { createMessage } from '../lib/Message'; @@ -29,7 +29,7 @@ export class OnAgentUnassignedHandler { await createMessage(livechatRoom.id, this.read, this.modify, { text: offlineMessage }, this.app); if (livechatRoom.isOpen) { - await closeChat(this.modify, this.read, rid, this.app); + await closeChat(this.modify, this.read, rid, this.app, CloseChatDescription.AGENT_UNASSIGNED); } else { await sendCloseChatMessage(this.read, this.modify, this.app, rid); } @@ -39,7 +39,7 @@ export class OnAgentUnassignedHandler { } } -export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp) => { +export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, closeChatDesc?: string) => { await cancelAllSessionMaintenanceJobForSession(modify, rid); const room = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { @@ -53,13 +53,12 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string, app: const DialogflowBotUsername = room.servedBy.username; await removeBotTypingListener(modify, rid, DialogflowBotUsername); - const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); await sendCloseChatMessage(read, modify, app, rid); const result = await modify .getUpdater() .getLivechatUpdater() - .closeRoom(room, closeChatMessage ? closeChatMessage : DefaultMessage.DEFAULT_DialogflowCloseChatMessage); + .closeRoom(room, closeChatDesc || ''); if (!result) { throw new Error(Logs.CLOSE_CHAT_REQUEST_FAILED_ERROR); } diff --git a/handler/PostMessageSentHandler.ts b/handler/PostMessageSentHandler.ts index 734ac99..4133236 100644 --- a/handler/PostMessageSentHandler.ts +++ b/handler/PostMessageSentHandler.ts @@ -3,7 +3,7 @@ import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { ILivechatMessage, ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; import { RoomType } from '@rocket.chat/apps-engine/definition/rooms'; import { AppSetting } from '../config/Settings'; -import { DialogflowRequestType, IDialogflowMessage, IDialogflowQuickReplies, LanguageCode, Message } from '../enum/Dialogflow'; +import { CloseChatDescription, DialogflowRequestType, IDialogflowMessage, IDialogflowQuickReplies, LanguageCode, Message } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { botTypingListener, removeBotTypingListener } from '../lib//BotTyping'; @@ -72,7 +72,7 @@ export class PostMessageSentHandler { if (text === Message.CUSTOMER_IDLE_TIMEOUT) { await this.handleClosedByVisitor(rid, this.read); - await closeChat(this.modify, this.read, rid, this.app); + await closeChat(this.modify, this.read, rid, this.app, CloseChatDescription.CUSTOMER_IDLE_TIMEOUT); return; } diff --git a/lib/Room.ts b/lib/Room.ts index 0a52072..8d16ef5 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -4,7 +4,7 @@ import { IDepartment, ILivechatRoom, ILivechatTransferData, IVisitor } from '@ro import { IButtonElement } from '@rocket.chat/apps-engine/definition/uikit'; import { AppSetting, DefaultMessage } from '../config/Settings'; import { EventName } from '../enum/Analytics'; -import { IImageBlockExtended, IRoomCustomField } from '../enum/Dialogflow'; +import { CloseChatDescription, IImageBlockExtended, IRoomCustomField } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { JobName } from '../enum/Scheduler'; import { getEventData } from '../lib/Analytics'; @@ -75,7 +75,7 @@ export const updateRoomLogData = async (rid: string, data: IRoomCustomField, rea }; // eslint-disable-next-line @typescript-eslint/no-unused-vars -export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, _persistence?: IPersistence) => { +export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, closeChatDesc?: string, _persistence?: IPersistence) => { const room: ILivechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { throw new Error(Logs.INVALID_ROOM_ID); @@ -92,12 +92,11 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string, app: const DialogflowBotUsername = room.servedBy.username; await removeBotTypingListener(modify, rid, DialogflowBotUsername); - const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); await sendCloseChatMessage(read, modify, app, rid); const result = await modify .getUpdater() .getLivechatUpdater() - .closeRoom(room, closeChatMessage ? closeChatMessage : DefaultMessage.DEFAULT_DialogflowCloseChatMessage); + .closeRoom(room, closeChatDesc || ''); if (!result) { throw new Error(Logs.CLOSE_CHAT_REQUEST_FAILED_ERROR); } @@ -109,7 +108,7 @@ export const sendCloseChatMessage = async (read: IRead, modify: IModify, app: IA if (closeChatMessage?.length > 0) { await createMessage(rid, read, modify, { text: closeChatMessage }, app); } -}; +} export const performHandover = async ( app: IApp, @@ -145,7 +144,7 @@ export const performHandover = async ( await removeBotTypingListener(modify, rid, DialogflowBotUsername); }; - const handleHandoverFailure = async (error?: string) => { + const handleHandoverFailure = async (error?: string, closeChatDesc?: string) => { const offlineMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowHandoverFailedMessage); const handoverFailure = { error: error || offlineMessage, @@ -161,7 +160,7 @@ export const performHandover = async ( await createMessage(rid, read, modify, { text: offlineMessage }, app); } await removeBotTypingIndicator(); - await closeChat(modify, read, rid, app); + await closeChat(modify, read, rid, app, closeChatDesc); }; // Fill livechatTransferData.targetDepartment param if required @@ -169,7 +168,7 @@ export const performHandover = async ( const targetDepartment: IDepartment = (await read.getLivechatReader().getLivechatDepartmentByIdOrName(targetDepartmentName)) as IDepartment; if (!targetDepartment) { modify.getAnalytics().sendEvent(getEventData(rid, EventName.ESCALATION_FAILED_DUE_TO_INVALID_TARGET_DEPARTMENT)); - await handleHandoverFailure(Logs.INVALID_DEPARTMENT_NAME); + await handleHandoverFailure(Logs.INVALID_DEPARTMENT_NAME, CloseChatDescription.INVALID_TARGET_DEPARTMENT); return false; } livechatTransferData.targetDepartment = targetDepartment.id; @@ -179,7 +178,7 @@ export const performHandover = async ( const serviceOnline = await read.getLivechatReader().isOnlineAsync(livechatTransferData.targetDepartment); if (!serviceOnline) { modify.getAnalytics().sendEvent(getEventData(rid, EventName.ESCALATION_FAILED_DUE_TO_LIVEAGENT_BOT_OFFLINE_OR_DISABLED)); - await handleHandoverFailure(); + await handleHandoverFailure('', CloseChatDescription.LIVEAGENT_BOT_OFFLINE_OR_DISABLED); return false; } @@ -194,6 +193,7 @@ export const performHandover = async ( await createMessage(rid, read, modify, { text: DefaultMessage.DEFAULT_DialogflowHandoverMessage }, app); } + let closeChatDesc; const result = await modify .getUpdater() .getLivechatUpdater() @@ -201,17 +201,20 @@ export const performHandover = async ( .catch((error) => { const { error: errorName, message: errorMessage } = error; let eventName = EventName.ESCALATION_FAILED_DUE_TO_NETWORK_OR_APP_ERROR; + closeChatDesc = CloseChatDescription.NETWORK_OR_APP_ERROR; if (errorName === 'error-forwarding-chat-same-department') { eventName = EventName.ESCALATION_FAILED_DUE_TO_SAME_TARGET_DEPARTMENT; + closeChatDesc = CloseChatDescription.SAME_TARGET_DEPARTMENT; } else if (errorName === 'error-user-is-offline') { eventName = EventName.ESCALATION_FAILED_DUE_TO_LIVEAGENT_BOT_OFFLINE_OR_DISABLED; + closeChatDesc = CloseChatDescription.LIVEAGENT_BOT_OFFLINE_OR_DISABLED; } modify.getAnalytics().sendEvent(getEventData(rid, eventName, { error: errorMessage })); throw new Error(`${Logs.HANDOVER_REQUEST_FAILED_ERROR} ${error}`); }); if (!result) { - await handleHandoverFailure(); + await handleHandoverFailure('', closeChatDesc); return false; } diff --git a/lib/SynchronousHandover.ts b/lib/SynchronousHandover.ts index 2e25384..f82efae 100644 --- a/lib/SynchronousHandover.ts +++ b/lib/SynchronousHandover.ts @@ -3,10 +3,10 @@ import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; import { IButtonElement } from '@rocket.chat/apps-engine/definition/uikit'; import { AppSetting } from '../config/Settings'; -import { IImageBlockExtended } from '../enum/Dialogflow'; +import { CloseChatDescription, IImageBlockExtended } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { createMessage } from '../lib/Message'; -import { performHandover, sendCloseChatMessage, updateRoomCustomFields } from './Room'; +import { closeChat, performHandover, updateRoomCustomFields } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const incFallbackIntentAndSendResponse = async ( @@ -42,7 +42,7 @@ export const incFallbackIntentAndSendResponse = async ( console.error(Logs.EMPTY_HANDOVER_DEPARTMENT); const serviceUnavailable: string = await getLivechatAgentConfig(read, sessionId, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(sessionId, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, sessionId); + await closeChat(modify, read, sessionId, app, CloseChatDescription.INVALID_TARGET_DEPARTMENT); return; } diff --git a/lib/payloadAction.ts b/lib/payloadAction.ts index c235d47..fa13a35 100644 --- a/lib/payloadAction.ts +++ b/lib/payloadAction.ts @@ -4,6 +4,7 @@ import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat'; import { AppSetting } from '../config/Settings'; import { ActionIds } from '../enum/ActionIds'; import { + CloseChatDescription, DialogflowRequestType, IDialogflowAction, IDialogflowCustomFields, @@ -25,7 +26,7 @@ import { setQueuedMessage, updatePersistentData, } from '../lib/Persistence'; -import { closeChat, performHandover, sendCloseChatMessage, updateRoomCustomFields } from '../lib/Room'; +import { closeChat, performHandover, updateRoomCustomFields } from '../lib/Room'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; import { getLivechatAgentConfig } from './Settings'; @@ -77,7 +78,7 @@ export const handlePayloadActions = async ( } else if (actionName === ActionIds.CLOSE_CHAT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (livechatRoom && livechatRoom.isOpen) { - await closeChat(modify, read, rid, app); + await closeChat(modify, read, rid, app, CloseChatDescription.CLOSED_BY_VISITOR); } } else if (actionName === ActionIds.NEW_WELCOME_EVENT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; @@ -115,7 +116,7 @@ export const handlePayloadActions = async ( console.error(error); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read, rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } } else if (actionName === ActionIds.CHANGE_LANGUAGE_CODE) { @@ -149,7 +150,7 @@ const sendChangeLanguageEvent = async (app: IApp, read: IRead, modify: IModify, console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read, rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } }; @@ -212,7 +213,7 @@ export const sendWelcomeEventToDialogFlow = async ( console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read, rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } }; diff --git a/lib/responseParameters.ts b/lib/responseParameters.ts index 5c3adae..cdd2411 100644 --- a/lib/responseParameters.ts +++ b/lib/responseParameters.ts @@ -1,13 +1,13 @@ import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { AppSetting } from '../config/Settings'; -import { DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow'; +import { CloseChatDescription, DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { getError } from '../lib/Helper'; import { getRoomAssoc, retrieveDataByAssociation, updatePersistentData } from '../lib/Persistence'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; -import { sendCloseChatMessage } from './Room'; +import { closeChat } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const handleParameters = async ( @@ -44,7 +44,7 @@ const sendChangeLanguageEvent = async (app: IApp, read: IRead, modify: IModify, console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read,rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } }; diff --git a/lib/sendEventToDialogFlow.ts b/lib/sendEventToDialogFlow.ts index 2faff11..20b4cb3 100644 --- a/lib/sendEventToDialogFlow.ts +++ b/lib/sendEventToDialogFlow.ts @@ -1,13 +1,13 @@ import { IHttp, IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { AppSetting } from '../config/Settings'; -import { DialogflowRequestType, IDialogflowMessage, IMessageParameters, LanguageCode } from '../enum/Dialogflow'; +import { CloseChatDescription, DialogflowRequestType, IDialogflowMessage, IMessageParameters, LanguageCode } from '../enum/Dialogflow'; import { Logs } from '../enum/Logs'; import { getError } from '../lib/Helper'; import { Dialogflow } from './Dialogflow'; import { createDialogflowMessage, createMessage } from './Message'; import { getRoomAssoc, retrieveDataByAssociation } from './Persistence'; -import { sendCloseChatMessage } from './Room'; +import { closeChat } from './Room'; import { getLivechatAgentConfig } from './Settings'; export const sendEventToDialogFlow = async ( @@ -23,7 +23,7 @@ export const sendEventToDialogFlow = async ( console.error(Logs.INVALID_EVENT_DATA); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read,rid, app, CloseChatDescription.INVALID_EVENT_DATA); return; } try { @@ -40,7 +40,7 @@ export const sendEventToDialogFlow = async ( console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await sendCloseChatMessage(read, modify, app, rid); + await closeChat(modify, read, rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } }; From ce9cf71376e3b9a7ecac55a729f271940644ab7d Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 22 Sep 2022 18:01:06 +0300 Subject: [PATCH 4/9] minor fixes --- enum/Dialogflow.ts | 2 +- lib/Room.ts | 2 +- lib/responseParameters.ts | 2 +- lib/sendEventToDialogFlow.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 95d1af8..07d0605 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -157,5 +157,5 @@ export enum CloseChatDescription { LIVEAGENT_BOT_OFFLINE_OR_DISABLED = 'Escalation failed due to liveagent bot offline or disabled', NETWORK_OR_APP_ERROR = 'Escalation failed due to network or app error', AGENT_UNASSIGNED = 'Agent is unassigned', - INVALID_EVENT_DATA = "Invalid Dialogflow event data" + INVALID_EVENT_DATA = 'Invalid Dialogflow event data', } diff --git a/lib/Room.ts b/lib/Room.ts index 8d16ef5..1d9e097 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -108,7 +108,7 @@ export const sendCloseChatMessage = async (read: IRead, modify: IModify, app: IA if (closeChatMessage?.length > 0) { await createMessage(rid, read, modify, { text: closeChatMessage }, app); } -} +}; export const performHandover = async ( app: IApp, diff --git a/lib/responseParameters.ts b/lib/responseParameters.ts index cdd2411..3411b74 100644 --- a/lib/responseParameters.ts +++ b/lib/responseParameters.ts @@ -44,7 +44,7 @@ const sendChangeLanguageEvent = async (app: IApp, read: IRead, modify: IModify, console.error(`${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getError(error)}`); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await closeChat(modify, read,rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); + await closeChat(modify, read, rid, app, CloseChatDescription.NETWORK_OR_APP_ERROR); return; } }; diff --git a/lib/sendEventToDialogFlow.ts b/lib/sendEventToDialogFlow.ts index 20b4cb3..459ac4d 100644 --- a/lib/sendEventToDialogFlow.ts +++ b/lib/sendEventToDialogFlow.ts @@ -23,7 +23,7 @@ export const sendEventToDialogFlow = async ( console.error(Logs.INVALID_EVENT_DATA); const serviceUnavailable: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowServiceUnavailableMessage); await createMessage(rid, read, modify, { text: serviceUnavailable }, app); - await closeChat(modify, read,rid, app, CloseChatDescription.INVALID_EVENT_DATA); + await closeChat(modify, read, rid, app, CloseChatDescription.INVALID_EVENT_DATA); return; } try { From b45609488a417d7b5c38930ef0ef8a7e72a0e73b Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Fri, 23 Sep 2022 19:25:28 +0300 Subject: [PATCH 5/9] Removed debugging code --- lib/Room.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Room.ts b/lib/Room.ts index 1d9e097..fba68d9 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -104,7 +104,6 @@ export const closeChat = async (modify: IModify, read: IRead, rid: string, app: export const sendCloseChatMessage = async (read: IRead, modify: IModify, app: IApp, rid: string) => { const closeChatMessage: string = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowCloseChatMessage); - // const closeChatMessage = 'ds'; if (closeChatMessage?.length > 0) { await createMessage(rid, read, modify, { text: closeChatMessage }, app); } From 6102356e7fb3cef97a1a80325bf46b43bacb3152 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 29 Sep 2022 14:35:01 +0300 Subject: [PATCH 6/9] Fixed close chat description for closing chat from incoming API/Endpoint case --- endpoints/IncomingEndpoint.ts | 2 +- enum/Dialogflow.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/endpoints/IncomingEndpoint.ts b/endpoints/IncomingEndpoint.ts index 367097d..8f61db3 100644 --- a/endpoints/IncomingEndpoint.ts +++ b/endpoints/IncomingEndpoint.ts @@ -52,7 +52,7 @@ export class IncomingEndpoint extends ApiEndpoint { const room = (await read.getRoomReader().getById(sessionId)) as ILivechatRoom; switch (action) { case EndpointActionNames.CLOSE_CHAT: - await closeChat(modify, read, sessionId, this.app, CloseChatDescription.CLOSED_BY_VISITOR); + await closeChat(modify, read, sessionId, this.app, CloseChatDescription.CLOSED_BY_API_ENDPOINT); break; case EndpointActionNames.HANDOVER: const { actionData: { targetDepartment = '' } = {} } = endpointContent; diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 07d0605..8b726f8 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -158,4 +158,5 @@ export enum CloseChatDescription { NETWORK_OR_APP_ERROR = 'Escalation failed due to network or app error', AGENT_UNASSIGNED = 'Agent is unassigned', INVALID_EVENT_DATA = 'Invalid Dialogflow event data', + CLOSED_BY_API_ENDPOINT = 'Closed by incoming API/Endpoint', } From 3aebc17f00b24249c10892a30e46b36108e00f74 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Tue, 4 Oct 2022 18:20:50 +0300 Subject: [PATCH 7/9] Added 'Closed by agnet' CloseChatDescription --- enum/Dialogflow.ts | 1 + lib/payloadAction.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 8b726f8..4ce1232 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -151,6 +151,7 @@ export enum Message { export enum CloseChatDescription { CLOSED_BY_VISITOR = 'Closed by visitor', + CLOSED_BY_AGENT = 'Closed by agent', CUSTOMER_IDLE_TIMEOUT = 'Customer Timeout', INVALID_TARGET_DEPARTMENT = 'Escalation failed due to invalid target department', SAME_TARGET_DEPARTMENT = 'Escalation failed due to same target department', diff --git a/lib/payloadAction.ts b/lib/payloadAction.ts index fa13a35..2b94225 100644 --- a/lib/payloadAction.ts +++ b/lib/payloadAction.ts @@ -78,7 +78,7 @@ export const handlePayloadActions = async ( } else if (actionName === ActionIds.CLOSE_CHAT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (livechatRoom && livechatRoom.isOpen) { - await closeChat(modify, read, rid, app, CloseChatDescription.CLOSED_BY_VISITOR); + await closeChat(modify, read, rid, app, CloseChatDescription.CLOSED_BY_AGENT); } } else if (actionName === ActionIds.NEW_WELCOME_EVENT) { const livechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; From cc75af45c97be731cfcfe03290d86f3da88bfb33 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Wed, 5 Oct 2022 15:53:08 +0300 Subject: [PATCH 8/9] Clarifications on CloseChatDescription messages --- enum/Dialogflow.ts | 4 ++-- lib/Room.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index 4ce1232..b0af923 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -151,12 +151,12 @@ export enum Message { export enum CloseChatDescription { CLOSED_BY_VISITOR = 'Closed by visitor', - CLOSED_BY_AGENT = 'Closed by agent', + CLOSED_BY_AGENT = 'Closed by agent bot', CUSTOMER_IDLE_TIMEOUT = 'Customer Timeout', INVALID_TARGET_DEPARTMENT = 'Escalation failed due to invalid target department', SAME_TARGET_DEPARTMENT = 'Escalation failed due to same target department', LIVEAGENT_BOT_OFFLINE_OR_DISABLED = 'Escalation failed due to liveagent bot offline or disabled', - NETWORK_OR_APP_ERROR = 'Escalation failed due to network or app error', + NETWORK_OR_APP_ERROR = 'Escalation failed due to network or DF app error', AGENT_UNASSIGNED = 'Agent is unassigned', INVALID_EVENT_DATA = 'Invalid Dialogflow event data', CLOSED_BY_API_ENDPOINT = 'Closed by incoming API/Endpoint', diff --git a/lib/Room.ts b/lib/Room.ts index fba68d9..b226aae 100644 --- a/lib/Room.ts +++ b/lib/Room.ts @@ -1,4 +1,4 @@ -import { IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; +import { IModify, IRead } from '@rocket.chat/apps-engine/definition/accessors'; import { IApp } from '@rocket.chat/apps-engine/definition/IApp'; import { IDepartment, ILivechatRoom, ILivechatTransferData, IVisitor } from '@rocket.chat/apps-engine/definition/livechat'; import { IButtonElement } from '@rocket.chat/apps-engine/definition/uikit'; @@ -74,8 +74,7 @@ export const updateRoomLogData = async (rid: string, data: IRoomCustomField, rea } }; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, closeChatDesc?: string, _persistence?: IPersistence) => { +export const closeChat = async (modify: IModify, read: IRead, rid: string, app: IApp, closeChatDesc?: string) => { const room: ILivechatRoom = (await read.getRoomReader().getById(rid)) as ILivechatRoom; if (!room) { throw new Error(Logs.INVALID_ROOM_ID); From 4fc90cb1e1901f45876b871b5812979f01f6669e Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Thu, 6 Oct 2022 13:53:46 +0300 Subject: [PATCH 9/9] Minor change to CloseChatDescription --- enum/Dialogflow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enum/Dialogflow.ts b/enum/Dialogflow.ts index b0af923..1909230 100644 --- a/enum/Dialogflow.ts +++ b/enum/Dialogflow.ts @@ -151,7 +151,7 @@ export enum Message { export enum CloseChatDescription { CLOSED_BY_VISITOR = 'Closed by visitor', - CLOSED_BY_AGENT = 'Closed by agent bot', + CLOSED_BY_AGENT = 'Closed by DF agent', CUSTOMER_IDLE_TIMEOUT = 'Customer Timeout', INVALID_TARGET_DEPARTMENT = 'Escalation failed due to invalid target department', SAME_TARGET_DEPARTMENT = 'Escalation failed due to same target department',