Closed TheMacros closed 10 months ago
You have to wait a bit while it fetches messages before calling this method, so after client connects, set a TimeOut or something to delay a bit while all messages are loading, then try get the messages, I hope this helps : )
You have to wait a bit while it fetches messages before calling this method, so after client connects, set a TimeOut or something to delay a bit while all messages are loading, then try get the messages, I hope this helps : )
Thanks, but if I run this
chat.fetchMessages({
fromMe: undefined,
limit: 1024
});
I get all messages (or 1024 max).
interesting, I am yet to experience that, I believe someone with more experience in that
"Infinity" should be a string. Works fine.
const messages = await chat.fetchMessages({limit: "Infinity"});
i've stumbled upon this error too
does anyone know if there's a pr for it already? i volunteer to fix this.
@HardRockPorn
this is supposed to be a number (or Infinity)
I just spent the last 4 hours debugging this behavior.
What I can resume from my findings:
chat.msgs.getModelsArray
)Store.ConversationMsgs.loadEarlierMsgs
)history sync on demmand
): This is where the problem residesloadEarlierMsgs
and a button appears so the user can force a history sync
from the device.The thing is, this method is not whell documented, but I have figured out how to call it and force it to load more messages, and even, be able to change "how many messages" to fetch from device at once.
moduleRaid
exists):Step 0: (optional) set how many messages to force a history sync
mR.findModule('bulkCreateOrReplaceABPropConfigs')[0].bulkCreateOrReplaceABPropConfigs([{
"configCode": 3811,
"configValue": 1000, // Default value is 50
"configExpoKey": null,
"hasAccessed": false
}])
Step 1: Trigger a History sync on demand
const HISTORY_SYNC_ON_DEMAND = 3 // Operation code declared a few times in source code
await mR.findModule('sendPeerDataOperationRequest')[0].sendPeerDataOperationRequest(HISTORY_SYNC_ON_DEMAND, {
"chatId": mR.findModule('createWid')[0].createWid('5511999999999@c.us') // The WID to Sync on demand goes here
})
Step 2: Use loadEarlierMsgs after finished (notice that this function is async, but doesn't wait until completion to return, need to investigate further)
Step 3: Read from getModelsArray as usual
This should be enough to force a on demand sync of a specific chat.
@ivanseidel, I didn't get your suggestion. Kind of hard to understand what to do to solve it, despite it is easy to understand the layers of data and how WA works behind the scenes. Why don't you PR with the suggestion? Your idea of forcing fetch, as user do (clicking on the button), is awesome.
Is there an existing issue for this?
Describe the bug
I'm trying to fetch all messages from all chats. As described in the documentation, I need to pass the Infinity to the limit property of the searchOptions https://docs.wwebjs.dev/Chat.html#fetchMessages. But I received only the latest message from the chat instead of all messages.
Expected behavior
As described in the documentation the method should return all messages from the chat.
Steps to Reproduce the Bug or Issue
Relevant Code
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Additional context
No response