Esendex Node.js SMS SDK
Our Node.js SDK is an easy to use client for our REST API which you can use to integrate SMS and Voice messaging into any Node.js application.
Requirements
- Node.js
- An internet connection
- An Esendex Account (create your account)
Installation
The SDK can be installed with npm
:
npm install esendex
Usage
Sending SMS messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
var messages = { | |
accountreference: 'EX0000000', | |
message: [{ | |
to: '07987654321', | |
body: 'Every message matters!' | |
},{ | |
to: '07123456789', | |
body: 'Really, every message matters!' | |
}] | |
}; | |
esendex.messages.send(messages, function (err, response) { | |
if (err) return console.log('error: ', err); | |
console.log(response); | |
}); |
Sending Voice messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
var messages = { | |
accountreference: 'EX0000000', | |
type: 'Voice', | |
lang: 'en-GB', | |
message: [{ | |
to: '07987654321', | |
body: 'Every message matters!', | |
lang: 'es-ES' | |
},{ | |
to: '07123456789', | |
body: 'Really, every message matters!', | |
type: 'Voice' | |
}] | |
}; | |
esendex.messages.send(messages, function (err, response) { | |
if (err) return console.log('error: ', err); | |
console.log(response); | |
}); |
Scheduling message sends
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
var messages = { | |
accountreference: 'EX0000000', | |
sendat: new Date(2015, 10, 25, 18, 13).toISOString(), // 2015-11-25T18:13:00.000Z | |
message: [{ | |
to: '07987654321', | |
body: 'Every message matters!' | |
},{ | |
to: '07123456789', | |
body: 'Really, every message matters!' | |
}] | |
}; | |
esendex.messages.send(messages, function (err, response) { | |
if (err) return console.log('error: ', err); | |
console.log(response); | |
}); |
Getting inbox messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.inbox.get({ count: 3 }, function (err, messages) { | |
if (err) return console.log(err); | |
messages.messageheader.forEach(function (msg) { | |
console.log(msg); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.inbox.get({ count: 3, accountreference: 'EX0000000' }, function (err, messages) { | |
if (err) return console.log(err); | |
messages.messageheader.forEach(function (msg) { | |
console.log(msg); | |
}); | |
}); |
Mark inbox messages read or unread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.inbox.update({ id: '8a6cae14-9bce-4195-830b-bd55e1c1ffef', read: true }, function (err) { | |
if (err) return console.log(err); | |
console.log('Marked message as read!'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.inbox.update({ id: '8a6cae14-9bce-4195-830b-bd55e1c1ffef', read: false }, function (err) { | |
if (err) return console.log(err); | |
console.log('Marked message as unread!'); | |
}); |
Getting sent messages and message bodies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.messages.get({ count: 3 }, function (err, messages) { | |
if (err) return console.log(err); | |
messages.messageheader.forEach(function (msg) { | |
esendex.messages.getBody(msg.id, function (err, body) { | |
if (err) return console.log(err); | |
msg.body = body; | |
console.log(msg); | |
}); | |
}); | |
}); |
Getting message batches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var format = require('util').format, | |
esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.batches.get({ count: 2 }, function (err, batches) { | |
if (err) return console.log(err); | |
batches.messagebatch.forEach(function (batch, index) { | |
console.log(batch); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var format = require('util').format, | |
esendex = require('esendex')({ | |
username: 'you@yourdomain.com', | |
password: 'secure password' | |
}); | |
esendex.batches.get({ count: 2, filterBy: 'account', filterValue: 'EX0000000' }, function (err, batches) { | |
if (err) return console.log(err); | |
batches.messagebatch.forEach(function (batch, index) { | |
console.log(batch); | |
}); | |
}); |