Merge pull request #397 from deivisonrpg/fix/chatwoot-add-identifier-to-contact-filter

Fix(chatwoot): Include identifier to contact filter
This commit is contained in:
Davidson Gomes 2024-02-04 15:04:08 -03:00 committed by GitHub
commit 803b123ade
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -402,14 +402,14 @@ export class ChatwootService {
});
}
if (!contact) {
if (!contact && contact?.payload?.length === 0) {
this.logger.warn('contact not found');
return null;
}
if (!isGroup) {
this.logger.verbose('return contact');
return this.findContactInContactList(contact.payload, query);
return contact.payload.length > 1 ? this.findContactInContactList(contact.payload, query) : contact.payload[0];
} else {
this.logger.verbose('return group');
return contact.payload.find((contact) => contact.identifier === query);
@ -447,7 +447,7 @@ export class ChatwootService {
}
private getSearchableFields() {
return ['phone_number'];
return ['phone_number', 'identifier'];
}
private getFilterPayload(query: string) {
@ -461,7 +461,7 @@ export class ChatwootService {
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
filterPayload.push({
attribute_key: field,
filter_operator: 'equal_to',
filter_operator: field == 'phone_number' ? 'equal_to' : 'contains',
values: [number.replace('+', '')],
query_operator: queryOperator,
});
@ -470,6 +470,7 @@ export class ChatwootService {
return filterPayload;
}
public async createConversation(instance: InstanceDto, body: any) {
this.logger.verbose('create conversation to instance: ' + instance.instanceName);
try {