@@ -1159,6 +1159,7 @@ export class ChatwootService {
11591159 msg . documentWithCaptionMessage ?. message ?. documentMessage ?. caption ,
11601160 audioMessage : msg . audioMessage ?. caption ,
11611161 contactMessage : msg . contactMessage ?. vcard ,
1162+ contactsArrayMessage : msg . contactsArrayMessage ,
11621163 } ;
11631164
11641165 this . logger . verbose ( 'type message: ' + types ) ;
@@ -1183,14 +1184,48 @@ export class ChatwootService {
11831184 }
11841185 } ) ;
11851186
1187+ const telKey = Object . keys ( contactInfo ) . find ( ( key ) =>
1188+ key . startsWith ( 'item1.TEL;waid=' ) ,
1189+ ) ;
1190+
11861191 const formattedContact = `**Contact:**
11871192 **name:** ${ contactInfo [ 'FN' ] }
1188- **number:** ${ contactInfo [ 'item1.TEL;waid=5511952801378' ] } ` ;
1193+ **number:** ${ contactInfo [ telKey ] } ` ;
11891194
11901195 this . logger . verbose ( 'message content: ' + formattedContact ) ;
11911196 return formattedContact ;
11921197 }
11931198
1199+ if ( typeKey === 'contactsArrayMessage' ) {
1200+ const formattedContacts = result . contacts . map ( ( contact ) => {
1201+ const vCardData = contact . vcard . split ( '\n' ) ;
1202+ const contactInfo = { } ;
1203+
1204+ vCardData . forEach ( ( line ) => {
1205+ const [ key , value ] = line . split ( ':' ) ;
1206+ if ( key && value ) {
1207+ contactInfo [ key ] = value ;
1208+ }
1209+ } ) ;
1210+
1211+ const telKey = Object . keys ( contactInfo ) . find ( ( key ) =>
1212+ key . startsWith ( 'item1.TEL;waid=' ) ,
1213+ ) ;
1214+
1215+ const formattedContact = `**Contact:**
1216+ **name:** ${ contact . displayName }
1217+ **number:** ${ contactInfo [ telKey ] } ` ;
1218+
1219+ return formattedContact ;
1220+ } ) ;
1221+
1222+ const formattedContactsArray = formattedContacts . join ( '\n\n' ) ;
1223+
1224+ this . logger . verbose ( 'formatted contacts: ' + formattedContactsArray ) ;
1225+
1226+ return formattedContactsArray ;
1227+ }
1228+
11941229 this . logger . verbose ( 'message content: ' + result ) ;
11951230
11961231 return result ;
@@ -1201,12 +1236,8 @@ export class ChatwootService {
12011236
12021237 const types = this . getTypeMessage ( msg ) ;
12031238
1204- console . log ( 'types' , types ) ;
1205-
12061239 const messageContent = this . getMessageContent ( types ) ;
12071240
1208- console . log ( 'messageContent' , messageContent ) ;
1209-
12101241 this . logger . verbose ( 'conversation message: ' + messageContent ) ;
12111242
12121243 return messageContent ;
@@ -1457,7 +1488,7 @@ export class ChatwootService {
14571488
14581489 if ( event === 'connection.update' ) {
14591490 this . logger . verbose ( 'event connection.update' ) ;
1460- console . log ( 'connection.update' , body ) ;
1491+
14611492 if ( body . status === 'open' ) {
14621493 const msgConnection = `🚀 Conexão estabelecida com sucesso!` ;
14631494
0 commit comments