From 6bcc85c3d16b6e9277c0ee578abd414ad2d06de1 Mon Sep 17 00:00:00 2001 From: gustrb Date: Sun, 13 Oct 2024 11:23:47 -0300 Subject: [PATCH] feat: added `Livechat_Block_Unverified_Contacts` setting support --- .changeset/clean-ravens-melt.md | 5 +++-- .../app/livechat/server/lib/RoutingManager.ts | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.changeset/clean-ravens-melt.md b/.changeset/clean-ravens-melt.md index e6bef4d1d10f..799e48a7e442 100644 --- a/.changeset/clean-ravens-melt.md +++ b/.changeset/clean-ravens-melt.md @@ -5,5 +5,6 @@ Added three new settings to control how the agent might be handled down to the Omnichannel queue, they are: - Livechat_Block_Unknown_Contacts: if the contact associated with the livechat visitor is unknown, the conversation won't be handled down to an agent; -- Livechat_Contact_Verification_App: Defines the app that is going to be used to verify the contact; -- Livechat_Request_Verification_On_First_Contact_Only: if the contact associated with the livechat visitor should be verified every time he starts a new conversation or only once. +- Livechat_Block_Unverified_Contacts: if the contact has no verified channel, the conversation won't be handled down to an agent; +- Livechat_Request_Verification_On_First_Contact_Only: if the contact associated with the livechat visitor should be verified every time he starts a new conversation or only once; +- Livechat_Contact_Verification_App: Defines the app that is going to be used to verify the contact. \ No newline at end of file diff --git a/apps/meteor/app/livechat/server/lib/RoutingManager.ts b/apps/meteor/app/livechat/server/lib/RoutingManager.ts index 317a0811f62e..45c5c18ef2bc 100644 --- a/apps/meteor/app/livechat/server/lib/RoutingManager.ts +++ b/apps/meteor/app/livechat/server/lib/RoutingManager.ts @@ -260,16 +260,27 @@ export const RoutingManager: Routing = { return room; } + // Note: this should either be 1 or 0, if he is verified or not, but since we have an array of channels instead of a set there is no strong + // guarantee that is the case :P + const isContactVerified = + (contact.channels?.filter((channel) => channel.verified && channel.name === room.source.type) || []).length > 0; + + if (!isContactVerified && settings.get('Livechat_Block_Unverified_Contacts')) { + logger.debug( + `Contact ${inquiry.v._id} is not verified and Livechat_Block_Unverified_Contacts is enabled so we can't handle him down to the queue`, + ); + return room; + } + const contactVerificationApp = settings.get('Livechat_Contact_Verification_App'); // Note: Non-empty `Livechat_Contact_Verification_App` means the user has a Contact Verification App setup, // therefore, we must give the app control over the room if (contactVerificationApp !== '') { // Note: If it is not `Livechat_Request_Verification_On_First_Contact_Only` it means that even though the contact // was already verified, we must verify it again in order to handle the livechat conversation down to the queue - const verifiedChannels = contact.channels?.filter((channel) => channel.verified && channel.name === room.source.type) || []; if ( !settings.get('Livechat_Request_Verification_On_First_Contact_Only') || - (verifiedChannels.length === 0 && settings.get('Livechat_Block_Unverified_Contacts')) + (!isContactVerified && settings.get('Livechat_Block_Unverified_Contacts')) ) { await unverifyContactChannel(contact, room.source.type, inquiry.v._id); return room;