@@ -453,29 +453,33 @@ export class ChatwootService {
453453 const findContact = await this . findContact ( instance , chatId ) ;
454454
455455 let contact : any ;
456-
457- if ( findContact ) {
458- contact = await this . updateContact ( instance , findContact . id , {
459- name : nameContact ,
460- avatar_url : picture_url . profilePictureUrl || null ,
461- } ) ;
456+ if ( body . key . fromMe ) {
457+ contact = findContact ;
462458 } else {
463- contact = await this . createContact (
464- instance ,
465- chatId ,
466- filterInbox . id ,
467- isGroup ,
468- nameContact ,
469- picture_url . profilePictureUrl || null ,
470- ) ;
459+ if ( findContact ) {
460+ contact = await this . updateContact ( instance , findContact . id , {
461+ name : nameContact ,
462+ avatar_url : picture_url . profilePictureUrl || null ,
463+ } ) ;
464+ } else {
465+ contact = await this . createContact (
466+ instance ,
467+ chatId ,
468+ filterInbox . id ,
469+ isGroup ,
470+ nameContact ,
471+ picture_url . profilePictureUrl || null ,
472+ ) ;
473+ }
471474 }
472475
473476 if ( ! contact ) {
474477 this . logger . warn ( 'contact not found' ) ;
475478 return null ;
476479 }
477480
478- const contactId = contact . payload . id || contact . payload . contact . id ;
481+ const contactId =
482+ contact ?. payload ?. id || contact ?. payload ?. contact ?. id || contact ?. id ;
479483
480484 if ( ! body . key . fromMe && contact . name === chatId && nameContact !== chatId ) {
481485 this . logger . verbose ( 'update contact name in chatwoot' ) ;
@@ -987,13 +991,9 @@ export class ChatwootService {
987991 }
988992
989993 if ( command . includes ( '#inbox_whatsapp' ) ) {
990- console . log ( 'command include #inbox_whatsapp' ) ;
991-
992994 const urlServer = this . configService . get < HttpServer > ( 'SERVER' ) . URL ;
993995 const apiKey = this . configService . get ( 'AUTHENTICATION' ) . API_KEY . KEY ;
994996
995- console . log ( 'url server: ' + urlServer ) ;
996- console . log ( 'api key: ' + apiKey ) ;
997997 const data = {
998998 instanceName : command . split ( ':' ) [ 1 ] ,
999999 qrcode : true ,
@@ -1014,9 +1014,7 @@ export class ChatwootService {
10141014 data : data ,
10151015 } ;
10161016
1017- const { data : response } = await axios . request ( config ) ;
1018-
1019- console . log ( response ) ;
1017+ await axios . request ( config ) ;
10201018 }
10211019 }
10221020
@@ -1101,7 +1099,6 @@ export class ChatwootService {
11011099 body . content_type === 'input_csat' &&
11021100 body . event === 'message_created'
11031101 ) {
1104- console . log ( body ) ;
11051102 this . logger . verbose ( 'check if is csat' ) ;
11061103
11071104 const data : SendTextDto = {
@@ -1161,6 +1158,7 @@ export class ChatwootService {
11611158 documentWithCaptionMessage :
11621159 msg . documentWithCaptionMessage ?. message ?. documentMessage ?. caption ,
11631160 audioMessage : msg . audioMessage ?. caption ,
1161+ contactMessage : msg . contactMessage ?. vcard ,
11641162 } ;
11651163
11661164 this . logger . verbose ( 'type message: ' + types ) ;
@@ -1174,6 +1172,25 @@ export class ChatwootService {
11741172
11751173 const result = typeKey ? types [ typeKey ] : undefined ;
11761174
1175+ if ( typeKey === 'contactMessage' ) {
1176+ const vCardData = result . split ( '\n' ) ;
1177+ const contactInfo = { } ;
1178+
1179+ vCardData . forEach ( ( line ) => {
1180+ const [ key , value ] = line . split ( ':' ) ;
1181+ if ( key && value ) {
1182+ contactInfo [ key ] = value ;
1183+ }
1184+ } ) ;
1185+
1186+ const formattedContact = `**Contact:**
1187+ **name:** ${ contactInfo [ 'FN' ] }
1188+ **number:** ${ contactInfo [ 'item1.TEL;waid=5511952801378' ] } ` ;
1189+
1190+ this . logger . verbose ( 'message content: ' + formattedContact ) ;
1191+ return formattedContact ;
1192+ }
1193+
11771194 this . logger . verbose ( 'message content: ' + result ) ;
11781195
11791196 return result ;
@@ -1184,8 +1201,12 @@ export class ChatwootService {
11841201
11851202 const types = this . getTypeMessage ( msg ) ;
11861203
1204+ console . log ( 'types' , types ) ;
1205+
11871206 const messageContent = this . getMessageContent ( types ) ;
11881207
1208+ console . log ( 'messageContent' , messageContent ) ;
1209+
11891210 this . logger . verbose ( 'conversation message: ' + messageContent ) ;
11901211
11911212 return messageContent ;
0 commit comments