Merge pull request #378 from moraisamilton/develop

Implemented a function to synchronize message deletions on WhatsApp, automatically reflecting in Chatwoot.
This commit is contained in:
Davidson Gomes
2024-01-29 11:28:59 -03:00
committed by GitHub
6 changed files with 47 additions and 32 deletions

View File

@@ -26,7 +26,7 @@ export class MessageRaw {
messageType?: string;
messageTimestamp?: number | Long.Long;
owner: string;
source?: 'android' | 'web' | 'ios';
source?: 'android' | 'web' | 'ios' | 'unknown' | 'desktop';
source_id?: string;
source_reply_id?: string;
chatwoot?: ChatwootMessage;
@@ -45,7 +45,7 @@ const messageSchema = new Schema<MessageRaw>({
participant: { type: String },
messageType: { type: String },
message: { type: Object },
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios'] },
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios','unknown','desktop' ] },
messageTimestamp: { type: Number, required: true },
owner: { type: String, required: true, minlength: 1 },
chatwoot: {

View File

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