F
F
faketox2022-01-31 21:08:56
Node.js
faketox, 2022-01-31 21:08:56

How to make a REST API wrapper over a library?

I found the whatsapp-web.js library , I wanted to make an internal service with the REST API. But the library code is written in an event style and all attempts were unsuccessful. For example, a qr-code request is executed automatically after calling initialize();

const client = new Client();
client.on('qr', (qr) => {
    console.log('QR RECEIVED', qr);
});
client.initialize();

In my case, I would like to do this through an endpoint like /qr_generate.

Also, when disconnected from the side, an event occurs
client.on('disconnected', (reason) => {
    console.log('Client was logged out', reason);
});

In this case, you must completely recreate the Client object and hang events on it again.
I'm not strong in JavaScript, maybe I don't know some features. Tell me please :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question