pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.62k stars 3.48k forks source link

`getChats()` only returning 500 chats #1557

Closed leoffx closed 7 months ago

leoffx commented 2 years ago

Is there an existing issue for this?

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 commented 2 years ago

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 commented 2 years ago

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:

PurpShell commented 1 year ago

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

leoffx commented 1 year ago

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:

bernardoely commented 1 year ago

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!

tcccotacoes commented 1 year ago

any solution to the problem?

mdedirudianto commented 1 year ago

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.

hdem607 commented 7 months ago

This was marked as closed and the problem still remains.

alechkos commented 7 months ago

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