-
Notifications
You must be signed in to change notification settings - Fork 12
Utils
SegFault edited this page Sep 8, 2022
·
4 revisions
My wrapper comes with some helpers functions
The wrapper automatically pulls the countries data out of the api and store it during 24h to reuse it.
It is stored in /tmp/smsApi.countries.json
const country: ICountry = await api.utils.countries.get('russia');
console.log(country);
/*
Will result:
{'id':0,'rus':"Россия","eng:"Russia","chn":"俄罗斯","visible":1,"retry":1,"rent":1,"multiService":1}
*/
Parameter | Type | Description |
---|---|---|
name |
string |
Required. The name of the country, example: russia
|
name |
string |
Optional. Lang to search in: en , ru or cn . All if not specified |
const id: number = await api.utils.countries.toNumber('russia');
console.log(id);
/*
Will result:
0
*/
Parameter | Type | Description |
---|---|---|
name |
string |
Required. The name of the country, example: russia
|
name |
string |
Optional. Lang to search in: en , ru or cn . All if not specified |
api.getNumber({ service: 'go', country: 'france' }).then(async number: INumber => {
/** do your stuff with number.phoneNumber (example writing in the field) **/
await api.setStatus({ id: number.activationId, status: EActivationSetStatus.Sent });
try {
const code = await api.utils.waitForCode(number.activationId);
/** do your stuff with the code **/
await api.setStatus({ id: number.activationId, status: EActivationSetStatus.Success });
} catch(err) {
console.error(err);
await api.setStatus({ id: number.activationId, status: EActivationSetStatus.Failed });
}
}).catch(error => console.error);
Parameter | Type | Description |
---|---|---|
id |
string / number
|
Required. The id of the activation number |
tries |
number |
Optionnal. Number of tries in seconds before it throws "EXPIRED". Default: 180 (3 minutes) |