npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pskzcompany/sms-sender

v2.0.1

Published

This is a wrapper for AWS.SNS & SMSC API in Node.js

Downloads

7

Readme

sms-sender

travis build codecov coverage npm Commitizen friendly semantic-release

This is a wrapper for AWS.SNS and SMSC API.

Installation

yarn add @pskzcompany/sms-sender

API

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

Sending SMS

To send an SMS you have to create an instance of provider and call sendSms() method:

import { Smsc } from '@pskzcompany/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 }}

Get delivery status of SMS

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

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 or in SMSC docs.

Get cost of SMS

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

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

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

getCost() is not available for Mobizon provider.

Get current balance

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

  const response = await smsc.getBalance();

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

Examples

Here is an example of usage with RegExp:

// @flow

import { Smsc, Sns, Mobizon } from '@pskzcompany/sms-sender';

// don't forget to put your credentials
const providers = {
  smsc: new Smsc({
    login: '',
    password: '',
  }),

  sns: new Sns({
    region: '',
    accessKeyId: '',
    secretAccessKey: '',
  }),
  
  mobizon: new Mobizon({
    apiKey: '',
  }),
};

async function send(phone: string, message: string): Promise<Object> {
  const regexp = RegExp('7708', 'g');
  let provider;
  if (regexp.test(phone)) {
    provider = providers.smsc;
  } else {
    provider = providers.sns;
  }
  const res = await provider.sendSms(phone, message);
  return res;
}

send('+77081113344', 'hello world').then(res => {
  console.log(res);
});

Other examples are available in ./examples.

Contribution

Feel free to submit pull request to us. Also, be sure all tests has passed otherwise pull request won't be accepted.

License

MIT