GetSMS
getSMS - This is Node.js module that allows you to interact with the SMS services api
Features
- Promises
- Supports
SMSActivate
,SMSHub
- Using undici http client
Docs
You can find documentation here
Installation
Node.js 12.0.0 or newer is required
Yarn
yarn add getsms
NPM
npm i getsms
Errors caught
Errors that can be caught with catch()
:
MAIL_RULE
- For buying this service number you must satisfied additional site rules (smshub, undocumented)BAD_KEY
- Invalid api keyERROR_SQL
- Server database errorBAD_ACTION
- Bad request dataWRONG_SERVICE
- Wrong service identifierBAD_SERVICE
- Wrong service name',NO_ACTIVATION
- Activation not found.NO_BALANCE
- No balanceNO_NUMBERS
- No numbersWRONG_ACTIVATION_ID
- Wrong activation idWRONG_EXCEPTION_PHONE
- Wrong exception phoneNO_BALANCE_FORWARD
- No balance for forwardNOT_AVAILABLE
- Multiservice is not available for selected countryBAD_FORWARD
- Incorrect forwardWRONG_ADDITIONAL_SERVICE
- Wrong additional serviceWRONG_SECURITY
- WRONG_SECURITY errorREPEAT_ADDITIONAL_SERVICE
- Repeat additional service errorBANNED:YYYY-m-d H-i-s
- Account banned
if the ban code is BANNED:YYYY-m-d H-i-s
then the error object contains the properties banTime
, banDate
, banTimestamp
banTime
-YYYY-m-d H-i-s
(for example2020-12-31 23-59-59
)banTimestamp
- UnixtimebanDate
- JavaScriptnew Date()
Object
Usage example
const { GetSMS, ServiceApiError, TimeoutError, errors } = require('getsms')
const sms = new GetSMS({
key: 'bc103fa02b63f986cd102a6d2f5c',
url: 'https://smshub.org/stubs/handler_api.php',
service: 'smshub'
});
(async () => {
try {
// eslint-disable-next-line camelcase
const { balance_number } = await sms.getBalance()
// eslint-disable-next-line camelcase
if (balance_number > 0) {
// Service - bd, operator - mts, country - russia (0)
const { id, number } = await sms.getNumber('bd', 'mts', 0)
console.log('Number ID:', id)
console.log('Number:', number)
// Set "message has been sent" status
await sms.setStatus(1, id)
// Wait for code
const { code } = await sms.getCode(id)
console.log('Code:', code)
await sms.setStatus(6, id) // Accept, end
} else console.log('No money')
} catch (error) {
if (error instanceof TimeoutError) {
console.log('Timeout reached')
}
if (error instanceof ServiceApiError) {
if (error.code === errors.BANNED) {
console.log(`Banned! Time ${error.banTime}`)
} else {
console.error(error.code, error.message)
}
} else console.error(error)
}
})()