Bipsms
Send SMS(s), query their delivery reports and sending history in nodejs using infobip JSON API
Install / Use
/learn @lykmapipo/BipsmsREADME
bipsms
Send SMS(s), query their delivery reports and sending history in nodejs using infobip JSON API.
Note:! It strongly recommend using the E.164 number formatting when sending SMS(s)
Requirements
Installation
$ npm install bipsms --save
Usage
Firstly, you'll need a valid Infobip account.
Send single SMS to single destination
To send single SMS to single destination, instantiate bipsms with your account details then invoke sendSingleSMS(sms,callback(error,response)) where
sms- is an sms to senderror- is any error encountered when sending SMS(s)response- is a response of sent SMS(s)
Example
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
//prepare sms
var sms = {
from: 'InfoSMS',
to: '41793026727',
text: 'Test SMS.'
};
//send SMS
transport.sendSingleSMS(sms, function(error, response) {
expect(error).to.be.null;
expect(response).to.exist;
expect(response.messages).to.exist;
});
Send single SMS to multiple destination
To send single SMS to multiple destination, instantiate bipsms with your account details then invoke sendSingleSMS(sms,callback(error,response)) where
sms- is an sms to senderror- is any error encountered when sending SMS(s)response- is a response of sent SMS(s)
Example
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
//prepare SMS
var sms = {
from: 'InfoSMS',
to: [
'41793026727',
'41793026834'
],
text: 'Test SMS.'
};
//send SMS
transport.sendSingleSMS(sms, function(error, response) {
expect(error).to.be.null;
expect(response).to.exist;
expect(response.messages).to.exist;
});
Send multiple SMS to multiple destination
To send multiple SMS, instantiate bipsms with your account details then invoke sendMultiSMS(sms,callback(error,response)) where
sms- is a collection of SMS(s) to senderror- is any error encountered when sending SMS(s)response- is a response of sent SMS(s)
Example
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
//prepare sms(s) to send
var sms = {
messages: [{
from: 'InfoSMS',
to: [
'41793026727',
'41793026731'
],
text: 'May the Force be with you!'
}, {
from: '41793026700',
to: '41793026785',
text: 'A long time ago, in a galaxy far, far away.'
}]
};
//send sms(s)
transport.sendMultiSMS(sms, function(error, response) {
expect(error).to.be.null;
expect(response).to.exist;
expect(response.messages).to.exist;
});
Send Fully Featured SMS
To send fully featured textual SMS, instantiate bipsms with your account details then invoke sendFeaturedSMS(sms,callback(error,response)) where
sms- is a fully featured textual SMS(s) to senderror- is any error encountered when sending SMS(s)response- is a response of sent SMS(s)
Example
var Transport = require('bipsms');
var transport = new Transport({ username: '<username>', password: '<password>' });
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
//prepare featured sms(s) to send
var sms = {
bulkId: 'BULK-ID-123-xyz',
messages: [{
from: 'InfoSMS',
destinations: [{
to: '41793026727',
messageId: 'MESSAGE-ID-123-xyz'
}, {
to: '41793026731'
}],
text: 'Mama always said life was like a box of chocolates.',
notifyUrl: 'http://www.example.com/sms/advanced',
notifyContentType: 'application/json',
callbackData: 'There\'s no place like home.'
}]
};
//send featured sms(s)
transport.sendFeaturedSMS(sms, function(error, response) {
expect(error).to.be.null;
expect(response).to.exist;
expect(response.messages).to.exist;
});
Delivery Reports
To obtain SMS(s) delivery reports, instantiate bipsms with your account details then invoke getDeliveryReports(options,callback(error,logs)) where
options- are valid request parameters to be supplied on the requesterror- is any error encountered during requesting SMS(s) sent delivery reportdeliveryReport- is SMS(s) sent delivery reports
Note!: Delivery reports can only be retrieved one time. Once you retrieve a delivery report, you will not be able to get the same report again by using this endpoint.
Example - Request all delivery reports
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getDeliveryReports(function(error, deliveryReport) {
expect(error).to.be.null;
expect(deliveryReport).to.exist;
expect(deliveryReport.results).to.exist;
});
Example - Request delivery report with parameters specified
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getDeliveryReports({
bulkId: '<bulkId>'
},function(error, deliveryReport) {
expect(error).to.be.null;
expect(deliveryReport).to.exist;
expect(deliveryReport.results).to.exist;
});
Sent SMS Logs (Send History)
To obtain SMS(s) sent history(log), instantiate bipsms with your account details then invoke getSentSMSLogs(options,callback(error,logs)) where
options- are valid request parameters to be supplied on the requesterror- is any error encountered during requesting SMS(s) sent history/logslogs- is SMS(s) sent history / logs
Note!: SMS logs are available for the last 48 hours!
Example - Request all sent history / logs
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getSentSMSLogs(function(error, logs) {
expect(error).to.be.null;
expect(logs).to.exist;
expect(logs.results).to.exist;
});
Example - Request logs with parameters specified
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getSentSMSLogs({
bulkId: '<bulkId>'
},function(error, logs) {
expect(error).to.be.null;
expect(logs).to.exist;
expect(logs.results).to.exist;
});
Received SMS
To obtain received SMS(s), instantiate bipsms with your account details then invoke getReceivedSMS(options,callback(error,receivedSMS)) where
options- are valid request parameters to be supplied on the requesterror- is any error encountered during requesting received SMS(s)receivedSMS- are SMS(s) received
Example - Request all received SMS(s)
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getReceivedSMS(function(error, receivedSMS) {
expect(error).to.be.null;
expect(receivedSMS).to.exist;
expect(receivedSMS.results).to.exist;
});
Example - Request received SMS(s) with parameters specified
var Transport = require('bipsms');
var transport = new Transport({username:'<username>',password:'<password>'});
//or use Fake Transport for non production environment
var transport = new Transport({fake:true});
transport.getReceivedSMS({
limit: '<limit>'
},function(error, receivedSMS) {
expect(error).to.be.null;
expect(

