From 159b0b063017f2d21bf174aba459dc1c68e04159 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Thu, 21 Sep 2023 12:23:44 -0600 Subject: [PATCH] types of endpoint --- .../app/livechat/server/hooks/checkMAC.ts | 25 +++++++++++++++++++ apps/meteor/app/livechat/server/index.ts | 1 + packages/rest-typings/src/v1/omnichannel.ts | 3 +++ 3 files changed, 29 insertions(+) create mode 100644 apps/meteor/app/livechat/server/hooks/checkMAC.ts diff --git a/apps/meteor/app/livechat/server/hooks/checkMAC.ts b/apps/meteor/app/livechat/server/hooks/checkMAC.ts new file mode 100644 index 0000000000000..56d5b26a15980 --- /dev/null +++ b/apps/meteor/app/livechat/server/hooks/checkMAC.ts @@ -0,0 +1,25 @@ +import { Omnichannel } from '@rocket.chat/core-services'; +import { isEditedMessage } from '@rocket.chat/core-typings'; + +import { callbacks } from '../../../../lib/callbacks'; + +callbacks.add('beforeSaveMessage', async (message, room) => { + if (!room || room.t !== 'l') { + return message; + } + + if (isEditedMessage(message)) { + return message; + } + + if (message.token) { + return message; + } + + const canSendMessage = await Omnichannel.isRoomEnabled(room); + if (!canSendMessage) { + throw new Error('error-mac-limit-reached'); + } + + return message; +}); diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 7d91679669531..b6f4e98af6dbb 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -16,6 +16,7 @@ import './hooks/saveContactLastChat'; import './hooks/saveLastMessageToInquiry'; import './hooks/afterUserActions'; import './hooks/afterAgentRemoved'; +import './hooks/checkMAC'; import './methods/addAgent'; import './methods/addManager'; import './methods/changeLivechatStatus'; diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index bebea2856861f..98091043ff568 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -3699,6 +3699,9 @@ export type OmnichannelEndpoints = { value: string | number; }[]; }; + '/v1/omnichannel/mac/check': { + GET: () => { onLimit: boolean }; + }; } & { // EE '/v1/livechat/analytics/agents/average-service-time': {