mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
feat: add logical or permanent message deletion based on env config
This commit is contained in:
parent
ab0fedf484
commit
45acc6d281
@ -41,6 +41,7 @@ DATABASE_SAVE_DATA_LABELS=true
|
|||||||
DATABASE_SAVE_DATA_HISTORIC=true
|
DATABASE_SAVE_DATA_HISTORIC=true
|
||||||
DATABASE_SAVE_IS_ON_WHATSAPP=true
|
DATABASE_SAVE_IS_ON_WHATSAPP=true
|
||||||
DATABASE_SAVE_IS_ON_WHATSAPP_DAYS=7
|
DATABASE_SAVE_IS_ON_WHATSAPP_DAYS=7
|
||||||
|
DATABASE_DELETE_MESSAGE=true
|
||||||
|
|
||||||
# RabbitMQ - Environment variables
|
# RabbitMQ - Environment variables
|
||||||
RABBITMQ_ENABLED=false
|
RABBITMQ_ENABLED=false
|
||||||
|
@ -3003,7 +3003,49 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
public async deleteMessage(del: DeleteMessage) {
|
public async deleteMessage(del: DeleteMessage) {
|
||||||
try {
|
try {
|
||||||
return await this.client.sendMessage(del.remoteJid, { delete: del });
|
const response = await this.client.sendMessage(del.remoteJid, { delete: del });
|
||||||
|
if (response) {
|
||||||
|
const messageId = response.message?.protocolMessage?.key?.id;
|
||||||
|
if (messageId) {
|
||||||
|
const isLogicalDeleted = configService.get<Database>('DATABASE').DELETE_DATA.LOGICAL_MESSAGE_DELETE;
|
||||||
|
let message = await this.prismaRepository.message.findUnique({
|
||||||
|
where: { id: messageId },
|
||||||
|
});
|
||||||
|
if (isLogicalDeleted) {
|
||||||
|
if (!message) return response;
|
||||||
|
const existingKey = typeof message?.key === 'object' && message.key !== null ? message.key : {};
|
||||||
|
message = await this.prismaRepository.message.update({
|
||||||
|
where: { id: messageId },
|
||||||
|
data: {
|
||||||
|
key: {
|
||||||
|
...existingKey,
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await this.prismaRepository.message.deleteMany({
|
||||||
|
where: {
|
||||||
|
id: messageId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.sendDataWebhook(Events.MESSAGES_DELETE, {
|
||||||
|
id: message.id,
|
||||||
|
instanceId: message.instanceId,
|
||||||
|
key: message.key,
|
||||||
|
messageType: message.messageType,
|
||||||
|
status: message.status,
|
||||||
|
source: message.source,
|
||||||
|
messageTimestamp: message.messageTimestamp,
|
||||||
|
pushName: message.pushName,
|
||||||
|
participant: message.participant,
|
||||||
|
message: message.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString());
|
throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString());
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,12 @@ export type Database = {
|
|||||||
CONNECTION: DBConnection;
|
CONNECTION: DBConnection;
|
||||||
PROVIDER: string;
|
PROVIDER: string;
|
||||||
SAVE_DATA: SaveData;
|
SAVE_DATA: SaveData;
|
||||||
|
DELETE_DATA: DeleteData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DeleteData = {
|
||||||
|
LOGICAL_MESSAGE_DELETE: boolean;
|
||||||
|
};
|
||||||
export type EventsRabbitmq = {
|
export type EventsRabbitmq = {
|
||||||
APPLICATION_STARTUP: boolean;
|
APPLICATION_STARTUP: boolean;
|
||||||
INSTANCE_CREATE: boolean;
|
INSTANCE_CREATE: boolean;
|
||||||
@ -300,6 +304,9 @@ export class ConfigService {
|
|||||||
IS_ON_WHATSAPP: process.env?.DATABASE_SAVE_IS_ON_WHATSAPP === 'true',
|
IS_ON_WHATSAPP: process.env?.DATABASE_SAVE_IS_ON_WHATSAPP === 'true',
|
||||||
IS_ON_WHATSAPP_DAYS: Number.parseInt(process.env?.DATABASE_SAVE_IS_ON_WHATSAPP_DAYS ?? '7'),
|
IS_ON_WHATSAPP_DAYS: Number.parseInt(process.env?.DATABASE_SAVE_IS_ON_WHATSAPP_DAYS ?? '7'),
|
||||||
},
|
},
|
||||||
|
DELETE_DATA: {
|
||||||
|
LOGICAL_MESSAGE_DELETE: process.env?.DATABASE_DELETE_MESSAGE === 'true',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RABBITMQ: {
|
RABBITMQ: {
|
||||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||||
|
Loading…
Reference in New Issue
Block a user