Skip to content
SegFault edited this page Sep 8, 2022 · 4 revisions

My wrapper comes with some helpers functions


Countries

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

Get the country object for a lang

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

Get the country id for a lang

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

Wait for code

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)
Clone this wiki locally