fix: when deleting a message in whatsapp, delete the message in chatwoot too

The message model schema was changed. Old format in message model was field chatwootMessageId. Now we have a document chatwoot with new properties.

I cant find a simple way to create a migration function up then the old field was no migrate to new format.
This commit is contained in:
jaison-x
2023-12-20 17:53:37 -03:00
parent 060a945aea
commit 07e8449379
4 changed files with 100 additions and 26 deletions

View File

@@ -1798,7 +1798,11 @@ export class WAStartupService {
);
if (chatwootSentMessage?.id) {
messageRaw.chatwootMessageId = chatwootSentMessage.id;
messageRaw.chatwoot = {
messageId: chatwootSentMessage.id,
inboxId: chatwootSentMessage.inbox_id,
conversationId: chatwootSentMessage.conversation_id,
};
}
}
@@ -1941,6 +1945,22 @@ export class WAStartupService {
this.instance.name,
database.SAVE_DATA.MESSAGE_UPDATE,
);
if (this.localChatwoot.enabled) {
this.chatwootService.eventWhatsapp(
Events.MESSAGES_DELETE,
{ instanceName: this.instance.name },
{
key: {
remoteJid: key.remoteJid,
fromMe: key.fromMe,
id: key.id,
participant: key.participant,
},
},
);
}
return;
}