node-smsportal v0.5.0
Node SMS Portal
Basic SMS Portal HTTP API wrapper built around node's request module.
A node wrapper to allow more native node usage of the SMS Portal web services http API Requires an existing account with SMS Portal www.smsportal.co.za.
Dependancies
- bluebird.js for promises.
- xml2json to parse the response xml into something more manageable in node.
Install
In your node app, run:
$ npm install --save node-smsportal
Once it is installed, it needs to be included:
var Client = require('node-smsportal');
To use it, it needs to be instantiated and initialized, one of 2 ways.
var options = {
username: '<existing smsportal username>',
password: '<existing smsportal username>'
}
var smsportal = new Client();
smsportal.init(options);
OR
var options = {
username: '<existing smsportal username>',
password: '<existing smsportal username>'
}
var smsportal = new Client(options);
Code Example
Currently the library only supports 2 functions, checking the accounts credit balance, and sending a message. The message can be sent to one number or a comma separated list of numbers.
The following examples were written in express.
Check Credits
router.get('/check-credits', function(req, res,next){
var options = {
username: 'username',
password: 'password'
}
var Client = require('node-smsportal');
var smsportal = new Client();
smsportal.init(options);
smsportal.checkCredits(function(result){
console.log(result);
res.json(result);
res.end();
});
});
Send SMS to 1 Number
router.get('/send-sms', function(req, res,next){
var options = {
username: 'username',
password: 'password'
}
var Client = require('node-smsportal');
var smsportal = new Client();
var message = 'some text here';
var number = '0812345678';
smsportal.init(options);
smsportal.sendSms(number, message,function(result){
console.log(result);
res.json(result);
res.end();
});
});
Send SMS to Multiple Numbers
router.get('/send-sms', function(req, res,next){
var options = {
username: 'username',
password: 'password'
}
var Client = require('node-smsportal');
var smsportal = new Client();
var message = 'some text here';
var numbers = '0812345678,0712345678,0612345678';
smsportal.init(options);
smsportal.sendSms(numbers, message,function(result){
console.log(result);
res.json(result);
res.end();
});
});
Motivation
A node wrapper to allow more native node usage of the SMS Portal web services http API. This is being used as part of existing projects and made sense to abastract it out into its own module. API docs and more information can be found on MyMobileAPI.com.
Tests
Currently no tests have been implemented
License
MIT, see LICENSE.