diff --git a/index.d.ts b/index.d.ts index 8353c5a..bfa5e32 100644 --- a/index.d.ts +++ b/index.d.ts @@ -77,6 +77,9 @@ declare namespace WAWebJS { /** Check if a given ID is registered in whatsapp */ isRegisteredUser(contactId: string): Promise + /** Get the registered WhatsApp ID for a number. Returns null if the number is not registered on WhatsApp. */ + getNumberId(number: string): Promise + /** * Mutes the Chat until a specified date * @param chatId ID of the chat that will be muted diff --git a/src/Client.js b/src/Client.js index 0aa30be..8560094 100644 --- a/src/Client.js +++ b/src/Client.js @@ -712,6 +712,26 @@ class Client extends EventEmitter { }, id); } + /** + * Get the registered WhatsApp ID for a number. + * Will return null if the number is not registered on WhatsApp. + * @param {string} number Number or ID ("@c.us" will be automatically appended if not specified) + * @returns {Promise} + */ + async getNumberId(number) { + if(!number.endsWith('@c.us')) { + number += '@c.us'; + } + + try { + return await this.pupPage.evaluate(async numberId => { + return window.WWebJS.getNumberId(numberId); + }, number); + } catch(_) { + return null; + } + } + /** * Create a new group * @param {string} name group title diff --git a/src/util/Injected.js b/src/util/Injected.js index 9460c03..0e15e90 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -34,6 +34,7 @@ exports.ExposeStore = (moduleRaidStr) => { exports.LoadUtils = () => { window.WWebJS = {}; + window.WWebJS.getNumberId = async (id) => { let result = await window.Store.Wap.queryExist(id); @@ -41,6 +42,7 @@ exports.LoadUtils = () => { throw 'The number provided is not a registered whatsapp user'; return result.jid; }; + window.WWebJS.sendSeen = async (chatId) => { let chat = window.Store.Chat.get(chatId); if (chat !== undefined) { @@ -50,6 +52,7 @@ exports.LoadUtils = () => { return false; }; + window.WWebJS.sendMessage = async (chat, content, options = {}) => { let attOptions = {}; if (options.attachment) {