mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-01-09 05:12:28 -06:00
Implemented a function to synchronize message deletions on WhatsApp, automatically reflecting in Chatwoot
A new variable has been created, and a function has been implemented to manage the deletion of messages on WhatsApp. Now, when deleting a message for everyone on WhatsApp, the same action will be automatically performed on Chatwoot, ensuring consistency across platforms
This commit is contained in:
@@ -7,7 +7,7 @@ import Jimp from 'jimp';
|
||||
import mimeTypes from 'mime-types';
|
||||
import path from 'path';
|
||||
|
||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||
import { ConfigService, HttpServer, ChatWoot} from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ICache } from '../abstract/abstract.cache';
|
||||
import { ChatwootDto } from '../dto/chatwoot.dto';
|
||||
@@ -1894,33 +1894,37 @@ export class ChatwootService {
|
||||
}
|
||||
|
||||
if (event === Events.MESSAGES_DELETE) {
|
||||
this.logger.verbose('deleting message from instance: ' + instance.instanceName);
|
||||
|
||||
const chatwootDelete = this.configService.get<ChatWoot>('CHATWOOT').MESSAGE_DELETE
|
||||
if (chatwootDelete === true) {
|
||||
this.logger.verbose('deleting message from instance: ' + instance.instanceName);
|
||||
|
||||
if (!body?.key?.id) {
|
||||
this.logger.warn('message id not found');
|
||||
return;
|
||||
}
|
||||
if (!body?.key?.id) {
|
||||
this.logger.warn('message id not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const message = await this.getMessageByKeyId(instance, body.key.id);
|
||||
if (message?.chatwoot?.messageId && message?.chatwoot?.conversationId) {
|
||||
this.logger.verbose('deleting message in repository. Message id: ' + body.key.id);
|
||||
this.repository.message.delete({
|
||||
where: {
|
||||
key: {
|
||||
id: body.key.id,
|
||||
},
|
||||
owner: instance.instanceName,
|
||||
},
|
||||
});
|
||||
const message = await this.getMessageByKeyId(instance, body.key.id);
|
||||
if (message?.chatwoot?.messageId && message?.chatwoot?.conversationId) {
|
||||
this.logger.verbose('deleting message in repository. Message id: ' + body.key.id);
|
||||
this.repository.message.delete({
|
||||
where: {
|
||||
key: {
|
||||
id: body.key.id,
|
||||
},
|
||||
owner: instance.instanceName,
|
||||
},
|
||||
});
|
||||
|
||||
this.logger.verbose('deleting message in chatwoot. Message id: ' + body.key.id);
|
||||
return await client.messages.delete({
|
||||
accountId: this.provider.account_id,
|
||||
conversationId: message.chatwoot.conversationId,
|
||||
messageId: message.chatwoot.messageId,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.logger.verbose('deleting message in chatwoot. Message id: ' + body.key.id);
|
||||
return await client.messages.delete({
|
||||
accountId: this.provider.account_id,
|
||||
conversationId: message.chatwoot.conversationId,
|
||||
messageId: message.chatwoot.messageId,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'messages.read') {
|
||||
this.logger.verbose('read message from instance: ' + instance.instanceName);
|
||||
|
||||
Reference in New Issue
Block a user