Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check queue settings to take inquiry #33782

Open
wants to merge 3 commits into
base: feat/single-contact-id
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ILivechatContact, IOmnichannelSource } from '@rocket.chat/core-typings';
import { makeFunction } from '@rocket.chat/patch-injection';

export const isAgentAvailableToTakeContactInquiry = makeFunction(
async (
_source: IOmnichannelSource,
_contactId: ILivechatContact['_id'] | null,
): Promise<{ error: string; value: false } | { value: true }> => ({
value: true,
}),
);
7 changes: 4 additions & 3 deletions apps/meteor/app/livechat/server/methods/takeInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Meteor } from 'meteor/meteor';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { settings } from '../../../settings/server';
import { RoutingManager } from '../lib/RoutingManager';
import { isAgentAvailableToTakeContactInquiry } from '../lib/contacts/isAgentAvailableToTakeContactInquiry';
import { migrateVisitorIfMissingContact } from '../lib/contacts/migrateVisitorIfMissingContact';
import { shouldTriggerVerificationApp } from '../lib/contacts/shouldTriggerVerificationApp';

declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -57,8 +57,9 @@ export const takeInquiry = async (
}

const contactId = await migrateVisitorIfMissingContact(inquiry.v._id, room.source);
if (contactId && (await shouldTriggerVerificationApp(contactId, room.source))) {
throw new Meteor.Error('error-unverified-contact');
const isAgentAvailableToTakeContactInquiryResult = await isAgentAvailableToTakeContactInquiry(room.source, contactId);
if (!isAgentAvailableToTakeContactInquiryResult.value) {
throw new Meteor.Error(isAgentAvailableToTakeContactInquiryResult.error);
}

const agent = {
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/ee/server/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import './isDepartmentCreationAvailable';
import './verifyContactChannel';
import './mergeContacts';
import './shouldTriggerVerificationApp';
import './isAgentAvailableToTakeContactInquiry';
import './airGappedRestrictionsWrapper';
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { ILivechatContact, IOmnichannelSource } from '@rocket.chat/core-typings';
import { License } from '@rocket.chat/license';
import { LivechatContacts } from '@rocket.chat/models';

import { isAgentAvailableToTakeContactInquiry } from '../../../app/livechat/server/lib/contacts/isAgentAvailableToTakeContactInquiry';
import { settings } from '../../../app/settings/server';

// If the contact is unknown and the setting to block unknown contacts is on, we must not allow the agent to take this inquiry
// if the contact is not verified in this channel and the block unverified contacts setting is on, we should not allow the inquiry to be taken
// otherwise, the contact is allowed to be taken
const runIsAgentAvailableToTakeContactInquiry = async (
_next: any,
source: IOmnichannelSource,
contactId: ILivechatContact['_id'] | null,
): Promise<{ error: string; value: false } | { value: true }> => {
if (!contactId) {
return { value: false, error: 'error-invalid-contact' };
}

const contact = await LivechatContacts.findOneById<Pick<ILivechatContact, '_id' | 'unknown' | 'channels'>>(contactId, {
projection: {
_id: 1,
unknown: 1,
channels: 1,
},
});

if (!contact) {
return { value: false, error: 'error-invalid-contact' };
}

if (contact.unknown && settings.get<boolean>('Livechat_Block_Unknown_Contacts')) {
return { value: false, error: 'error-unknown-contact' };
}

const isContactVerified = (contact.channels?.filter((channel) => channel.verified && channel.name === source.type) || []).length > 0;
if (!isContactVerified && settings.get<boolean>('Livechat_Block_Unverified_Contacts')) {
return { value: false, error: 'error-unverified-contact' };
}

return { value: true };
};

isAgentAvailableToTakeContactInquiry.patch(runIsAgentAvailableToTakeContactInquiry, () => License.hasModule('contact-id-verification'));
4 changes: 0 additions & 4 deletions apps/meteor/ee/server/patches/shouldTriggerVerificationApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ const runShouldTriggerVerificationApp = async (
return false;
}

if (contact.unknown && settings.get<boolean>('Livechat_Block_Unknown_Contacts')) {
return true;
}

// There is no configured verification app, so there is no reason to trigger a verification app, since
// none will be able to be assigned
if (settings.get<string>('Livechat_Contact_Verification_App') === '') {
Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/ee/server/settings/contact-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const addSettings = async (): Promise<void> => {
invalidValue: false,
});

await this.add('Livechat_Block_Unverified_Contacts', false, {
type: 'boolean',
invalidValue: false,
});

await this.add('Livechat_Require_Contact_Verification', 'always', {
type: 'select',
values: [
Expand Down
8 changes: 6 additions & 2 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,7 @@
"error-invalid-custom-field-name": "Invalid custom field name. Use only letters, numbers, hyphens and underscores.",
"error-invalid-custom-field-value": "Invalid value for {{field}} field",
"error-custom-field-not-allowed": "Custom field {{key}} is not allowed",
"error-invalid-contact": "Invalid contact.",
"error-invalid-date": "Invalid date provided.",
"error-invalid-dates": "From date cannot be after To date",
"error-invalid-description": "Invalid description",
Expand Down Expand Up @@ -2183,7 +2184,6 @@
"error-max-number-simultaneous-chats-reached": "The maximum number of simultaneous chats per agent has been reached.",
"error-max-rooms-per-guest-reached": "The maximum number of rooms per guest has been reached.",
"error-mac-limit-reached": "The maximum number of monthly active contacts for this workspace has been reached.",
"error-unverified-contact": "The contact must be verified.",
"error-message-deleting-blocked": "Message deleting is blocked",
"error-message-editing-blocked": "Message editing is blocked",
"error-message-size-exceeded": "Message size exceeds Message_MaxAllowedSize",
Expand Down Expand Up @@ -2246,6 +2246,8 @@
"error-no-permission-team-channel": "You don't have permission to add this channel to the team",
"error-no-owner-channel": "Only owners can add this channel to the team",
"error-unable-to-update-priority": "Unable to update priority",
"error-unknown-contact": "Contact is unkknown.",
"error-unverified-contact": "Contact is not verified.",
"error-you-are-last-owner": "You are the last owner. Please set new owner before leaving the room.",
"error-saving-sla": "An error ocurred while saving the SLA",
"error-duplicated-sla": "An SLA with the same name or due time already exists",
Expand Down Expand Up @@ -3344,7 +3346,9 @@
"Omnichannel_hide_conversation_after_closing": "Hide conversation after closing",
"Omnichannel_hide_conversation_after_closing_description": "After closing the conversation you will be redirected to Home.",
"Livechat_Block_Unknown_Contacts": "Block unknown contacts",
"Livechat_Block_Unknown_Contacts_Description": "Messages from people who are not on the contact list will not appear in the queue but will still appear in contact center.",
"Livechat_Block_Unknown_Contacts_Description": "Conversations from people who are not on the contact list will not be able to be taken.",
"Livechat_Block_Unverified_Contacts": "Block unverified contacts",
"Livechat_Block_Unverified_Contacts_Description": "Conversations from people who are not verified will not be able to be taken.",
"Livechat_Contact_Verification_App": "Contact verification app",
"Livechat_Contact_Verification_App_Description": "Install verification app from marketplace.",
"Livechat_Require_Contact_Verification": "Require verification on contacts.",
Expand Down
Loading