@@ -1354,6 +1354,37 @@ export class ChatwootService {
13541354 ) ;
13551355 }
13561356 }
1357+
1358+ const chatwootRead = this . configService . get < Chatwoot > ( 'CHATWOOT' ) . MESSAGE_READ ;
1359+ if ( chatwootRead ) {
1360+ const lastMessage = await this . repository . message . find ( {
1361+ where : {
1362+ key : {
1363+ fromMe : false ,
1364+ } ,
1365+ owner : instance . instanceName ,
1366+ } ,
1367+ limit : 1 ,
1368+ } ) ;
1369+ if ( lastMessage . length > 0 && ! lastMessage [ 0 ] . chatwoot ?. isRead ) {
1370+ waInstance ?. markMessageAsRead ( {
1371+ read_messages : lastMessage . map ( ( msg ) => ( {
1372+ id : msg . key ?. id ,
1373+ fromMe : msg . key ?. fromMe ,
1374+ remoteJid : msg . key ?. remoteJid ,
1375+ } ) ) ,
1376+ } ) ;
1377+ const updateMessage = lastMessage . map ( ( msg ) => ( {
1378+ key : msg . key ,
1379+ owner : msg . owner ,
1380+ chatwoot : {
1381+ ...msg . chatwoot ,
1382+ isRead : true ,
1383+ } ,
1384+ } ) ) ;
1385+ this . repository . message . update ( updateMessage , instance . instanceName , true ) ;
1386+ }
1387+ }
13571388 }
13581389
13591390 if ( body . message_type === 'template' && body . event === 'message_created' ) {
@@ -2047,6 +2078,34 @@ export class ChatwootService {
20472078 }
20482079 }
20492080
2081+ if ( event === 'messages.edit' ) {
2082+ const editedText = `${
2083+ body ?. editedMessage ?. conversation || body ?. editedMessage ?. extendedTextMessage ?. text
2084+ } \n\n_\`${ i18next . t ( 'cw.message.edited' ) } .\`_`;
2085+ const message = await this . getMessageByKeyId ( instance , body ?. key ?. id ) ;
2086+ const messageType = message . key ?. fromMe ? 'outgoing' : 'incoming' ;
2087+
2088+ if ( message && message . chatwoot ?. conversationId ) {
2089+ const send = await this . createMessage (
2090+ instance ,
2091+ message . chatwoot . conversationId ,
2092+ editedText ,
2093+ messageType ,
2094+ false ,
2095+ [ ] ,
2096+ {
2097+ message : { extendedTextMessage : { contextInfo : { stanzaId : message . key . id } } } ,
2098+ } ,
2099+ 'WAID:' + body . key . id ,
2100+ ) ;
2101+ if ( ! send ) {
2102+ this . logger . warn ( 'edited message not sent' ) ;
2103+ return ;
2104+ }
2105+ }
2106+ return ;
2107+ }
2108+
20502109 if ( event === 'messages.read' ) {
20512110 this . logger . verbose ( 'read message from instance: ' + instance . instanceName ) ;
20522111
0 commit comments