File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments