Hey guys, suddenly my application stopped working as soon as I moved it to DigitalOcean. Here's the problem breakdown:
- I scan the QR code and the whatsapp gets authenticated.
- When I send message through an API it just returns
{status: false, response: []} - When I restart my application using
pm2 restartit returns the status true BUT it doesn't actually sends the whatsapp message.
My API:
app.post("/send-message", async (req, res) => {
console.log(req.body);
const sender = req.body.sender;
const number = phoneNumberFormatter(req.body.number);
const message = req.body.message;
const client = sessions.find((sess) => sess.id == sender)?.client;
// Make sure the sender is exists & ready
if (!client) {
return res.status(422).json({
status: false,
message: `The sender: ${sender} is not found!`,
});
} else {
console.log("Client found with id " + sender);
}
/**
* Check if the number is already registered
* Copied from app.js
*
* Please check app.js for more validations example
* You can add the same here!
*/
const isRegisteredNumber = await client.isRegisteredUser(number);
if (!isRegisteredNumber) {
return res.status(422).json({
status: false,
message: "The number is not registered",
});
}
client
.sendMessage(number, message)
.then((response) => {
res.status(200).json({
status: true,
response: response,
});
})
.catch((err) => {
console.log("ERROR OCCURED! " + err);
res.status(500).json({
status: false,
response: err,
});
});
});
My console log when I log the client (attached)