whatsapp-web.js
whatsapp-web.js copied to clipboard
`getChats()` only returning 500 chats
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
When calling getChats()
after the ready
event, only 500 chats are found.
Expected behavior
If you have more than 500 chats, all the chats should be return.
Steps to Reproduce the Bug or Issue
- Create new session
- Scan QR
- Immediately after 'ready' event, call
getChats()
Relevant Code
const qrcode = require('qrcode-terminal');
const { Client } = require('whatsapp-web.js');
const client = new Client();
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
const chats = await client.getChats();
console.log(chats.length); // even if you have more than 500 chats, 500 will be printed
});
client.initialize();
Browser Type
Chromium
WhatsApp Account Type
WhatsApp Business
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
OS: Windows, Ubuntu Phone OS: Android whatsapp-web.js 1.7.0 WhatsApp Web version: 2.2222.11 Node.js Version: v16.13.2
Additional context
No response
This could be related to business accounts, I tested here on some normal ones, and it was working fine. The business ones are still only finding 500, but I don't have access to one to debug it.
The virtual scroll used by WhatsApp might have a part in this.
after talking to @PurpShell on Discord, he suspects it's a serialization limit and we might need to chunk up the chats somehow.
Things I've tried before and didn't work:
- having a 30 seconds timeout to see if the rest of the chats would load up
- calling
getChats()
, scrolling down the chats (document.querySelector('#pane-side').scrollBy({top: 999999,left: 0,behavior: 'smooth'})
), and readinggetChats()
again
hmm as said before. We could probably implement pagination to fix this issue.. also If you are using MD, it might not be even loading the chats at all to preserve RAM
this is a bigger issue related to whatsapp web. I'm not sure there's something we can do. Feel free to test the following and confirm if it's also like this for you:
- have a phone with over 1000 chats and non business whatsapp
- open whatsapp web
- scroll down on chat list, and verify not all chats are loaded
hmm as said before. We could probably implement pagination to fix this issue.. also If you are using MD, it might not be even loading the chats at all to preserve RAM
Pagination and some filter in getChats() would be really nice, because we also need to pull them all since we don't have filters or pagination. Also, WhatsApp Web shows to the left the last message of the chat besides the "chat name". Including the last message of the chat on getChats() may be a nice feature as well.
Thank you!
any solution to the problem?
I tried with a personal account, not the business. It also faced the same issue, only loading around 500 chats.
One tricky way for business account is to select all of the chats and then label it. We can access all the chat numbers from Label object collection.
This was marked as closed and the problem still remains.
@hdem607 The problem is not with the library but with the whatsap web