From 40520f4272eb508050143921b22a5de379011a09 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Fri, 21 Aug 2020 15:16:10 -0300 Subject: [PATCH] [NEW][APPS-ENGINE] Implement new IPostLivechatRoomTransferred event (#18625) * Implement new IPostLivechatRoomTransferred event * Move event trigger to correct place * Update Apps-Engine version --- app/apps/server/bridges/listeners.js | 12 +++++++++++ app/livechat/server/lib/Helper.js | 30 +++++++++++++++++++++++++--- package-lock.json | 11 +++------- package.json | 2 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/apps/server/bridges/listeners.js b/app/apps/server/bridges/listeners.js index c3d481da7386..617e86801a79 100644 --- a/app/apps/server/bridges/listeners.js +++ b/app/apps/server/bridges/listeners.js @@ -1,4 +1,5 @@ import { AppInterface } from '@rocket.chat/apps-engine/definition/metadata'; +import { LivechatTransferEventType } from '@rocket.chat/apps-engine/definition/livechat'; export class AppListenerBridge { constructor(orch) { @@ -39,6 +40,7 @@ export class AppListenerBridge { case AppInterface.IPostLivechatRoomClosed: case AppInterface.IPostLivechatAgentAssigned: case AppInterface.IPostLivechatAgentUnassigned: + case AppInterface.IPostLivechatRoomTransferred: return 'livechatEvent'; case AppInterface.IUIKitInteractionHandler: return 'uiKitInteractionEvent'; @@ -100,6 +102,16 @@ export class AppListenerBridge { room: this.orch.getConverters().get('rooms').convertRoom(data.room), agent: this.orch.getConverters().get('users').convertToApp(data.user), }); + case AppInterface.IPostLivechatRoomTransferred: + const converter = data.type === LivechatTransferEventType.AGENT ? 'users' : 'departments'; + + return this.orch.getManager().getListenerManager().executeListener(inte, { + type: data.type, + room: this.orch.getConverters().get('rooms').convertById(data.room), + from: this.orch.getConverters().get(converter).convertById(data.from), + to: this.orch.getConverters().get(converter).convertById(data.to), + }); + default: const room = this.orch.getConverters().get('rooms').convertRoom(data); diff --git a/app/livechat/server/lib/Helper.js b/app/livechat/server/lib/Helper.js index 9a31fe397595..4f7d4be897f0 100644 --- a/app/livechat/server/lib/Helper.js +++ b/app/livechat/server/lib/Helper.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { MongoInternals } from 'meteor/mongo'; +import { LivechatTransferEventType } from '@rocket.chat/apps-engine/definition/livechat'; import { Messages, LivechatRooms, Rooms, Subscriptions, Users, LivechatInquiry, LivechatDepartment, LivechatDepartmentAgents } from '../../../models/server'; import { Livechat } from './Livechat'; @@ -44,8 +45,11 @@ export const createLivechatRoom = (rid, name, guest, roomInfo = {}, extraData = const roomId = Rooms.insert(room); - Apps.getBridges().getListenerBridge().livechatEvent(AppEvents.IPostLivechatRoomStarted, room); - callbacks.run('livechat.newRoom', room); + Meteor.defer(() => { + Apps.triggerEvent(AppEvents.IPostLivechatRoomStarted, room); + callbacks.run('livechat.newRoom', room); + }); + return roomId; }; @@ -166,7 +170,9 @@ export const removeAgentFromSubscription = (rid, { _id, username }) => { Subscriptions.removeByRoomIdAndUserId(rid, _id); Messages.createUserLeaveWithRoomIdAndUser(rid, { _id, username }); - Apps.getBridges().getListenerBridge().livechatEvent(AppEvents.IPostLivechatAgentUnassigned, { room, user }); + Meteor.defer(() => { + Apps.triggerEvent(AppEvents.IPostLivechatAgentUnassigned, { room, user }); + }); }; export const parseAgentCustomFields = (customFields) => { @@ -257,6 +263,15 @@ export const forwardRoomToAgent = async (room, transferData) => { removeAgentFromSubscription(rid, oldServedBy); } Messages.createUserJoinWithRoomIdAndUser(rid, { _id: servedBy._id, username: servedBy.username }); + + Meteor.defer(() => { + Apps.triggerEvent(AppEvents.IPostLivechatRoomTransferred, { + type: LivechatTransferEventType.AGENT, + room: rid, + from: oldServedBy?._id, + to: servedBy._id, + }); + }); } callbacks.run('livechat.afterForwardChatToAgent', { rid, servedBy, oldServedBy }); @@ -267,6 +282,15 @@ export const updateChatDepartment = ({ rid, newDepartmentId, oldDepartmentId }) LivechatRooms.changeDepartmentIdByRoomId(rid, newDepartmentId); LivechatInquiry.changeDepartmentIdByRoomId(rid, newDepartmentId); + Meteor.defer(() => { + Apps.triggerEvent(AppEvents.IPostLivechatRoomTransferred, { + type: LivechatTransferEventType.DEPARTMENT, + room: rid, + from: oldDepartmentId, + to: newDepartmentId, + }); + }); + return callbacks.run('livechat.afterForwardChatToDepartment', { rid, newDepartmentId, oldDepartmentId }); }; diff --git a/package-lock.json b/package-lock.json index 6237d2a66985..d226bbf260ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5240,9 +5240,9 @@ } }, "@rocket.chat/apps-engine": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.16.0.tgz", - "integrity": "sha512-hUqctTnf2g4aD3zBC3ou9nsLdKvM88m4yz8hfon1xaMEu0KScByiVESOSH0AmzfEDnkUw9DECxhURA9gsrL2KQ==", + "version": "1.17.0-beta.3607", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.17.0-beta.3607.tgz", + "integrity": "sha512-g8GwN6k6ezBPXYO4q9QqZvrXXeWva3xC62fykQPMzDBSRBT+daofqJd7QOS/LzUUveaWUB3nROKuiUVuWb110A==", "requires": { "adm-zip": "^0.4.9", "cryptiles": "^4.1.3", @@ -5253,11 +5253,6 @@ "uuid": "^3.2.1" }, "dependencies": { - "adm-zip": { - "version": "0.4.16", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.16.tgz", - "integrity": "sha512-TFi4HBKSGfIKsK5YCkKaaFG2m4PEDyViZmEwof3MTIgzimHLto6muaHVpbrljdIvIrFZzEq/p4nafOeLcYegrg==" - }, "typescript": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", diff --git a/package.json b/package.json index 5e83ebbd5540..7f82c3f62eb0 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "@nivo/heatmap": "^0.61.0", "@nivo/line": "^0.61.1", "@nivo/pie": "^0.61.1", - "@rocket.chat/apps-engine": "1.16.0", + "@rocket.chat/apps-engine": "1.17.0-beta.3607", "@rocket.chat/css-in-js": "^0.14.0", "@rocket.chat/fuselage": "^0.14.0", "@rocket.chat/fuselage-hooks": "^0.14.0",