mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
feat: added messages.delete event
This commit is contained in:
parent
c00f132145
commit
e6b0addb6c
@ -8,6 +8,7 @@
|
||||
* Now it's getting the API URL directly in the request, no longer need the variable in the env file
|
||||
* Removed link preview endpoint, now it's done automatically from sending conventional text
|
||||
* Added group membership validation before sending message to groups
|
||||
* Added messages.delete event
|
||||
|
||||
# 1.2.2 (2023-07-15 09:36)
|
||||
|
||||
|
@ -55,6 +55,7 @@ WEBHOOK_EVENTS_QRCODE_UPDATED=true
|
||||
WEBHOOK_EVENTS_MESSAGES_SET=true
|
||||
WEBHOOK_EVENTS_MESSAGES_UPSERT=true
|
||||
WEBHOOK_EVENTS_MESSAGES_UPDATE=true
|
||||
WEBHOOK_EVENTS_MESSAGES_DELETE=true
|
||||
WEBHOOK_EVENTS_SEND_MESSAGE=true
|
||||
WEBHOOK_EVENTS_CONTACTS_SET=true
|
||||
WEBHOOK_EVENTS_CONTACTS_UPSERT=true
|
||||
|
@ -59,6 +59,7 @@ ENV WEBHOOK_EVENTS_QRCODE_UPDATED=$WEBHOOK_EVENTS_QRCODE_UPDATED
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_SET=$WEBHOOK_EVENTS_MESSAGES_SET
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPSERT=$WEBHOOK_EVENTS_MESSAGES_UPSERT
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_UPDATE=$WEBHOOK_EVENTS_MESSAGES_UPDATE
|
||||
ENV WEBHOOK_EVENTS_MESSAGES_DELETE=$WEBHOOK_EVENTS_MESSAGES_DELETE
|
||||
ENV WEBHOOK_EVENTS_SEND_MESSAGE=$WEBHOOK_EVENTS_SEND_MESSAGE
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_SET=$WEBHOOK_EVENTS_CONTACTS_SET
|
||||
ENV WEBHOOK_EVENTS_CONTACTS_UPSERT=$WEBHOOK_EVENTS_CONTACTS_UPSERT
|
||||
|
@ -76,6 +76,7 @@ export type EventsWebhook = {
|
||||
MESSAGES_SET: boolean;
|
||||
MESSAGES_UPSERT: boolean;
|
||||
MESSAGES_UPDATE: boolean;
|
||||
MESSAGES_DELETE: boolean;
|
||||
SEND_MESSAGE: boolean;
|
||||
CONTACTS_SET: boolean;
|
||||
CONTACTS_UPDATE: boolean;
|
||||
@ -238,6 +239,7 @@ export class ConfigService {
|
||||
MESSAGES_SET: process.env?.WEBHOOK_EVENTS_MESSAGES_SET === 'true',
|
||||
MESSAGES_UPSERT: process.env?.WEBHOOK_EVENTS_MESSAGES_UPSERT === 'true',
|
||||
MESSAGES_UPDATE: process.env?.WEBHOOK_EVENTS_MESSAGES_UPDATE === 'true',
|
||||
MESSAGES_DELETE: process.env?.WEBHOOK_EVENTS_MESSAGES_DELETE === 'true',
|
||||
SEND_MESSAGE: process.env?.WEBHOOK_EVENTS_SEND_MESSAGE === 'true',
|
||||
CONTACTS_SET: process.env?.WEBHOOK_EVENTS_CONTACTS_SET === 'true',
|
||||
CONTACTS_UPDATE: process.env?.WEBHOOK_EVENTS_CONTACTS_UPDATE === 'true',
|
||||
|
@ -96,6 +96,7 @@ WEBHOOK:
|
||||
MESSAGES_SET: true
|
||||
MESSAGES_UPSERT: true
|
||||
MESSAGES_UPDATE: true
|
||||
MESSAGES_DELETE: true
|
||||
SEND_MESSAGE: true
|
||||
CONTACTS_SET: true
|
||||
CONTACTS_UPSERT: true
|
||||
|
@ -39,6 +39,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
@ -828,6 +829,7 @@ export const webhookSchema: JSONSchema7 = {
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
|
@ -1116,6 +1116,7 @@ export class WAStartupService {
|
||||
},
|
||||
|
||||
'messages.update': async (args: WAMessageUpdate[], database: Database) => {
|
||||
console.log(args);
|
||||
this.logger.verbose('Event received: messages.update');
|
||||
const status: Record<number, wa.StatusMessage> = {
|
||||
0: 'ERROR',
|
||||
@ -1126,11 +1127,7 @@ export class WAStartupService {
|
||||
5: 'PLAYED',
|
||||
};
|
||||
for await (const { key, update } of args) {
|
||||
if (
|
||||
key.remoteJid !== 'status@broadcast' &&
|
||||
!key?.remoteJid?.match(/(:\d+)/) &&
|
||||
key.fromMe
|
||||
) {
|
||||
if (key.remoteJid !== 'status@broadcast' && !key?.remoteJid?.match(/(:\d+)/)) {
|
||||
this.logger.verbose('Message update is valid');
|
||||
|
||||
let pollUpdates: any;
|
||||
@ -1150,6 +1147,16 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
if (status[update.status] === 'READ' && !key.fromMe) return;
|
||||
|
||||
if (update.message === null && update.status === undefined) {
|
||||
this.logger.verbose('Message deleted');
|
||||
|
||||
this.logger.verbose('Sending data to webhook in event MESSAGE_DELETE');
|
||||
await this.sendDataWebhook(Events.MESSAGES_DELETE, key);
|
||||
return;
|
||||
}
|
||||
|
||||
const message: MessageUpdateRaw = {
|
||||
...key,
|
||||
status: status[update.status],
|
||||
|
@ -9,6 +9,7 @@ export enum Events {
|
||||
MESSAGES_SET = 'messages.set',
|
||||
MESSAGES_UPSERT = 'messages.upsert',
|
||||
MESSAGES_UPDATE = 'messages.update',
|
||||
MESSAGES_DELETE = 'messages.delete',
|
||||
SEND_MESSAGE = 'send.message',
|
||||
CONTACTS_SET = 'contacts.set',
|
||||
CONTACTS_UPSERT = 'contacts.upsert',
|
||||
|
Loading…
Reference in New Issue
Block a user