Skip to content

Commit cffb673

Browse files
committed
Include identifier to contact filter in chatwoot
1 parent cc17d61 commit cffb673

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/whatsapp/services/chatwoot.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,14 @@ export class ChatwootService {
402402
});
403403
}
404404

405-
if (!contact) {
405+
if (!contact && contact?.payload?.length === 0) {
406406
this.logger.warn('contact not found');
407407
return null;
408408
}
409409

410410
if (!isGroup) {
411411
this.logger.verbose('return contact');
412-
return this.findContactInContactList(contact.payload, query);
412+
return contact.payload.length > 1 ? this.findContactInContactList(contact.payload, query) : contact.payload[0];
413413
} else {
414414
this.logger.verbose('return group');
415415
return contact.payload.find((contact) => contact.identifier === query);
@@ -447,7 +447,7 @@ export class ChatwootService {
447447
}
448448

449449
private getSearchableFields() {
450-
return ['phone_number'];
450+
return ['phone_number', 'identifier'];
451451
}
452452

453453
private getFilterPayload(query: string) {
@@ -461,7 +461,7 @@ export class ChatwootService {
461461
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
462462
filterPayload.push({
463463
attribute_key: field,
464-
filter_operator: 'equal_to',
464+
filter_operator: field == 'phone_number' ? 'equal_to' : 'contains',
465465
values: [number.replace('+', '')],
466466
query_operator: queryOperator,
467467
});
@@ -470,6 +470,7 @@ export class ChatwootService {
470470

471471
return filterPayload;
472472
}
473+
473474
public async createConversation(instance: InstanceDto, body: any) {
474475
this.logger.verbose('create conversation to instance: ' + instance.instanceName);
475476
try {

0 commit comments

Comments
 (0)