feat: Update chatwoot source ID and status after sent

This commit is contained in:
Judson Cairo 2024-09-27 09:40:18 -03:00
parent e241cf4ee0
commit f9726863ef
2 changed files with 12 additions and 0 deletions

View File

@ -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<MessageModel> {

View File

@ -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();