From 59f5208c5c05526e08a210e7776b58653e6d8a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20Cl=C3=AAuder=20Lima=20de=20Jesus?= Date: Sat, 27 Jan 2024 22:29:04 -0300 Subject: [PATCH] fix: search number without 9 in number from brazil --- src/whatsapp/services/chatwoot.service.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 26b0cce9..c78d2bb1 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -380,8 +380,9 @@ export class ChatwootService { } let query: any; + const isGroup = phoneNumber.includes('@g.us'); - if (!phoneNumber.includes('@g.us')) { + if (!isGroup) { this.logger.verbose('format phone number'); query = `+${phoneNumber}`; } else { @@ -390,12 +391,21 @@ export class ChatwootService { } this.logger.verbose('find contact in chatwoot'); - const contact: any = await client.contacts.search({ + let contact: any = await client.contacts.search({ accountId: this.provider.account_id, q: query, }); - if (!contact) { + if (!contact && !isGroup && query.startsWith('+55') && query.length > 13) { + this.logger.verbose('trying without the 9th digit'); + query = query.slice(0, 3) + query.slice(4); + contact = await client.contacts.search({ + accountId: this.provider.account_id, + q: query, + }); + } + + if(!contact) { this.logger.warn('contact not found'); return null; }