Skip to content

Commit 59f5208

Browse files
committed
fix: search number without 9 in number from brazil
1 parent 45e03d8 commit 59f5208

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/whatsapp/services/chatwoot.service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ export class ChatwootService {
380380
}
381381

382382
let query: any;
383+
const isGroup = phoneNumber.includes('@g.us');
383384

384-
if (!phoneNumber.includes('@g.us')) {
385+
if (!isGroup) {
385386
this.logger.verbose('format phone number');
386387
query = `+${phoneNumber}`;
387388
} else {
@@ -390,12 +391,21 @@ export class ChatwootService {
390391
}
391392

392393
this.logger.verbose('find contact in chatwoot');
393-
const contact: any = await client.contacts.search({
394+
let contact: any = await client.contacts.search({
394395
accountId: this.provider.account_id,
395396
q: query,
396397
});
397398

398-
if (!contact) {
399+
if (!contact && !isGroup && query.startsWith('+55') && query.length > 13) {
400+
this.logger.verbose('trying without the 9th digit');
401+
query = query.slice(0, 3) + query.slice(4);
402+
contact = await client.contacts.search({
403+
accountId: this.provider.account_id,
404+
q: query,
405+
});
406+
}
407+
408+
if(!contact) {
399409
this.logger.warn('contact not found');
400410
return null;
401411
}

0 commit comments

Comments
 (0)