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
15.53k stars 3.7k forks source link

Duplicate Contacts Returned by getContacts() Method #3272

Closed HosseinBabmoradi closed 2 months ago

HosseinBabmoradi commented 2 months ago

Is there an existing issue for this?

Describe the bug

When calling await this.client.getContacts(), the method returns duplicate contacts with the same name. One contact has the correct number, while the other (or multiple) contact(s) have numbers with an @lid suffix. This often results in more than two entries for the same contact, which seems incorrect.

Expected behavior

Only one entry should be returned for each contact, with the correct number (without the @lid suffix). Duplicate contacts with the same name but different number formats should not be included.

Steps to Reproduce the Bug or Issue

Call the getContacts() method: const contacts = await this.client.getContacts(); console.log(contacts); Observe that some contacts are returned multiple times with the same name: One contact has the correct phone number format. Other contacts have the same name but their numbers include the @lid suffix. Example: [ { "id": "123456789@c.us", "number": "123456789", "name": "John Doe" }, { "id": "123456789@lid", "number": "123456789", "name": "John Doe" } ]

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

whatsapp web js: [pedroslopez/whatsapp-web.js#webpack-exodus] Node.js Version: [v21.7.2] Operating System: [Windows]

Additional context

No response

HosseinBabmoradi commented 2 months ago

With this code i filtering data that i got from WhatsAppClient const filteredContacts = contacts.filter(contact => !contact.id.endsWith("@lid"));