Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/livechat/server/api/lib/livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 1 addition & 6 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
renatobecker-zz marked this conversation as resolved.
Show resolved Hide resolved
if (agents.count() === 0) {
return false;
}
Expand Down
32 changes: 22 additions & 10 deletions app/livechat/server/lib/QueueMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down