Tutorial section - SMS

Send SMS with SMPP using NodeJS

Sending SMS with the SMPP API using the NodeJS programming language

The node-smpp library can be used to make SMPP requests using Node.js. This library can be used to submit SMS to an SMS gateway or SMSC.

SMPP requirements

SMPP is the Short Message Peer-to-Peer protocol for conveying SMS operations. An SMPP account can easily be obtained for using the Tyr SMS Gateway or SMSC Simulator. The following are required to send SMS with SMPP:

NodeJS requirements

Ruby is a programming language and can be used to quickly and easily add SMS support for programmatically sending and receiving SMS messages. The following are required to send SMS using NodeJS:

  • Node.js - Node.js is a scripting/programming language

Requirements

The following are required to send SMS with SMPP using NodeJS:

  • node-smpp - SMPP client and server implementation in Node.js.

Code

Create the file sendsms.js containing the code below. Replace the hostname smscsim.melroselabs.com, port 2775, SYSTEMID and PASSWORD values with those from your SMPP API account. Alternatively, replace SYSTEMID and PASSWORD with those allocated to you for use with the Melrose Labs SMSC Simulator.

The following example Node.js code opens an SMPP transmitter bind to smscsim.melroselabs.com on port 2775 (SMPP port), and then sends the message Hello World #$£ to mobile number 447712345678 from MelroseLabs. The message ID returned in $messageID is that returned from the SMS gateway or SMSC after a successful submission. The SMPP system ID and password for the SMPP account are contained in SYSTEMID and PASSWORD respectively.

	var smpp = require('smpp');
var session = smpp.connect('smpp://smscsim.melroselabs.com:2775');
session.bind_transceiver({
	system_id: 'SYSTEMID',
	password: 'PASSWORD'
}, function(pdu) {
	if (pdu.command_status == 0) {
		// Successfully bound
		session.submit_sm({
			destination_addr: '447712345678',
			short_message: 'Hello World €$£'
		}, function(pdu) {
			if (pdu.command_status == 0) {
				// Message successfully sent
				console.log(pdu.message_id);
			}
		});
	}
});