Skip to content

Commit 3a1ce71

Browse files
authored
fix: Queue chat when transferring and waiting queue is active (#36494)
1 parent 92b0bce commit 3a1ce71

File tree

3 files changed

+233
-2
lines changed

3 files changed

+233
-2
lines changed

.changeset/fluffy-cougars-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes a behavior when transferring a room to another department that was not considering the `waiting queue` setting and attempted to route the chat to an agent instead of leaving it on the department's queue

apps/meteor/app/livechat/server/lib/Helper.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,27 @@ export const forwardRoomToDepartment = async (room: IOmnichannelRoom, guest: ILi
635635
},
636636
});
637637

638+
// Cases:
639+
// 1. Routing is manual
640+
// 2. Server is out of macs
641+
// 3. Department allows to forward when offline and department is offline
642+
// 4. Department is online && waiting queue is enabled
643+
const onlineAgents = await checkOnlineAgents(departmentId);
644+
const isWaitingQueueEnabled = settings.get('Livechat_waiting_queue');
638645
if (
639646
!RoutingManager.getConfig()?.autoAssignAgent ||
640647
!(await Omnichannel.isWithinMACLimit(room)) ||
641-
(department?.allowReceiveForwardOffline && !(await checkOnlineAgents(departmentId)))
648+
(department?.allowReceiveForwardOffline && !onlineAgents) ||
649+
(isWaitingQueueEnabled && onlineAgents)
642650
) {
643-
logger.debug(`Room ${room._id} will be on department queue`);
651+
logger.debug({
652+
msg: 'Room will be on department queue',
653+
roomId: room._id,
654+
departmentId,
655+
departmentAllowOffline: department?.allowReceiveForwardOffline,
656+
areAgentsOnline: onlineAgents,
657+
isWaitingQueueEnabled,
658+
});
644659
await saveTransferHistory(room, transferData);
645660
return RoutingManager.unassignAgent(inquiry, departmentId, true);
646661
}

apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,178 @@ describe('LIVECHAT - rooms', () => {
12481248
},
12491249
);
12501250

1251+
(IS_EE ? it : it.skip)(
1252+
'when manager forwards a chat that hasnt been assigned to a user to another department with no online agents, chat should end ready in department (not queued)',
1253+
async () => {
1254+
await updateSetting('Livechat_accept_chats_with_no_agents', true);
1255+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1256+
const { department: initialDepartment } = await createDepartmentWithAnOfflineAgent({});
1257+
const { department: forwardToOfflineDepartment } = await createDepartmentWithAnOfflineAgent({});
1258+
1259+
const newVisitor = await createVisitor(initialDepartment._id);
1260+
const newRoom = await createLivechatRoom(newVisitor.token);
1261+
1262+
const manager = await createUser();
1263+
const managerCredentials = await login(manager.username, password);
1264+
await createManager(manager.username);
1265+
1266+
await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1267+
roomId: newRoom._id,
1268+
departmentId: forwardToOfflineDepartment._id,
1269+
clientAction: true,
1270+
comment: 'test comment',
1271+
});
1272+
1273+
const inquiry = await fetchInquiry(newRoom._id);
1274+
1275+
// Inquiry status doesn't change, it was ready when created, it keeps ready after forwarding as no assignment was done
1276+
expect(inquiry.status).to.equal('ready');
1277+
expect(inquiry.department).to.equal(forwardToOfflineDepartment._id);
1278+
1279+
await Promise.all([deleteDepartment(initialDepartment._id), deleteDepartment(forwardToOfflineDepartment._id)]);
1280+
},
1281+
);
1282+
1283+
(IS_EE ? it : it.skip)(
1284+
'when manager forwards a chat that hasnt been assigned to a user to another department with no online agents when waiting queue is active, chat should end queued in department',
1285+
async () => {
1286+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1287+
await updateSetting('Livechat_waiting_queue', true);
1288+
const { department: initialDepartment } = await createDepartmentWithAnOfflineAgent({});
1289+
const { department: forwardToOfflineDepartment } = await createDepartmentWithAnOfflineAgent({});
1290+
1291+
const newVisitor = await createVisitor(initialDepartment._id);
1292+
const newRoom = await createLivechatRoom(newVisitor.token);
1293+
1294+
const manager = await createUser();
1295+
const managerCredentials = await login(manager.username, password);
1296+
await createManager(manager.username);
1297+
1298+
expect(newRoom.servedBy).to.be.undefined;
1299+
await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1300+
roomId: newRoom._id,
1301+
departmentId: forwardToOfflineDepartment._id,
1302+
clientAction: true,
1303+
comment: 'test comment',
1304+
});
1305+
1306+
const inquiry = await fetchInquiry(newRoom._id);
1307+
1308+
expect(inquiry.status).to.equal('queued');
1309+
expect(inquiry.department).to.equal(forwardToOfflineDepartment._id);
1310+
1311+
await Promise.all([
1312+
deleteDepartment(initialDepartment._id),
1313+
deleteDepartment(forwardToOfflineDepartment._id),
1314+
updateSetting('Livechat_waiting_queue', true),
1315+
updateSetting('Livechat_accept_chats_with_no_agents', false),
1316+
]);
1317+
},
1318+
);
1319+
1320+
(IS_EE ? it : it.skip)(
1321+
'when manager forward to a department while waiting_queue is active and allowReceiveForwardOffline is true, chat should end in departments queue',
1322+
async () => {
1323+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1324+
const { department: initialDepartment } = await createDepartmentWithAnOnlineAgent();
1325+
const { department: forwardToOfflineDepartment } = await createDepartmentWithAnAwayAgent({ allowReceiveForwardOffline: true });
1326+
1327+
const newVisitor = await createVisitor(initialDepartment._id);
1328+
const newRoom = await createLivechatRoom(newVisitor.token);
1329+
1330+
const manager = await createUser();
1331+
const managerCredentials = await login(manager.username, password);
1332+
await createManager(manager.username);
1333+
1334+
// Waiting queue enabled after assignement but before transfer, otherwise, chat will fall on previous test case
1335+
await updateSetting('Livechat_waiting_queue', true);
1336+
await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1337+
roomId: newRoom._id,
1338+
departmentId: forwardToOfflineDepartment._id,
1339+
clientAction: true,
1340+
comment: 'test comment',
1341+
});
1342+
1343+
const inquiry = await fetchInquiry(newRoom._id);
1344+
1345+
expect(inquiry.status).to.equal('queued');
1346+
expect(inquiry.department).to.equal(forwardToOfflineDepartment._id);
1347+
1348+
await Promise.all([
1349+
deleteDepartment(initialDepartment._id),
1350+
deleteDepartment(forwardToOfflineDepartment._id),
1351+
updateSetting('Livechat_waiting_queue', false),
1352+
]);
1353+
},
1354+
);
1355+
1356+
(IS_EE ? it : it.skip)(
1357+
'when manager forward to a department while waiting_queue is active and allowReceiveForwardOffline is false, transfer should fail',
1358+
async () => {
1359+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1360+
const { department: initialDepartment } = await createDepartmentWithAnOnlineAgent();
1361+
const { department: forwardToOfflineDepartment } = await createDepartmentWithAnAwayAgent({ allowReceiveForwardOffline: false });
1362+
1363+
const newVisitor = await createVisitor(initialDepartment._id);
1364+
const newRoom = await createLivechatRoom(newVisitor.token);
1365+
1366+
const manager = await createUser();
1367+
const managerCredentials = await login(manager.username, password);
1368+
await createManager(manager.username);
1369+
1370+
// Waiting queue enabled after assignement but before transfer, otherwise, chat will fall on previous test case
1371+
await updateSetting('Livechat_waiting_queue', true);
1372+
const res = await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1373+
roomId: newRoom._id,
1374+
departmentId: forwardToOfflineDepartment._id,
1375+
clientAction: true,
1376+
comment: 'test comment',
1377+
});
1378+
1379+
expect(res.status).to.equal(400);
1380+
expect(res.body).to.have.property('error', 'error-no-agents-online-in-department');
1381+
1382+
await Promise.all([
1383+
deleteDepartment(initialDepartment._id),
1384+
deleteDepartment(forwardToOfflineDepartment._id),
1385+
updateSetting('Livechat_waiting_queue', false),
1386+
]);
1387+
},
1388+
);
1389+
1390+
(IS_EE ? it : it.skip)(
1391+
'when manager forward to a department while waiting_queue is disabled and allowReceiveForwardOffline is false, but department is online, transfer should succeed',
1392+
async () => {
1393+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1394+
const { department: initialDepartment } = await createDepartmentWithAnOnlineAgent();
1395+
const { department: targetDepartment } = await createDepartmentWithAnOnlineAgent();
1396+
1397+
const newVisitor = await createVisitor(initialDepartment._id);
1398+
const newRoom = await createLivechatRoom(newVisitor.token);
1399+
1400+
const manager = await createUser();
1401+
const managerCredentials = await login(manager.username, password);
1402+
await createManager(manager.username);
1403+
1404+
expect(newRoom).to.have.property('servedBy');
1405+
const res = await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1406+
roomId: newRoom._id,
1407+
departmentId: targetDepartment._id,
1408+
clientAction: true,
1409+
comment: 'test comment',
1410+
});
1411+
1412+
expect(res.status).to.equal(200);
1413+
1414+
const inquiry = await fetchInquiry(newRoom._id);
1415+
1416+
expect(inquiry).to.have.property('department', targetDepartment._id);
1417+
expect(inquiry).to.have.property('status', 'taken');
1418+
1419+
await Promise.all([deleteDepartment(initialDepartment._id), deleteDepartment(targetDepartment._id)]);
1420+
},
1421+
);
1422+
12511423
(IS_EE ? it : it.skip)(
12521424
'when manager forward to online (agent away, accept when agent idle on) department the inquiry should not be set to the queue',
12531425
async () => {
@@ -1285,6 +1457,45 @@ describe('LIVECHAT - rooms', () => {
12851457
},
12861458
);
12871459

1460+
(IS_EE ? it : it.skip)(
1461+
'when manager forward to a department while waiting_queue is enabled, but department is online, transfer should succeed but it should end queued on target',
1462+
async () => {
1463+
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
1464+
const { department: initialDepartment } = await createDepartmentWithAnOnlineAgent();
1465+
const { department: targetDepartment } = await createDepartmentWithAnOnlineAgent();
1466+
1467+
const newVisitor = await createVisitor(initialDepartment._id);
1468+
const newRoom = await createLivechatRoom(newVisitor.token);
1469+
1470+
const manager = await createUser();
1471+
const managerCredentials = await login(manager.username, password);
1472+
await createManager(manager.username);
1473+
1474+
expect(newRoom).to.have.property('servedBy');
1475+
1476+
await updateSetting('Livechat_waiting_queue', true);
1477+
const res = await request.post(api('livechat/room.forward')).set(managerCredentials).send({
1478+
roomId: newRoom._id,
1479+
departmentId: targetDepartment._id,
1480+
clientAction: true,
1481+
comment: 'test comment',
1482+
});
1483+
1484+
expect(res.status).to.equal(200);
1485+
1486+
const inquiry = await fetchInquiry(newRoom._id);
1487+
1488+
expect(inquiry).to.have.property('department', targetDepartment._id);
1489+
expect(inquiry).to.have.property('status', 'queued');
1490+
1491+
await Promise.all([
1492+
deleteDepartment(initialDepartment._id),
1493+
deleteDepartment(targetDepartment._id),
1494+
updateSetting('Livechat_waiting_queue', false),
1495+
]);
1496+
},
1497+
);
1498+
12881499
(IS_EE ? it : it.skip)(
12891500
'should update inquiry last message when manager forward to offline department and the inquiry returns to queued',
12901501
async () => {

0 commit comments

Comments
 (0)