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

[FIX] Check agent status when starting a new conversation with an agent assigned #16618

Merged
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
10 changes: 10 additions & 0 deletions app/livechat/server/lib/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,13 @@ export const normalizeTransferredByData = (transferredBy, room) => {
type,
};
};

export const checkServiceStatus = ({ guest, agent }) => {
if (agent) {
const { agentId } = agent;
const users = Users.findOnlineAgents(agentId);
return users && users.count() > 0;
}

return Livechat.online(guest.department);
};
5 changes: 2 additions & 3 deletions app/livechat/server/lib/QueueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';

import { LivechatRooms, LivechatInquiry } from '../../../models/server';
import { createLivechatRoom, createLivechatInquiry } from './Helper';
import { checkServiceStatus, createLivechatRoom, createLivechatInquiry } from './Helper';
import { callbacks } from '../../../callbacks/server';
import { RoutingManager } from './RoutingManager';
import { Livechat } from './Livechat';

export const QueueManager = {
async requestRoom({ guest, message, roomInfo, agent }) {
Expand All @@ -19,7 +18,7 @@ export const QueueManager = {
department: Match.Maybe(String),
}));

if (!Livechat.online(guest.department)) {
if (!checkServiceStatus({ guest, agent })) {
sampaiodiego marked this conversation as resolved.
Show resolved Hide resolved
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');
}

Expand Down
4 changes: 2 additions & 2 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class Users extends Base {
return this.update(_id, update);
}

findOnlineAgents() {
const query = queryStatusAgentOnline();
findOnlineAgents(agentId) {
const query = queryStatusAgentOnline(agentId && { _id: agentId });

return this.find(query);
}
Expand Down