Merge pull request #393 from deivisonrpg/fix/chatwoot-validate-9-digit

Fix/chatwoot validate 9 digit
This commit is contained in:
Davidson Gomes 2024-02-02 14:05:02 -03:00 committed by GitHub
commit 0547ff719c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -447,27 +447,29 @@ export class ChatwootService {
} }
private getSearchableFields() { private getSearchableFields() {
return ['identifier', 'phone_number', 'name', 'email']; return ['phone_number'];
} }
private getFilterPayload(query: string) { private getFilterPayload(query: string) {
const payload = []; const filterPayload = [];
const values = this.getNumbers(query);
const fields = this.getSearchableFields(); const numbers = this.getNumbers(query);
fields.forEach((key, index) => { const fieldsToSearch = this.getSearchableFields();
const queryOperator = fields.length - 1 === index ? null : 'OR';
payload.push({ fieldsToSearch.forEach((field, index1) => {
attribute_key: key, numbers.forEach((number, index2) => {
filter_operator: 'contains', const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
values: values, filterPayload.push({
query_operator: queryOperator, attribute_key: field,
filter_operator: 'equal_to',
values: [number.replace('+', '')],
query_operator: queryOperator,
});
}); });
}); });
return payload; return filterPayload;
} }
public async createConversation(instance: InstanceDto, body: any) { public async createConversation(instance: InstanceDto, body: any) {
this.logger.verbose('create conversation to instance: ' + instance.instanceName); this.logger.verbose('create conversation to instance: ' + instance.instanceName);
try { try {