Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconsistent output #1504

Closed
FerryAr opened this issue Jan 17, 2023 · 1 comment
Closed

Unconsistent output #1504

FerryAr opened this issue Jan 17, 2023 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@FerryAr
Copy link

FerryAr commented Jan 17, 2023

Description

Unconsistent output from getAllChats() and getAllChatsWithMessages()

Environment

  • WPPConnect version(s): 1.20.0
  • WA-JS version(s): 2.18.1
  • Browser: Chromium latest from Homebrew
  • OS: MacOS Monterey 12.6
  • Node version: Node 18.13.0
  • WhatsApp version: 2.22.24.78
  • MultiDevice (BETA): yes

Output

getAllChats()
Screen Shot 2023-01-17 at 09 03 03

getAllChatsWithMessages()
Screen Shot 2023-01-17 at 09 04 02

With getAllChats() I can see there is contact data but no message, but with getAllChatsWithMessages() the messages is there but not the contact data. I want to use the contact data to display the contact and the message data to display the latest message

@FerryAr FerryAr added bug Something isn't working needs triage labels Jan 17, 2023
@icleitoncosta
Copy link
Contributor

icleitoncosta commented Jan 20, 2023

This is a normal result, as this return comes from WhatsApp itself.
I suggest doing the following:

const allChatsWithMessages = await client.getAllChatsWithMessages();
for (const msgs of allChatsWithMessages) {
    const contact = await client.getChatById(msgs.id);
    msgs.contact = contact;
}
console.log(allChatsWithMessages)

With this code you will return the chat already formatted as you need. We avoid messing too much with the return of what WhatsApp sends us to avoid BREAKING CHANGES.

@FerryAr FerryAr closed this as completed Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants