[IMPROVE] Ignore agent status when queuing incoming livechats via Guest Pool (#13818)

* Several improvements regarding Guest Pool routing method.

* rename const `agents` to `allAgents`.
pull/13863/head
Renato Becker 6 years ago committed by GitHub
parent 90fc64321a
commit 920f0a151a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/livechat/server/api/lib/livechat.js
  2. 7
      app/livechat/server/lib/Livechat.js
  3. 32
      app/livechat/server/lib/QueueMethods.js

@ -3,9 +3,11 @@ import { Random } from 'meteor/random';
import { Users, Rooms, LivechatVisitors, LivechatDepartment, LivechatTrigger } from '../../../../models';
import _ from 'underscore';
import { Livechat } from '../../lib/Livechat';
import { settings as rcSettings } from '../../../../settings';
export function online() {
return Users.findOnlineAgents().count() > 0;
const onlineAgents = Livechat.getOnlineAgents();
return (onlineAgents && onlineAgents.count() > 0) || rcSettings.get('Livechat_guest_pool_with_no_agents');
}
export function findTriggers() {

@ -533,12 +533,7 @@ export const Livechat = {
const agentIds = [];
// get the agents of the department
if (departmentId) {
let agents = Livechat.getOnlineAgents(departmentId);
if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) {
agents = Livechat.getAgents(departmentId);
}
const agents = Livechat.getAgents(departmentId);
if (agents.count() === 0) {
return false;
}

@ -91,21 +91,23 @@ export const QueueMethods = {
* only the client until paired with an agent
*/
'Guest_Pool'(guest, message, roomInfo) {
let agents = Livechat.getOnlineAgents(guest.department);
if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) {
agents = Livechat.getAgents(guest.department);
const onlineAgents = Livechat.getOnlineAgents(guest.department);
if (settings.get('Livechat_guest_pool_with_no_agents') === false) {
if (!onlineAgents || onlineAgents.count() === 0) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}
}
if (agents.count() === 0) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
const allAgents = Livechat.getAgents(guest.department);
if (allAgents.count() === 0) {
throw new Meteor.Error('no-agent-available', 'Sorry, no available agents.');
}
Rooms.updateLivechatRoomCount();
const agentIds = [];
agents.forEach((agent) => {
allAgents.forEach((agent) => {
if (guest.department) {
agentIds.push(agent.agentId);
} else {
@ -157,16 +159,26 @@ export const QueueMethods = {
LivechatInquiry.insert(inquiry);
Rooms.insert(room);
// Alert the agents of the queued request
agentIds.forEach((agentId) => {
// Alert only the online agents of the queued request
onlineAgents.forEach((agent) => {
const { _id, active, emails, language, status, statusConnection, username } = agent;
sendNotification({
// fake a subscription in order to make use of the function defined above
subscription: {
rid: room._id,
t : room.t,
u: {
_id : agentId,
_id,
},
receiver: [{
active,
emails,
language,
status,
statusConnection,
username,
}],
},
sender: room.v,
hasMentionToAll: true, // consider all agents to be in the room

Loading…
Cancel
Save