From 6727b1cfca93716568b22f018e1be30429cf5841 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 18 Jul 2023 14:49:38 -0300 Subject: [PATCH] fix: Adjusts to receive contact with more numbers --- src/whatsapp/services/chatwoot.service.ts | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 1997dcc5..67d39aee 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -1174,6 +1174,7 @@ export class ChatwootService { const result = typeKey ? types[typeKey] : undefined; if (typeKey === 'contactMessage') { + console.log(result); const vCardData = result.split('\n'); const contactInfo = {}; @@ -1184,13 +1185,17 @@ export class ChatwootService { } }); - const telKey = Object.keys(contactInfo).find((key) => - key.startsWith('item1.TEL;waid='), - ); + let formattedContact = `**Contact:** + **name:** ${contactInfo['FN']}`; - const formattedContact = `**Contact:** - **name:** ${contactInfo['FN']} - **number:** ${contactInfo[telKey]}`; + let numberCount = 1; + Object.keys(contactInfo).forEach((key) => { + if (key.startsWith('item') && key.includes('TEL;waid=')) { + const phoneNumber = contactInfo[key]; + formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`; + numberCount++; + } + }); this.logger.verbose('message content: ' + formattedContact); return formattedContact; @@ -1208,13 +1213,17 @@ export class ChatwootService { } }); - const telKey = Object.keys(contactInfo).find((key) => - key.startsWith('item1.TEL;waid='), - ); + let formattedContact = `**Contact:** + **name:** ${contact.displayName}`; - const formattedContact = `**Contact:** - **name:** ${contact.displayName} - **number:** ${contactInfo[telKey]}`; + let numberCount = 1; + Object.keys(contactInfo).forEach((key) => { + if (key.startsWith('item') && key.includes('TEL;waid=')) { + const phoneNumber = contactInfo[key]; + formattedContact += `\n**number ${numberCount}:** ${phoneNumber}`; + numberCount++; + } + }); return formattedContact; });