mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: Get registered ID for a given phone number (#483)
Exposes internal getNumberById function for easy usage. This can help with dealing with brazilian numbers with the extra digit, always returning the correct ID. This will probably eventually replace the current isRegisteredUser function. Co-authored-by: Pedro Lopez <pedroslopez@me.com>
This commit is contained in:
committed by
Pedro S. Lopez
parent
87cb5a0519
commit
576768e390
@@ -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<Object|null>}
|
||||
*/
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user