whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

What is the best strategy to scale-up multiple clients?

Open thEpisode opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I know this is not a bug, but I want to know how many memory consume every client? because I want to design a high level orchestrator system to support multiple clients, a single app to create n clients? or maybe multiple Node.js apps? in my use case I want to use more than 10 clients at the same time and I want to create a good approach in architecture design. Thanks

Expected behavior

Create a websocket orchestrator to handle more than 10 clients.

Steps to Reproduce the Bug or Issue

Not an issue

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Debian, Raspberry Pi Phone: Android

Additional context

No response

thEpisode avatar Feb 24 '23 00:02 thEpisode

You could use a Node Server and write a object that handles whatsapps sessions, then persist the data in a My SQL with messages yours customers want to send, the object will need a set interval method that get messages from the database and send them regurlaly, as well get results from those sent messages in order to persist it in database. If has anyone a better context to do it, please, feel confortable to teach us, ;)

CelsoFurtunato avatar Mar 09 '23 18:03 CelsoFurtunato

i'm totally agreed with @CelsoFurtunato answer, but i think, instead of setting interval and create and write to DB, you can save to db in any listeners onMessage etc

mkhotib20 avatar Apr 20 '23 05:04 mkhotib20

Hi, I wanted to try a Multiple Clients system but somehow, I am not able to get unique ids for each client.

What I tried is that in a loop, initialized no. of clients. These were then added to an array. But only one client is working.

I am new to nodejs, so please excuse my coding standards:

`const qrcode = require ('qrcode-terminal') const fs = require('fs') const {Client, LocalAuth, AuthStrategy} = require ('whatsapp-web.js')

const SESSION_FILE_PATH = './sessions.json'; const CLIENTS_COUNT = 2;

let sessionData; if(fs.existsSync(SESSION_FILE_PATH)){ sessionData = require(SESSION_FILE_PATH); }

const clients = [];

for( i = 0; i< CLIENTS_COUNT; i++) {

console.log (Initializing client: ${i}); var client = new Client({ authStrategy: new LocalAuth( {clientId: client-${i}} )} ); client.on('qr', (qr) => { console.log(this); console.log(client.info); console.log(QR Received for client ${client.clientId}, qr); qrcode.generate(qr, {small: true}); });

cliclient. Onessage', message => { console.log(message.body); console.log(message.from); client.sendMessage(message.from, "Thank you for sending me a message"); });

client.on('ready', () => { console.log(Client ${i} is ready); });

client.initialize().then(clients.push(client));

}

//Close the process and dispose the clients process.on('SIGINT', async() => { console.log('(SIGINT) Shutting down...'); await client.destroy(); console.log('Client destroyed'); process. Exit(0);

});`

These lines don't give the desired output: console.log(QR Received for client ${client.clientId}, qr);
// Output: QR Received for client undefined

Is it possible to access clientId in every function / event.

gr8tushar avatar Apr 28 '23 08:04 gr8tushar