mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Format phone numbers (#650)
* 📦 Declared NumberInfo in store * 📝 Add client.js functionality * 🚨 eslint just admires singlequote strings * 📝 Add shortcuts to using client method * ♿ Adding parity between the ids * ♿ Same method name parity * 🚨 ESLint indentation error. * 🚨 ESLint doublequote string error. * 🎨 Proposed changes * 🎨 Fixed badly done code :v and applied proposed changes. * ⚡ fixed calling the wrong function (sigh) * ⚡ Fixed missing try-catch code. * 🚨 Fixes ESLint indentation errors. * ⚡ fix the documentation issues. * 🏷️ typescript * 🏷️ Typo in function name Co-authored-by: Rajeh Taher <rajeh@reforward.tk>
This commit is contained in:
@@ -840,10 +840,7 @@ class Client extends EventEmitter {
|
||||
* @returns {Promise<Object|null>}
|
||||
*/
|
||||
async getNumberId(number) {
|
||||
if(!number.endsWith('@c.us')) {
|
||||
number += '@c.us';
|
||||
}
|
||||
|
||||
if (!number.endsWith('@c.us')) number += '@c.us';
|
||||
try {
|
||||
return await this.pupPage.evaluate(async numberId => {
|
||||
return window.WWebJS.getNumberId(numberId);
|
||||
@@ -853,6 +850,32 @@ class Client extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted number of a WhatsApp ID.
|
||||
* @param {string} number Number or ID
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async getFormattedNumber(number) {
|
||||
if(!number.endsWith('@s.whatsapp.net')) number = number.replace('c.us', 's.whatsapp.net');
|
||||
|
||||
return await this.pupPage.evaluate(async numberId => {
|
||||
return window.NumberInfo.formattedPhoneNumber(numberId);
|
||||
}, number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the country code of a WhatsApp ID.
|
||||
* @param {string} number Number or ID
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async getCountryCode(number) {
|
||||
number = number.replace(' ', '').replace('+', '').replace('@c.us', '');
|
||||
|
||||
return await this.pupPage.evaluate(async numberId => {
|
||||
return window.NumberInfo.findCC(numberId);
|
||||
}, number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new group
|
||||
* @param {string} name group title
|
||||
|
||||
Reference in New Issue
Block a user