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

Reply message POST

Open cirovas opened this issue 2 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I need to create a POST endpoint to reply messages. Im getting error running code below. What could be wrong?

// reply message app.post('/reply', async (req, res) => { const chatId = req.body.chatId const body = req.body.body const messageId = req.body.messageId

let options = { quotedMessageId: messageId };

await client.sendMessage(chatId, body, options) .then(response => { res.status(200).json({ status: true, response: response }); }) .catch(err => { console.error(err); // adicionando console.error para exibir o erro no console res.status(500).json({ status: false, response: err }); }); });

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'unsafe') at window.WWebJS.sendMessage (puppeteer_evaluation_script:36:67) at puppeteer_evaluation_script:10:45 at ExecutionContext._evaluateInternal (/home/ubuntu/whatsapp-api/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js :221:19) at process._tickCallback (internal/process/next_tick.js:68:7)

you click this button)' } },

Expected behavior

Reply message with quoteMessageId

Steps to Reproduce the Bug or Issue

  1. POST message

Relevant Code

// reply message app.post('/reply', async (req, res) => { const chatId = req.body.chatId const body = req.body.body const messageId = req.body.messageId

let options = { quotedMessageId: messageId };

await client.sendMessage(chatId, body, options) .then(response => { res.status(200).json({ status: true, response: response }); }) .catch(err => { console.error(err); // adicionando console.error para exibir o erro no console res.status(500).json({ status: false, response: err }); }); });

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

whatsapp-web.js version 1.19.5

Additional context

No response

cirovas avatar Apr 15 '23 21:04 cirovas

Most likely you have the wrong message ID or the second option is that the message you quoted is not loaded (not in the cache)

I checked, the quotation works

tofers avatar Apr 16 '23 04:04 tofers

Thank you for reply!

The first option, I´m sending as below:

chatId: [email protected] messageId: 86E716FDB466DEADE8E2E2B5C016F309 body: Test

The second option, I´ve tried with many different messages and get the same error, any idea what I have to check and how to do it?

Thank you again.

cirovas avatar Apr 17 '23 02:04 cirovas

Thank you for reply!

The first option, I´m sending as below:

chatId: [email protected] messageId: 86E716FDB466DEADE8E2E2B5C016F309 body: Test

The second option, I´ve tried with many different messages and get the same error, any idea what I have to check and how to do it?

Thank you again.

message id should be a serialized like this [email protected]_86E716FDB466DEADE8E2E2B5C016F309

RC047 avatar Apr 17 '23 02:04 RC047

I would like to contribute here. I need some explanation about the problem

Vishal77fsd avatar Apr 19 '23 17:04 Vishal77fsd

I dont have problem send a reply message, however, in the phone the link is not working. https://github.com/pedroslopez/whatsapp-web.js/issues/1944

fernandomondo avatar Jul 17 '23 19:07 fernandomondo

Not a lib bug

alechkos avatar Dec 04 '23 01:12 alechkos

Thank you for reply! The first option, I´m sending as below: chatId: [email protected] messageId: 86E716FDB466DEADE8E2E2B5C016F309 body: Test The second option, I´ve tried with many different messages and get the same error, any idea what I have to check and how to do it? Thank you again.

message id should be a serialized like this [email protected]_86E716FDB466DEADE8E2E2B5C016F309

This fixed the issue. Thanks.

daveckw avatar May 21 '24 15:05 daveckw