submail-sms

0.1.4 • Public • Published

submail-sms

npm version npm downloads Build Status js-standard-style

Wrapper for Submail SMS-sending REST APIs.

Install

$ npm install submail-sms --save

How to use

var SMS = require('submail-sms')
var sms = new SMS('your_key', 'your_secret')
 
// call set methods separately or chain them together
sms.setProject('y6t7uO').addRecipient('18513993882', {var1: 'foo'})
sms.addRecipient('15831998328', {var1: 'bar'})
 
sms.getProject() // -> 'y6t7uO'
sms.getRecipients() // -> [ {to: '18513993882', vars: {var1: 'foo'}}, {to: '15831998328', vars: {var1: 'bar'}} ]
 
// the promise way
sms.send()
  .then(function (res) {
    /**
     * do something with the response here
     * see section below for response details
     */
  })
  .catch(function (err) {
    /* handle errors (more like exceptions) */
  })
 
// or with a callback
sms.send(function (err, res) {
  if (err) {
    /* handle errors */
    return
  }
 
  /* do something with response */
})

Sample response

The success response from Submail is an array of mixed successes and failures. An example:

[ { status: 'success',
    to: '18513993882',
    send_id: 'aba33c824223587ed47988ebfe49b07d',
    fee: 1,
    sms_credits: '33' },
  { status: 'error',
    to: '00000000000',
    code: 252,
    msg: 'Incorrect recipient message address' } ]

Test

$ npm test

Readme

Keywords

Package Sidebar

Install

npm i submail-sms

Weekly Downloads

1

Version

0.1.4

License

MIT

Last publish

Collaborators

  • yu1989