whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

How to get original message id of the revoked message?

Open su-chang opened this issue 3 years ago • 6 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

When we received message_revoke_everyone event, we can get revoke message and original message, but they have the same messageId, we can not match the original message if we revoked some messages which are same to each other.

Example

// revoke message
{
  "id": {
    "fromMe": true,
    "remote": "[email protected]",
    "id": "3EB08BC1EAB45750A416",
    "_serialized": "[email protected]_3EB08BC1EAB45750A416"
  },
  "ack": 3,
  "hasMedia": false,
  "body": "",
  "type": "revoked",
  "timestamp": 1644233597,
  "from": "[email protected]",
  "to": "[email protected]",
  "deviceType": "web",
  "isForwarded": false,
  "forwardingScore": 0,
  "isStatus": false,
  "isStarred": false,
  "fromMe": true,
  "hasQuotedMsg": false,
  "vCards": [],
  "mentionedIds": [],
  "isGif": false,
  "isEphemeral": false,
  "links": []
}
// original message
{
  "id": {
    "fromMe": true,
    "remote": "[email protected]",
    "id": "3EB08BC1EAB45750A416",
    "_serialized": "[email protected]_3EB08BC1EAB45750A416"
  },
  "ack": 3,
  "hasMedia": false,
  "body": "dong",
  "type": "chat",
  "timestamp": 1644233597,
  "from": "[email protected]",
  "to": "[email protected]",
  "deviceType": "web",
  "isForwarded": false,
  "forwardingScore": 0,
  "isStatus": false,
  "isStarred": false,
  "fromMe": true,
  "hasQuotedMsg": false,
  "vCards": [],
  "mentionedIds": [],
  "isGif": false,
  "isEphemeral": false,
  "links": []
}

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

I'm not sure it could be supported by WhatsApp or not.

Additional context Add any other context or screenshots about the feature request here.

Related source code:

let last_message;

await page.exposeFunction('onChangeMessageTypeEvent', (msg) => {

    if (msg.type === 'revoked') {
        const message = new Message(this, msg);
        let revoked_msg;
        if (last_message && msg.id.id === last_message.id.id) {
            revoked_msg = new Message(this, last_message);
        }

        /**
         * Emitted when a message is deleted for everyone in the chat.
         * @event Client#message_revoke_everyone
         * @param {Message} message The message that was revoked, in its current state. It will not contain the original message's data.
         * @param {?Message} revoked_msg The message that was revoked, before it was revoked. It will contain the message's original data. 
         * Note that due to the way this data is captured, it may be possible that this param will be undefined.
         */
        this.emit(Events.MESSAGE_REVOKED_EVERYONE, message, revoked_msg);
    }

});

await page.exposeFunction('onChangeMessageEvent', (msg) => {

    if (msg.type !== 'revoked') {
        last_message = msg;
    }

});

su-chang avatar Feb 07 '22 12:02 su-chang

I am also needing the id of the message that has been deleted. After and Before have the same message id. Please fix if possible

AlloryDante avatar May 08 '22 09:05 AlloryDante

Same here. ID from the message delivered is diference the original message.

telmedola avatar Oct 14 '22 12:10 telmedola

Same issue here!!!!

CSFelix avatar Feb 28 '23 19:02 CSFelix

anyone knows if this is already fixed?

Matheus-Lima-Moreira avatar Jul 25 '23 14:07 Matheus-Lima-Moreira

The original message object and the revoked one have attribute type, then you can compare two message ids and also the value of type they have, if the revoked_message has the same id as a message but the value of type in revoked_message is revoked, then it is a sign that your original message was deleted.

alechkos avatar Apr 12 '24 14:04 alechkos

The original message object and the revoked one have attribute type, then you can compare two message ids and also the value of type they have, if the revoked_message has the same id as a message but the value of type in revoked_message is revoked, then it is a sign that your original message was deleted.

But the problem is the message with the ID that those two variables have was never sent. And the message that was deleted has the other ID. How to detect which message have been deleted?

TheMacros avatar Apr 12 '24 15:04 TheMacros