From 0640b78395b580e0ded88bbfe7801394977109d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Wed, 12 Sep 2018 17:38:09 +0200 Subject: [PATCH] [Livechat] Notify agents when a new chat is queued --- packages/rocketchat-lib/server/lib/index.js | 4 +++- .../server/lib/sendNotificationsOnMessage.js | 2 ++ .../.app/i18n/de.i18n.json | 3 ++- .../.app/i18n/en.i18n.json | 3 ++- .../server/lib/QueueMethods.js | 21 +++++++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/index.js b/packages/rocketchat-lib/server/lib/index.js index 0a29fe0b32d2..1b06a6739780 100644 --- a/packages/rocketchat-lib/server/lib/index.js +++ b/packages/rocketchat-lib/server/lib/index.js @@ -7,9 +7,11 @@ */ import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig } from '../../lib/RoomTypeConfig'; +import { sendNotification } from './sendNotificationsOnMessage.js'; export { RoomSettingsEnum, RoomTypeConfig, - RoomTypeRouteConfig + RoomTypeRouteConfig, + sendNotification }; diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 2769f4c91fab..40176fd965f6 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -260,3 +260,5 @@ function sendAllNotifications(message, room) { } RocketChat.callbacks.add('afterSaveMessage', sendAllNotifications, RocketChat.callbacks.priority.LOW, 'sendNotificationsOnMessage'); + +export {sendNotification}; diff --git a/packages/rocketchat-livechat/.app/i18n/de.i18n.json b/packages/rocketchat-livechat/.app/i18n/de.i18n.json index 4756f9833272..126ad03efe1c 100644 --- a/packages/rocketchat-livechat/.app/i18n/de.i18n.json +++ b/packages/rocketchat-livechat/.app/i18n/de.i18n.json @@ -16,6 +16,7 @@ "How_satisfied_were_you_with_this_chat": "Wie zufrieden sind Sie mit diesem Gespräch?", "Installation": "Installation", "New_messages": "Neue Nachrichten", + "New_livechat_in_queue": "Neuer Chat in der Wartschlange", "No": "Nein", "Options": "Optionen", "Please_answer_survey": "Bitte nehmen Sie sich einen Moment Zeit, um kurz einige Fragen zu dem Gespräch zu beantworten.", @@ -44,4 +45,4 @@ "Yes": "Ja", "You": "Sie", "You_must_complete_all_fields": "Sie müssen alle Felder ausfüllen" -} \ No newline at end of file +} diff --git a/packages/rocketchat-livechat/.app/i18n/en.i18n.json b/packages/rocketchat-livechat/.app/i18n/en.i18n.json index f0e58143a03d..1211ed5eacd7 100644 --- a/packages/rocketchat-livechat/.app/i18n/en.i18n.json +++ b/packages/rocketchat-livechat/.app/i18n/en.i18n.json @@ -16,6 +16,7 @@ "How_satisfied_were_you_with_this_chat": "How satisfied were you with this chat?", "Installation": "Installation", "New_messages": "New messages", + "New_livechat_in_queue": "New chat in queue", "No": "No", "Options": "Options", "Please_answer_survey": "Please take a moment to answer a quick survey about this chat", @@ -44,4 +45,4 @@ "Yes": "Yes", "You": "You", "You_must_complete_all_fields": "You must complete all fields" -} \ No newline at end of file +} diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index d167f18df62a..0ad2d4f681dc 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -1,4 +1,5 @@ import _ from 'underscore'; +import {sendNotification} from 'meteor/rocketchat:lib'; RocketChat.QueueMethods = { /* Least Amount Queuing method: @@ -141,6 +142,26 @@ RocketChat.QueueMethods = { RocketChat.models.LivechatInquiry.insert(inquiry); RocketChat.models.Rooms.insert(room); + // Alert the agents of the queued request + agentIds.forEach((agentId) => { + sendNotification({ + //fake a subscription in order to make use of the function defined above + subscription: { + rid: room._id, + t : room.t, + u: { + _id : agentId + } + }, + sender: room.v, + hasMentionToAll: true, //consider all agents to be in the room + hasMentionToHere: false, + message: Object.assign(message, {u: room.v}), + notificationMessage: message.msg, + room: Object.assign(room, {name: TAPi18n.__('New_livechat_in_queue')}), + mentionIds: [] + }); + }); return room; }, 'External'(guest, message, roomInfo, agent) {