Skip to content

Commit a987098

Browse files
authored
fix(Sns): export Sns.js (#5)
* docs(README): refactor links * fix(Sns): export Sns.js
1 parent 3946a34 commit a987098

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

README.md

+71-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# sms-sender
1+
# sms-sender :envelope: :rocket:
22

33
[![travis build](https://img.shields.io/travis/FrankAst/sms-sender.svg)](https://travis-ci.org/FrankAst/sms-sender)
44
[![codecov coverage](https://img.shields.io/codecov/c/github/FrankAst/sms-sender.svg)](https://codecov.io/github/FrankAst/sms-sender)
5-
[![](https://img.shields.io/npm/v/sms-sender.svg)](https://www.npmjs.com/package/sms-sender)
6-
<!-- [![npm](https://img.shields.io/npm/dt/graphql-compose-json.svg)](http://www.npmtrends.com/graphql-compose-json) -->
5+
[![](https://img.shields.io/npm/v/@frankast/sms-sender.svg)](https://www.npmjs.com/package/@frankast/sms-sender)
6+
[![npm](https://img.shields.io/npm/dt/@frankast/sms-sender.svg)](http://www.npmtrends.com/@frankast/sms-sender)
77
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
8-
<!-- [![Greenkeeper badge](https://badges.greenkeeper.io/graphql-compose/graphql-compose-json.svg)](https://greenkeeper.io/) -->
8+
[![Greenkeeper badge](https://badges.greenkeeper.io/FrankAst/sms-sender.svg)](https://greenkeeper.io/)
99
[![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)
1010

1111

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

21-
## Example
21+
## Examples
2222

2323
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.
2424

25-
Here is an example for using this wrapper with RegExp:
25+
To send an SMS you have to create an instance of provider and call `sendSms()` method:
26+
27+
```js
28+
import { Smsc } from '@frankast/sms-sender';
29+
30+
const smsc = new Smsc({
31+
login: YOUR_SMSC_LOGIN,
32+
password: YOUR_SMSC_PASSSWORD,
33+
});
34+
35+
// You can use Promises as well.
36+
const response = await smsc.sendSms('phone_number', 'message');
37+
38+
// The response object will contain `messageId` and `rawResponse`:
39+
// response = { messageId: 'id-phone_number', rawResponse: { cnt: 1, id: 50 }}
40+
```
41+
42+
To check the delivery status of SMS call `getStatus()` method:
43+
44+
```js
45+
const response = await smsc.getStatus('40-77718637484'); // takes messageId (id-phone_number)
46+
47+
// The response object will contain 'rawResponse' with general info and 'status':
48+
// response = {
49+
// rawResponse: {
50+
// cost: '0.00',
51+
// country: 'Казахстан',
52+
// last_date: '13.03.2018 15:50:50',
53+
// last_timestamp: 1520934650,
54+
// message: 'hello',
55+
// operator: 'Beeline',
56+
// phone: '77718637484',
57+
// region: '',
58+
// send_date: '13.03.2018 15:50:46',
59+
// send_timestamp: 1520934646,
60+
// sender_id: 'SMS-CENTRE',
61+
// status: 1,
62+
// status_name: 'Доставлено',
63+
// type: 0,
64+
// },
65+
// status: 'ok',
66+
// }
67+
```
68+
69+
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).
70+
71+
To get a cost of SMS call `getCost()` method:
72+
73+
```js
74+
const response = await smsc.getCost('phone_number','message');
75+
76+
// The response object will contain 'rawResponse' and 'cost':
77+
// response = { cost: '0', rawResponse: { cnt: 1, cost: '25' } };
78+
```
79+
80+
To get the current balance on your account call `getBalance()` method:
81+
82+
```js
83+
const response = await smsc.getBalance();
84+
85+
// The response object will contain 'balance' and 'currency':
86+
// response = { balance: '84.75', currency: 'KZT' };
87+
```
88+
89+
Here is an example of usage with RegExp:
2690

2791
```js
2892
// @flow
2993

30-
import Smsc from '../../src/transporters/Smsc';
31-
import Sns from '../../src/transporters/Sns';
94+
import { Smsc, Sns } from '@frankast/sms-sender';
3295

3396
// don't forget to put your credentials
3497
const providers = {

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/* @flow */
1+
// @flow
22

33
export { default as Smsc } from './transporters/Smsc';
4+
export { default as Sns } from './transporters/Sns';

src/transporters/Sns.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22

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

65
import type {

0 commit comments

Comments
 (0)