submail-sms
v0.1.4
Published
Wrapper for Submail SMS-sending REST APIs.
Downloads
3
Readme
submail-sms
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