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

Application crashes when replying to a revoked message

Open PGRjoystick opened this issue 10 months ago • 10 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

im trying to integrate chatgpt into whatsapp. When a user revokes their message in the middle of processing the reply, the application crashes with this error

home/joysky/ayanaboat/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229 throw new Error('Evaluation failed: ' + (0, util_js_1.getExceptionMessage)(exceptionDetails)); ^

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'unsafe') at window.WWebJS.sendMessage (pptr://puppeteer_evaluation_script:38:67) at pptr://puppeteer_evaluation_script:10:45 at ExecutionContext._ExecutionContext_evaluate (/home/joysky/ayanaboat/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/common/ExecutionContext.ts:294:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at ExecutionContext.evaluate (/home/joysky/ayanaboat/node_modules/whatsapp-web.js/node_modules/puppeteer-core/src/common/ExecutionContext.ts:137:12) at Client.sendMessage (/home/joysky/ayanaboat/node_modules/whatsapp-web.js/src/Client.js:938:28)

Node.js v18.17.1 error: script "start" exited with code 1 (SIGHUP)

i already tried to wrap the message.reply into try catch statement. its still crash. i also tried to print the message.rawData after the chatgpt finished proceesing the response and the user message is revoked. the message.type still returned chat, not revoked

Expected behavior

The application should not crash when a user revokes their message. Ideally, the library should provide a way to check if a message has been revoked in the middle of processing the replies before trying to reply to it.

Steps to Reproduce the Bug or Issue

  1. User sends a message
  2. Application receives the message and prepares to reply. this takes time
  3. Before the application can reply, the user revokes their message
  4. The application crashes with the error TypeError: Cannot read properties of undefined (reading 'unsafe')

Relevant Code

// WhatsApp message
client.on(Events.MESSAGE_RECEIVED, async (message: any) => {
	const gptResponse = await chatgpt.ask(message.body) // this process takes time
	message.reply(gptResponse); // the error occurs here
});

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Ubuntu 20.04 Phone OS: Android 14 whatsapp-web.js version: latest#webpack-exodus whatsapp web version: 2.3000.1012770224 node.js version: v18.17.1

Additional context

No response

PGRjoystick avatar Apr 14 '24 10:04 PGRjoystick

Same here

TheMacros avatar Apr 15 '24 07:04 TheMacros

remove all .wwebjs* files. delete node_modules folder. add this to your app,js image

and reinstall with npm -i its worked for me

cakracomp avatar Apr 16 '24 07:04 cakracomp

Same here!

image

najamrehman avatar Apr 17 '24 04:04 najamrehman

Same here!

image

Any clue ?

najamrehman avatar Apr 23 '24 03:04 najamrehman

Wrap it in try...catch

alechkos avatar May 06 '24 12:05 alechkos

Wrap it in try...catch

as i said before :

i already tried to wrap the message.reply into try catch statement. its still crash. i also tried to print the message.rawData after the chatgpt finished proceesing the response and the user message is revoked. the message.type still returned chat, not revoked

i already tried this in a try...catch statement. its still crash. please re-open this issue. im still having this problem.

the only workaround im using was sending the message using client.sendMessage method. but this method does not quoting the original user message

what i asking is, is there's a way to provide a status check if the message is already revoked by the user in the middle of trying to reply the message, rather than crash away.

PGRjoystick avatar May 07 '24 05:05 PGRjoystick

Hi, I have the same problem when I include options into sendMessage method:

let options = { quotedMessageId: quoted }; await client.sendMessage(phone, message, options);

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'unsafe')

elhumbertoz avatar Jun 16 '24 13:06 elhumbertoz

Please check this fix in order to send reply without error: #3108

This working for me. image

elhumbertoz avatar Jun 16 '24 22:06 elhumbertoz

Please check this fix in order to send reply without error: #3108

This working for me. image

Hello, i've tested this pr and still crashes with this error :

/home/joysky/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229
         throw new Error('Evaluation failed: ' + (0, util_js_1.getExceptionMessage)(exceptionDetails));
               ^
 Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'canReply')
     at window.WWebJS.sendMessage (pptr://__puppeteer_evaluation_script__:50:31)
     at pptr://__puppeteer_evaluation_script__:10:45
     at ExecutionContext._ExecutionContext_evaluate (/home/joysky/whatsapp-web.js/node_modules/puppeteer-core/src/common/ExecutionContext.ts:294:13)
     at processTicksAndRejections (node:internal/process/task_queues:95:5)
     at ExecutionContext.evaluate (/home/joysky/whatsapp-web.js/node_modules/puppeteer-core/src/common/ExecutionContext.ts:137:12)
     at Client.sendMessage (/home/joysky/whatsapp-web.js/src/Client.js:932:28)
 Node.js v18.20.4

PGRjoystick avatar Aug 14 '24 07:08 PGRjoystick

here is my code when executing message.reply() function on deleted message :

			// Default: raw Text reply

				try {
					trimmedTextResponse ? message.reply(trimmedTextResponse) : message.reply(response);
					sticker ? message.reply(sticker,'', {sendMediaAsSticker:true, stickerAuthor:'Ayana Izumi', stickerName:`Ayana ${currentEmotions? `${currentEmotions}` : null} sticker`}) : null;
				}
				catch (error) {
					console.log('Message Deleted');
				}

PGRjoystick avatar Aug 14 '24 07:08 PGRjoystick