Skip to content

Commit

Permalink
fix: Allow bot agents to skip the queue (#34987)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored Jan 29, 2025
1 parent 763c097 commit 755c26f
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-emus-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes a behavior in Omnichannel that was causing bot agents to be waiting in the queue, when they should always skip it.
7 changes: 6 additions & 1 deletion apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export class QueueManager {
return LivechatInquiryStatus.QUEUED;
}

// bots should be able to skip the queue and the routing check
if (agent && (await allowAgentSkipQueue(agent))) {
return LivechatInquiryStatus.READY;
}

if (settings.get('Livechat_waiting_queue')) {
return LivechatInquiryStatus.QUEUED;
}
Expand All @@ -139,7 +144,7 @@ export class QueueManager {
return LivechatInquiryStatus.READY;
}

if (!agent || !(await allowAgentSkipQueue(agent))) {
if (!agent) {
return LivechatInquiryStatus.QUEUED;
}

Expand Down
180 changes: 180 additions & 0 deletions apps/meteor/tests/end-to-end/api/livechat/24-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,186 @@ import { IS_EE } from '../../../e2e/config/constants';
await updateSetting('Livechat_Routing_Method', 'Manual_Selection');
});

// Basically: if there's a bot in the department, it should be assigned to the conversation
// No matter what settings workspace has in, as long as the setting to assign new conversations to bots is enabled
describe('Bots - Manual selection', () => {
let botUser: { user: IUser; credentials: Credentials };
let testDepartment: ILivechatDepartment;
let testDepartment2: ILivechatDepartment;
before(async () => {
const bot = await createUser({ roles: ['bot', 'livechat-agent'] });
const credentials = await login(bot.username, password);

botUser = { user: bot, credentials };
});
before(async () => {
testDepartment = await createDepartment([{ agentId: botUser.user._id }]);
testDepartment2 = await createDepartment();
await updateSetting('Livechat_Routing_Method', 'Manual_Selection');
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
await updateSetting('Livechat_accept_chats_with_no_agents', true);
});

after(async () => {
await deleteUser(botUser.user);
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
await updateSetting('Livechat_accept_chats_with_no_agents', false);
});

it('should assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.servedBy?._id).to.be.equal(botUser.user._id);
});
it('should not assign conversation to bot if department has no bots', async () => {
const visitor = await createVisitor(testDepartment2._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy).to.be.undefined;
});

describe('with setting disabled', () => {
before(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
});
after(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
});

it('should not assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy).to.be.undefined;
});
});
});

describe('Bots - Auto selection', () => {
let botUser: { user: IUser; credentials: Credentials };
let otherUser: { user: IUser; credentials: Credentials };
let testDepartment: ILivechatDepartment;
let testDepartment2: ILivechatDepartment;
before(async () => {
const bot = await createUser({ roles: ['bot', 'livechat-agent'] });
const credentials = await login(bot.username, password);

const other = await createUser({ roles: ['livechat-agent'] });
const otherCredentials = await login(other.username, password);

await makeAgentAvailable(otherCredentials);

botUser = { user: bot, credentials };
otherUser = { user: other, credentials: otherCredentials };
});
before(async () => {
testDepartment = await createDepartment([{ agentId: botUser.user._id }, { agentId: otherUser.user._id }]);
testDepartment2 = await createDepartment();
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
await updateSetting('Livechat_accept_chats_with_no_agents', true);
});

after(async () => {
await deleteUser(botUser.user);
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
await updateSetting('Livechat_accept_chats_with_no_agents', false);
});

it('should assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.servedBy?._id).to.be.equal(botUser.user._id);
});
it('should not assign conversation to bot if department has no bots', async () => {
const visitor = await createVisitor(testDepartment2._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy).to.be.undefined;
});

describe('with setting disabled', () => {
before(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
});
after(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
});

it('should not assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy?._id).to.be.equal(otherUser.user._id);
});
});
});

describe('Bots - Auto selection & Waiting queue', () => {
let botUser: { user: IUser; credentials: Credentials };
let testDepartment: ILivechatDepartment;
let testDepartment2: ILivechatDepartment;
before(async () => {
const bot = await createUser({ roles: ['bot', 'livechat-agent'] });
const credentials = await login(bot.username, password);

botUser = { user: bot, credentials };
});
before(async () => {
testDepartment = await createDepartment([{ agentId: botUser.user._id }]);
testDepartment2 = await createDepartment();
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
await updateSetting('Livechat_waiting_queue', true);
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
await updateSetting('Livechat_accept_chats_with_no_agents', true);
});

after(async () => {
await deleteUser(botUser.user);
await updateSetting('Livechat_waiting_queue', false);
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
await updateSetting('Livechat_accept_chats_with_no_agents', false);
});

it('should assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.servedBy?._id).to.be.equal(botUser.user._id);
});
it('should not assign conversation to bot if department has no bots', async () => {
const visitor = await createVisitor(testDepartment2._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy).to.be.undefined;
});

describe('with setting disabled', () => {
before(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', false);
});
after(async () => {
await updateSetting('Livechat_assign_new_conversation_to_bot', true);
});

it('should not assign conversation to bot', async () => {
const visitor = await createVisitor(testDepartment._id);
const room = await createLivechatRoom(visitor.token);

expect(room.servedBy).to.be.undefined;
});
});
});

describe('Auto-Selection', () => {
before(async () => {
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
Expand Down

0 comments on commit 755c26f

Please sign in to comment.