mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 12:39:20 +00:00
feat: Delete messages
This commit is contained in:
@@ -152,6 +152,13 @@ client.on('message', async msg => {
|
|||||||
chat.sendMessage(`Hi @${contact.number}!`, {
|
chat.sendMessage(`Hi @${contact.number}!`, {
|
||||||
mentions: [contact]
|
mentions: [contact]
|
||||||
});
|
});
|
||||||
|
} else if (msg.body == '!delete' && msg.hasQuotedMsg) {
|
||||||
|
const quotedMsg = await msg.getQuotedMessage();
|
||||||
|
if(quotedMsg.fromMe) {
|
||||||
|
quotedMsg.delete(true);
|
||||||
|
} else {
|
||||||
|
msg.reply('I can only delete my own messages');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,22 @@ class Message extends Base {
|
|||||||
|
|
||||||
return new MessageMedia(mimetype, data, filename);
|
return new MessageMedia(mimetype, data, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a message from the chat
|
||||||
|
* @param {?boolean} everyone If true and the message is sent by the current user, will delete it for everyone in the chat.
|
||||||
|
*/
|
||||||
|
async delete(everyone) {
|
||||||
|
await this.client.pupPage.evaluate((msgId, everyone) => {
|
||||||
|
let msg = window.Store.Msg.get(msgId);
|
||||||
|
|
||||||
|
if(everyone && msg.id.fromMe && msg.canRevoke()) {
|
||||||
|
return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.Store.Cmd.sendDeleteMsgs(msg.chat, [msg], true);
|
||||||
|
}, this.id._serialized, everyone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Message;
|
module.exports = Message;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
|
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
|
||||||
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
||||||
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
||||||
|
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
|
||||||
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user