#Return false with active session

11 messages · Page 1 of 1 (latest)

halcyon matrix
#

Hey guys, suddenly my application stopped working as soon as I moved it to DigitalOcean. Here's the problem breakdown:

  1. I scan the QR code and the whatsapp gets authenticated.
  2. When I send message through an API it just returns {status: false, response: []}
  3. When I restart my application using pm2 restart it 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)

#

PS: When I added a console log to the catch I get ```
ERROR OCCURED! TypeError: data.id.id.substring is not a function


And this code is present in Message.js of whatsapp-web.js

```js
        /**
         * String that represents from which device type the message was sent
         * @type {string}
         */
        this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';

cerulean slate
#

Bro it is default behaviour, you can change it on your main index.js file.

By creating client with the previous client I'd.. when server restarts, refresh client connection automatically..

halcyon matrix
cerulean slate
#

Means you have to call your client setup function again after restarting server..

#

With same client I'd..

#

Via any api request or directly in main js file..

halcyon matrix
cerulean slate
#

What type of message you are sending ?
Can you share code snippet

proven jetty
#

I'm having the same problem trying to send buttons