whatsapp-web.js
whatsapp-web.js copied to clipboard
What is the best strategy to scale-up multiple clients?
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
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, ;)
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
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.