# smshub

> SMSHub API

Latest version **1.6.1** (published 2020-12-31) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install smshub
pnpm add smshub
yarn add smshub
bun add smshub
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.6.1 |
| Published | 2020-12-31 |
| First published | 2020-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Maxim Telegin |
| Maintainers | viiprogrammer |
| Keywords | smshub, sms, smsapi, sms-api, sms-hub, smshub-api, sms, gate, smsgateway |

## Links

- npm: https://www.npmjs.com/package/smshub
- Repository: https://github.com/Viiprogrammer/sms-hub
- Homepage: https://github.com/Viiprogrammer/sms-hub#readme
- Issues: https://github.com/Viiprogrammer/sms-hub/issues
- npm.io page: https://npm.io/package/smshub

## Dependencies (1)

- [request](https://npm.io/package/request.md) ^2.88.2

## Recent versions

- 1.6.1 (latest) — 2020-12-31
- 1.6.0 — 2020-12-26
- 1.5.0 — 2020-11-08
- 1.4.7 — 2020-11-08
- 1.4.6 — 2020-11-08
- 1.4.5 — 2020-11-08
- 1.4.1 — 2020-11-08
- 1.4.0 — 2020-11-07
- 1.3.0 — 2020-11-07
- 1.2.0 — 2020-03-22
- 1.1.0 — 2020-03-22
- 1.0.0 — 2020-03-22

## README

## Getting Started

### Installation

To use SMSHUB in your project, run:

```bash
npm i smshub
```
or
```bash
yarn add smshub
```
[![NPM](https://nodei.co/npm/smshub.png?downloads=true&stars=true)](https://nodei.co/npm/smshub/)

# How to use
```javascript
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***

#### `Promise` getNumber(`service`, `country`) 
```javascript
 {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 
``` 
#### `Promise` setStatus(`numberID`, `statusID`) 
```javascript
 {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
``` 
#### `Promise` getCode(`numberID`) 
```javascript
 {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
``` 
  
#### `Promise` getBalance() 
```javascript
 {balance: BALANCE} - Success. BALANCE - float
 {type: 'api', error: ERRORCODE} //Api error (error codes here https://smshub.org/main#getBalance)
 {type: 'request'} //Request error
``` 
#### `Promise` getNumbersStatusAndCostHubFree() `!!!UNOFFICIAL HIDDEN METHOD!!!`
                                                   
```javascript
 Object - Success.
 {type: 'api', error: ERRORCODE} //Api error
 {type: 'request'} //Request error
``` 

#### `Promise` setParams(`service`, `maxPrice`, `random = true`, `country = 0`) `!!!UNOFFICIAL HIDDEN METHOD!!!`
```javascript
 {type: 'api', error: ERRORCODE}// Api error
 {type: 'request'} //Request error
``` 
#### `Promise` getCurrentActivations() `!!!UNOFFICIAL HIDDEN METHOD!!!`
```javascript
   {data: DATA} //Success.
   {type: 'api', error: ERRORCODE} //Api error
   {type: 'request'} //Request error
``` 
#### `Promise` getListOfCountriesAndOperators() `!!!UNOFFICIAL HIDDEN METHOD!!!`

This method returns list of countries and orerators and current setted country/operator

currentOperator & currentCountry is null if token is wrong
```javascript
   {status: 'success', services: {...}, data:[ {…}, {…}, … ],  currentOperator: 'OPERATOR NAME', currentCountry: 'COUNTRY ID'} //Success.
   {type: 'api', error: ERRORCODE} //Api error
   {type: 'request'} //Request error
``` 

#### `Promise` operatorAndCountryChange(`operator = '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!

```javascript
   { status: "success", msg: "Оператор успешно изменен" } //Success.
   {type: 'api', error: ERRORCODE} //Api error
   {type: 'request'} //Request error
```

---
_Source: https://npm.io/package/smshub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
