From 81fb154a9fdf7451ba988ae827a5a32697b3ff99 Mon Sep 17 00:00:00 2001 From: BenyFilho <168232825+BenyFilho@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:39:39 -0300 Subject: [PATCH] feat: getContactLidAndPhone (#3673) * Add method getContactLidOrPhone * Add method getContactLidOrPhone * Add method getContactLidOrPhone * Add method getContactLidOrPhone * Add method getContactLidOrPhone * Add method getContactLidOrPhone Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * Add method getContactLidOrPhone Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * Add method getContactLidOrPhone Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * Add method getContactLidOrPhone * Delete docs/index.html * Delete docs/Client.html * Create Client.html * Create index.html * Update to return the object * Update to return an object * Update Client.js to return both objects lid and phone * Update Client.js to return both objects lid and phone * Update src/Client.js Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * Update src/Client.js Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * Update index.d.ts Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> * refactor: rename function name for more clarity * Change accept and return Array * Change accept and return Array --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> --- index.d.ts | 3 +++ src/Client.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/index.d.ts b/index.d.ts index 9ed85e6..c0d05c9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -242,6 +242,9 @@ declare namespace WAWebJS { /** Deletes the contact from user's addressbook */ deleteAddressbookContact(honeNumber: string): Promise + + /** Get Contact lid and phone */ + getContactLidAndPhone(userIds: string[]): Promise<{ lid: string; pn: string }[]> /** Changes and returns the archive state of the Chat */ unarchiveChat(chatId: string): Promise diff --git a/src/Client.js b/src/Client.js index bd9758f..e44798e 100644 --- a/src/Client.js +++ b/src/Client.js @@ -2180,6 +2180,28 @@ class Client extends EventEmitter { return await window.Store.AddressbookContactUtils.deleteContactAction(phoneNumber); }, phoneNumber); } + + /** + * Get lid and phone number for multiple users + * @param {string[]} userIds - Array of user IDs + * @returns {Promise>} + */ + async getContactLidAndPhone(userIds) { + return await this.pupPage.evaluate((userIds) => { + !Array.isArray(userIds) && (userIds = [userIds]); + return userIds.map(userId => { + const wid = window.Store.WidFactory.createWid(userId); + const isLid = wid.server === 'lid'; + const lid = isLid ? wid : window.Store.LidUtils.getCurrentLid(wid); + const phone = isLid ? window.Store.LidUtils.getPhoneNumber(wid) : wid; + + return { + lid: lid._serialized, + pn: phone._serialized + }; + }); + }, userIds); + } } module.exports = Client;