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

`getChats()` only returning 500 chats

Open leoffx opened this issue 2 years ago • 6 comments

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

  1. Create new session
  2. Scan QR
  3. 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

leoffx avatar Jun 30 '22 06:06 leoffx

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.

leoffx avatar Jun 30 '22 18:06 leoffx

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 reading getChats() again

leoffx avatar Jul 03 '22 21:07 leoffx

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

purpshell avatar Aug 02 '22 22:08 purpshell

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

leoffx avatar Aug 03 '22 08:08 leoffx

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!

bernardoely avatar Aug 21 '22 23:08 bernardoely

any solution to the problem?

tcccotacoes avatar Feb 16 '23 13:02 tcccotacoes

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.

mdedirudianto avatar Mar 20 '23 08:03 mdedirudianto

This was marked as closed and the problem still remains.

hdem607 avatar Dec 13 '23 13:12 hdem607

@hdem607 The problem is not with the library but with the whatsap web

alechkos avatar Dec 13 '23 13:12 alechkos