diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index fe1c0301..1f370fb1 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1453,6 +1453,10 @@ export class ChatwootService { chatwootIsRead: chatwootMessageIds.isRead, }, }); + + if (this.isImportHistoryAvailable()) { + chatwootImport.updateMessageSourceID(chatwootMessageIds.messageId, key.id); + } } private async getMessageByKeyId(instance: InstanceDto, keyId: string): Promise { diff --git a/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts b/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts index 8f1ae580..a486eab0 100644 --- a/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts +++ b/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts @@ -542,6 +542,14 @@ class ChatwootImport { public isIgnorePhoneNumber(remoteJid: string) { return this.isGroup(remoteJid) || remoteJid === 'status@broadcast' || remoteJid === '0@s.whatsapp.net'; } + + public updateMessageSourceID(messageId: string | number, sourceId: string) { + const pgClient = postgresClient.getChatwootConnection(); + + const sql = `UPDATE messages SET source_id = $1, status = 0 WHERE id = $2;`; + + return pgClient.query(sql, [`WAID:${sourceId}`, messageId]); + } } export const chatwootImport = new ChatwootImport();