Skip to content

Commit

Permalink
fix(Sns): export Sns.js (#5)
Browse files Browse the repository at this point in the history
* docs(README): refactor links

* fix(Sns): export Sns.js
  • Loading branch information
borodayev authored Mar 31, 2018
1 parent 3946a34 commit a987098
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# sms-sender
# sms-sender :envelope: :rocket:

[![travis build](https://img.shields.io/travis/FrankAst/sms-sender.svg)](https://travis-ci.org/FrankAst/sms-sender)
[![codecov coverage](https://img.shields.io/codecov/c/github/FrankAst/sms-sender.svg)](https://codecov.io/github/FrankAst/sms-sender)
[![](https://img.shields.io/npm/v/sms-sender.svg)](https://www.npmjs.com/package/sms-sender)
<!-- [![npm](https://img.shields.io/npm/dt/graphql-compose-json.svg)](http://www.npmtrends.com/graphql-compose-json) -->
[![](https://img.shields.io/npm/v/@frankast/sms-sender.svg)](https://www.npmjs.com/package/@frankast/sms-sender)
[![npm](https://img.shields.io/npm/dt/@frankast/sms-sender.svg)](http://www.npmtrends.com/@frankast/sms-sender)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
<!-- [![Greenkeeper badge](https://badges.greenkeeper.io/graphql-compose/graphql-compose-json.svg)](https://greenkeeper.io/) -->
[![Greenkeeper badge](https://badges.greenkeeper.io/FrankAst/sms-sender.svg)](https://greenkeeper.io/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)


Expand All @@ -18,17 +18,80 @@ This is a wrapper for [AWS.SNS](https://aws.amazon.com/sns/) and [SMSC API](http
yarn add @frankast/sms-sender
```

## Example
## Examples

There are two providers `Smsc.js` (default) and `Sns.js`. If you want to use `Sns.js` do not forget to add `aws-sdk` optional dependency.

Here is an example for using this wrapper with RegExp:
To send an SMS you have to create an instance of provider and call `sendSms()` method:

```js
import { Smsc } from '@frankast/sms-sender';

const smsc = new Smsc({
login: YOUR_SMSC_LOGIN,
password: YOUR_SMSC_PASSSWORD,
});

// You can use Promises as well.
const response = await smsc.sendSms('phone_number', 'message');

// The response object will contain `messageId` and `rawResponse`:
// response = { messageId: 'id-phone_number', rawResponse: { cnt: 1, id: 50 }}
```

To check the delivery status of SMS call `getStatus()` method:

```js
const response = await smsc.getStatus('40-77718637484'); // takes messageId (id-phone_number)

// The response object will contain 'rawResponse' with general info and 'status':
// response = {
// rawResponse: {
// cost: '0.00',
// country: 'Казахстан',
// last_date: '13.03.2018 15:50:50',
// last_timestamp: 1520934650,
// message: 'hello',
// operator: 'Beeline',
// phone: '77718637484',
// region: '',
// send_date: '13.03.2018 15:50:46',
// send_timestamp: 1520934646,
// sender_id: 'SMS-CENTRE',
// status: 1,
// status_name: 'Доставлено',
// type: 0,
// },
// status: 'ok',
// }
```

P.S. You can get status codes [here](https://github.com/FrankAst/sms-sender/blob/3946a34f0d68369914e1ac6c180cc2a5948b718d/src/transporters/Smsc.js#L49) or in [SMSC docs](https://smsc.kz/api/http/status_messages/statuses/#menu).

To get a cost of SMS call `getCost()` method:

```js
const response = await smsc.getCost('phone_number','message');

// The response object will contain 'rawResponse' and 'cost':
// response = { cost: '0', rawResponse: { cnt: 1, cost: '25' } };
```

To get the current balance on your account call `getBalance()` method:

```js
const response = await smsc.getBalance();

// The response object will contain 'balance' and 'currency':
// response = { balance: '84.75', currency: 'KZT' };
```

Here is an example of usage with RegExp:

```js
// @flow

import Smsc from '../../src/transporters/Smsc';
import Sns from '../../src/transporters/Sns';
import { Smsc, Sns } from '@frankast/sms-sender';

// don't forget to put your credentials
const providers = {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* @flow */
// @flow

export { default as Smsc } from './transporters/Smsc';
export { default as Sns } from './transporters/Sns';
1 change: 0 additions & 1 deletion src/transporters/Sns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow

// import { promisify } from 'util';
import AWS from 'aws-sdk';

import type {
Expand Down

0 comments on commit a987098

Please sign in to comment.