Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/empty-tables-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes the condition for firing the `LivechatSessionTaken` webhook event.
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const onNewRoom = makeFunction(async (room: IOmnichannelRoom) => {

export const afterTakeInquiry = makeFunction(
async ({ room }: { inquiry: InquiryWithAgentInfo; room: IOmnichannelRoom; agent: { agentId: string; username: string } }) => {
if (settings.get('Livechat_webhook_on_chat_taken')) {
if (!settings.get('Livechat_webhook_on_chat_taken')) {
return;
}
await sendToCRM('LivechatSessionTaken', room);
Expand Down
92 changes: 90 additions & 2 deletions apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { ISetting } from '@rocket.chat/core-typings';
import type { IOmnichannelRoom, ISetting } from '@rocket.chat/core-typings';
import { expect } from 'chai';
import { after, before, describe, it } from 'mocha';
import type { Response } from 'supertest';

import { getCredentials, api, request, credentials } from '../../../data/api-data';
import { deleteVisitor } from '../../../data/livechat/rooms';
import {
closeOmnichannelRoom,
createAgent,
createLivechatRoom,
createVisitor,
deleteVisitor,
getLivechatRoomInfo,
startANewLivechatRoomAndTakeIt,
} from '../../../data/livechat/rooms';
import { sleep } from '../../../data/livechat/utils';
import { updatePermission, updateSetting } from '../../../data/permissions.helper';

describe('LIVECHAT - Integrations', () => {
Expand Down Expand Up @@ -138,7 +147,86 @@ describe('LIVECHAT - Integrations', () => {
await request.post(api('livechat/webhook.test')).set(credentials).expect(400);
});
});

describe('Webhook notifications', () => {
before(async () => {
await updateSetting('Livechat_webhookUrl', `${webhookUrl}/anything`);
await updateSetting('Livechat_Routing_Method', 'Manual_Selection');
await createAgent();
});
after(async () => {
await updateSetting('Livechat_webhookUrl', '');
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
await updateSetting('Livechat_webhook_on_start', false);
await updateSetting('Livechat_webhook_on_close', false);
await updateSetting('Livechat_webhook_on_chat_taken', false);
await updateSetting('Livechat_webhook_on_chat_queued', false);
});

it('should send a notification on chat start', async () => {
await updateSetting('Livechat_webhook_on_start', true);

const { room } = await startANewLivechatRoomAndTakeIt();
await sleep(1000);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.crmData).to.be.an('string');
expect(JSON.parse(roomInfo.crmData as string))
.to.have.property('json')
.that.has.property('type', 'LivechatSessionStart');
await updateSetting('Livechat_webhook_on_start', false);
await closeOmnichannelRoom(room._id);
});
it('should send a notification on chat taken', async () => {
await updateSetting('Livechat_webhook_on_chat_taken', true);

const { room } = await startANewLivechatRoomAndTakeIt();
await sleep(1000);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.crmData).to.be.an('string');
expect(JSON.parse(roomInfo.crmData as string))
.to.have.property('json')
.that.has.property('type', 'LivechatSessionTaken');
await updateSetting('Livechat_webhook_on_chat_taken', false);
await closeOmnichannelRoom(room._id);
});
let room: IOmnichannelRoom;
it('should send a notification on chat queued', async () => {
await updateSetting('Livechat_webhook_on_chat_queued', true);

const visitor = await createVisitor();
room = await createLivechatRoom(visitor.token);
await sleep(1000);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.crmData).to.be.an('string');
expect(JSON.parse(roomInfo.crmData as string))
.to.have.property('json')
.that.has.property('type', 'LivechatSessionQueued');
await updateSetting('Livechat_webhook_on_chat_queued', false);
});
it('should send a notification on chat close', async () => {
await updateSetting('Livechat_webhook_on_close', true);

await closeOmnichannelRoom(room._id);

await sleep(1000);

const roomInfo = await getLivechatRoomInfo(room._id);

expect(roomInfo.crmData).to.be.an('string');
expect(JSON.parse(roomInfo.crmData as string))
.to.have.property('json')
.that.has.property('type', 'LivechatSession');
await updateSetting('Livechat_webhook_on_close', false);
});
});
});

describe('omnichannel/integrations', () => {
describe('POST', () => {
it('should update the integration settings if the required parameters are provided', async () => {
Expand Down
Loading