#whatsapp-web.js and expressjs

5 messages · Page 1 of 1 (latest)

cerulean yarrow
#

Is it possible to create a restful api with expressjs which is integrated with wwebjs?, I want to interact with my bot via the api, such as creating new sessions, Send messages, and do other things using api. Give me an example of the code implementation.

keen ether
#

Yes, it's possible. You can create your express routes and interact with the lib, something like this:

app. get('/getstatus', async function (req, res) {
    var clientState = await client.getState();
    res.statusCode = 200;
    res.end('{"Sucesso":"true","state": ' + JSON.stringify(clientState) + '}');
});
cerulean yarrow
#

I want to ask sir, I use multi sessions, how can I interact with the sessions I choose, for example I create 2 new sessions, namely bot1 and bot2, both sessions are ready, how do I create a new endpoint to interact with my bot which has a bot2 session.

cerulean yarrow
#

Ohhh yes I succeeded, my problem is solved, I use an object to store an instance of the Client class when I create a new session, With that I can use the object according to my wishes, yes, maybe this method is already used by many people, But I am very happy to be able to solve this problem with my own logic.

#

Thank you for your help sir