waha icon indicating copy to clipboard operation
waha copied to clipboard

[WEBJS] - Deletes a message from the chat

Open yekdev opened this issue 9 months ago • 4 comments

It deletes the message on the first request, but gives an error on the second request.

DELETE /api/{session}/chats/{chatId}/messages/{messageId}

{
  "statusCode": 500,
  "timestamp": "2026-02-09T01:24:10.131Z",
  "exception": {
    "message": "Cannot read properties of undefined (reading 'id')",
    "name": "TypeError",
    "stack": "TypeError: Cannot read properties of undefined (reading 'id')\n    at evaluate (evaluate at WPage.evaluate (/var/www/vhosts/{domain}/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:2:51)\n    at #evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)\n    at async ExecutionContext.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:277:16)\n    at async IsolatedWorld.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:100:16)\n    at async CdpFrame.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:362:20)\n    at async CdpPage.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:818:20)\n    at async WPage.evaluate (/var/www/vhosts/{domain}/app/dist/core/engines/webjs/WPage.js:13:20)\n    at async Message.delete (/var/www/vhosts/{domain}/app/node_modules/whatsapp-web.js/src/structures/Message.js:512:9)\n    at async descriptor.value (/var/www/vhosts/{domain}/app/dist/core/abc/activity.js:9:20)"
  },
  "request": {
    "path": "/api/{session}chats/{chatId}/messages/{messageId}",
    "method": "DELETE",
    "query": {}
  },
  "version": {
    "version": "2025.2.1",
    "engine": "WEBJS",
    "tier": "PLUS",
    "browser": "/usr/bin/google-chrome-stable"
  }
}

Version

{
  "version": "2025.2.1",
  "engine": "WEBJS",
  "tier": "PLUS",
  "browser": "/usr/bin/google-chrome-stable"
}

patron:PLUS

yekdev avatar Feb 09 '26 01:02 yekdev

@devlikepro please read my brother

WhatsApp changes the message id when a message is deleted. When a message is deleted, it needs to return the deleted message id; this point is very important.

The deleted message id remains under _data.protocolMessageKey._serialized when retrieving messages. /api/{session}/chats/{chatId}/messages

We need to re-fetch messages each time to get a new message id, which significantly slows us down.

patron:PLUS

yekdev avatar Feb 10 '26 00:02 yekdev

Hi! Could you explain a bit your case?

gives an error on the second request.

Do you run DELETE 2 times for the same message id?

patron:PRO

devlikepro avatar Feb 16 '26 08:02 devlikepro

Yes, it gives an error when I run DELETE twice. What I want is for it to return the deleted message id when the message is deleted.

It only returns the headers.

If you really want to have healthy methods, I can contact you so we can solve the errors.

patron:PLUS

yekdev avatar Feb 16 '26 22:02 yekdev

it gives an error when I run DELETE twice

Well, it shouldn't give an exception that's true, but it anyway should return something like 404 when you call it the second time.

patron:PRO

devlikepro avatar Feb 17 '26 04:02 devlikepro