mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
fix: Correct logic of condition for sending LivechatSessionStarted webhook event (#36193)
This commit is contained in:
parent
1851038f0b
commit
f596b1f317
5
.changeset/empty-tables-change.md
Normal file
5
.changeset/empty-tables-change.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@rocket.chat/meteor": patch
|
||||
---
|
||||
|
||||
Fixes the condition for firing the `LivechatSessionTaken` webhook event.
|
||||
@ -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);
|
||||
|
||||
@ -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', () => {
|
||||
@ -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 () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user