mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 03:56:54 -06:00
Merge pull request #474 from jaison-x/edit-message
feat(chatwoot): show edited messages from WhatsApp in Chatwoot
This commit is contained in:
commit
ee1e4623a3
@ -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"
|
||||
}
|
@ -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"
|
||||
}
|
@ -2078,6 +2078,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);
|
||||
|
||||
|
@ -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 ||
|
||||
|
Loading…
Reference in New Issue
Block a user