README
Getting Started
Installation
To use SMSHUB in your project, run:
npm i smshub
or
yarn add smshub
How to use
const SMShub = require('smshub');
const sms = new SMShub({
url: 'https://smshub.org/stubs/handler_api.php',
token: 'TOKEN'
});
(async() => {
//Set default price, country, and activate random number
//Service - vk, max price - 0.67 RUB, random number - true, country - 0
await sms.setParams('vk', '0.67', true, 0);
await sms.operatorAndCountryChange('mts', 0);
//Logging List Of Countries And Operators
await sms.getListOfCountriesAndOperators().then(console.log);
const balance = await sms.getBalance();
if(balance > 0){
const {id, number} = await sms.getNumber('vk', 0);
console.log('Number ID:', id);
console.log('Number:', number);
//Set "message has been sent" status
await sms.setStatus(id, 1);
//Wait for code
await sms.getCode(id).then(async({id, code}) => {
console.log('Code:', code);
await sms.setStatus(id, 6); //Accept, end
});
} else console.log('No money');
})();
All errors can be caught via catch
getNumber( Promiseservice
, country
)
{id: ID, number: NUMBER} - Success.
{type: 'api', country: COUNTRY, service: SERVICE} //Api error (error codes here https://smshub.org/main#getNumbers)
{type: 'request', country: COUNTRY, service: SERVICE} //Request
setStatus( PromisenumberID
, statusID
)
{data: DATA} // Success, `DATA` - status code from SMSHub
{type: 'api', error: ERRORCODE, id: NUMBERID} //Api error (error codes here https://smshub.org/main#setStatus)
{type: 'request', id: NUMBERID} //Request error
getCode( PromisenumberID
)
{code: CODE, id: NUMBERID} //Success
{type: 'status', error: 'STATUS_CANCEL', id: NUMBERID} // if number cancelled
{type: 'api', error: ERRORCODE, id: NUMBERID} // Api error (error codes here https://smshub.org/main#getStatus)
{type: 'request', id: NUMBERID} //Request error
getBalance() Promise
{balance: BALANCE} - Success. BALANCE - float
{type: 'api', error: ERRORCODE} //Api error (error codes here https://smshub.org/main#getBalance)
{type: 'request'} //Request error
getNumbersStatusAndCostHubFree() Promise!!!UNOFFICIAL HIDDEN METHOD!!!
Object - Success.
{type: 'api', error: ERRORCODE} //Api error
{type: 'request'} //Request error
setParams( Promiseservice
, maxPrice
, random = true
, country = 0
) !!!UNOFFICIAL HIDDEN METHOD!!!
{type: 'api', error: ERRORCODE}// Api error
{type: 'request'} //Request error
getCurrentActivations() Promise!!!UNOFFICIAL HIDDEN METHOD!!!
{data: DATA} //Success.
{type: 'api', error: ERRORCODE} //Api error
{type: 'request'} //Request error
getListOfCountriesAndOperators() Promise!!!UNOFFICIAL HIDDEN METHOD!!!
This method returns list of countries and orerators and current setted country/operator
currentOperator & currentCountry is null if token is wrong
{status: 'success', services: {...}, data:[ {…}, {…}, … ], currentOperator: 'OPERATOR NAME', currentCountry: 'COUNTRY ID'} //Success.
{type: 'api', error: ERRORCODE} //Api error
{type: 'request'} //Request error
operatorAndCountryChange( Promiseoperator = 'any'
, country = 0
, url = 'https://smshub.org/api.php'
) !!!UNOFFICIAL HIDDEN METHOD!!!
This method change mobile operator setting
WARNING!!! If token is wrong, method returns success status!
{ status: "success", msg: "Оператор успешно изменен" } //Success.
{type: 'api', error: ERRORCODE} //Api error
{type: 'request'} //Request error