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:
Rajeh Taher
2021-10-30 06:33:38 +03:00
committed by GitHub
parent dbf9bf2158
commit 97a1d399ee
4 changed files with 60 additions and 7 deletions

View File

@@ -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