From b5e3802f2e66649134367bea5cbb1b2608e02df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Thu, 20 Sep 2018 22:29:51 +0200 Subject: [PATCH] [NEW] Livechat notifications on new incoming inquiries for guest-pool (#10588) --- packages/rocketchat-lib/server/lib/index.js | 2 ++ .../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, 29 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/index.js b/packages/rocketchat-lib/server/lib/index.js index 5910b28d6279..7d9a272a1a8d 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, + sendNotification, }; diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 3b864594b9d1..398207532816 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -266,3 +266,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 b216e9c6dd12..77d55d8e052b 100644 --- a/packages/rocketchat-livechat/.app/i18n/en.i18n.json +++ b/packages/rocketchat-livechat/.app/i18n/en.i18n.json @@ -17,6 +17,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", @@ -46,4 +47,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 fabca38ec345..a2d613b00964 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: @@ -149,6 +150,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) {