pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.24k stars 3.63k forks source link

Reply message POST #2146

Closed cirovas closed 10 months ago

cirovas commented 1 year ago

Is there an existing issue for this?

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

tofers commented 1 year ago

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

cirovas commented 1 year ago

Thank you for reply!

The first option, I´m sending as below:

chatId: 552799000570@c.us 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.

RC047 commented 1 year ago

Thank you for reply!

The first option, I´m sending as below:

chatId: 552799000570@c.us 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 true_552799000570@c.us_86E716FDB466DEADE8E2E2B5C016F309

Vishal77fsd commented 1 year ago

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

fernandomondo commented 1 year ago

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

alechkos commented 10 months ago

Not a lib bug

daveckw commented 4 months ago

Thank you for reply! The first option, I´m sending as below: chatId: 552799000570@c.us 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 true_552799000570@c.us_86E716FDB466DEADE8E2E2B5C016F309

This fixed the issue. Thanks.