whatsapp-web.js
whatsapp-web.js copied to clipboard
Reply message POST
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
- 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
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
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.
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
I would like to contribute here. I need some explanation about the problem
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
Not a lib bug
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.