diff --git a/src/utils/translations/en.json b/src/utils/translations/en.json index 2eeeccb1a..f0a64def3 100644 --- a/src/utils/translations/en.json +++ b/src/utils/translations/en.json @@ -21,5 +21,6 @@ "cw.locationMessage.locationUrl": "URL", "cw.contactMessage.contact": "Contact", "cw.contactMessage.name": "Name", - "cw.contactMessage.number": "Number" + "cw.contactMessage.number": "Number", + "cw.message.edited": "Edited Message" } \ No newline at end of file diff --git a/src/utils/translations/pt-BR.json b/src/utils/translations/pt-BR.json index 52bfcd691..a8d62417c 100644 --- a/src/utils/translations/pt-BR.json +++ b/src/utils/translations/pt-BR.json @@ -21,5 +21,6 @@ "cw.locationMessage.locationUrl": "URL", "cw.contactMessage.contact": "Contato", "cw.contactMessage.name": "Nome", - "cw.contactMessage.number": "Número" + "cw.contactMessage.number": "Número", + "cw.message.edited": "Mensagem editada" } \ No newline at end of file diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 3f50f06dc..5341c02b6 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -2047,6 +2047,34 @@ export class ChatwootService { } } + if (event === 'messages.edit') { + const editedText = `${ + body?.editedMessage?.conversation || body?.editedMessage?.extendedTextMessage?.text + }\n\n_\`${i18next.t('cw.message.edited')}.\`_`; + const message = await this.getMessageByKeyId(instance, body?.key?.id); + const messageType = message.key?.fromMe ? 'outgoing' : 'incoming'; + + if (message && message.chatwoot?.conversationId) { + const send = await this.createMessage( + instance, + message.chatwoot.conversationId, + editedText, + messageType, + false, + [], + { + message: { extendedTextMessage: { contextInfo: { stanzaId: message.key.id } } }, + }, + 'WAID:' + body.key.id, + ); + if (!send) { + this.logger.warn('edited message not sent'); + return; + } + } + return; + } + if (event === 'messages.read') { this.logger.verbose('read message from instance: ' + instance.instanceName); diff --git a/src/whatsapp/services/whatsapp.baileys.service.ts b/src/whatsapp/services/whatsapp.baileys.service.ts index 6dc55e0c2..a081b5b74 100644 --- a/src/whatsapp/services/whatsapp.baileys.service.ts +++ b/src/whatsapp/services/whatsapp.baileys.service.ts @@ -937,6 +937,17 @@ export class BaileysStartupService extends WAStartupService { try { this.logger.verbose('Event received: messages.upsert'); for (const received of messages) { + if ( + this.localChatwoot.enabled && + (received.message?.protocolMessage?.editedMessage || received.message?.editedMessage?.message) + ) { + const editedMessage = + received.message?.protocolMessage || received.message?.editedMessage?.message?.protocolMessage; + if (editedMessage) { + this.chatwootService.eventWhatsapp('messages.edit', { instanceName: this.instance.name }, editedMessage); + } + } + if ( (type !== 'notify' && type !== 'append') || received.message?.protocolMessage ||