Skip to content

Commit

Permalink
feat: added Livechat_Block_Unverified_Contacts setting support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustrb committed Oct 13, 2024
1 parent 63f0997 commit 6bcc85c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .changeset/clean-ravens-melt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 13 additions & 2 deletions apps/meteor/app/livechat/server/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>('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<boolean>('Livechat_Request_Verification_On_First_Contact_Only') ||
(verifiedChannels.length === 0 && settings.get<boolean>('Livechat_Block_Unverified_Contacts'))
(!isContactVerified && settings.get<boolean>('Livechat_Block_Unverified_Contacts'))
) {
await unverifyContactChannel(contact, room.source.type, inquiry.v._id);
return room;
Expand Down

0 comments on commit 6bcc85c

Please sign in to comment.