npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

larvitsmpp

v0.4.0

Published

Simplified SMPP implementation

Downloads

185

Readme

Build Status Dependencies Coverage Status

Larv IT SMPP

This is a simplified implementation of the SMPP protocol.

Installation

npm install larvitsmpp

Client

Simplest possible

This will setup a client that connects to localhost, port 2775 without username or password and send a message.

const larvitsmpp = require('larvitsmpp');

larvitsmpp.client(function(err, clientSession) {
	clientSession.sendSms({
		'from': '46701113311',
		'to': '46709771337',
		'message': 'Hello world'
	});

	// Gracefully close connection
	clientSession.unbind();
});

Some connection parameters and DLR

This will setup a client that connects to given host, port with username and password, send a password and retrieve a DLR and with a custom log driver, compatible with winston.

const larvitsmpp = require('larvitsmpp');
const LUtils = require('larvitutils');
const lUtils = new LUtils();
const log    = new lUtils.Log('debug');

larvitsmpp.client({
	'host':     'smpp.somewhere.com',
	'port':     2775,
	'username': 'foo',
	'password': 'bar',
	'log':      log
}, function(err, clientSession) {
	if (err) {
		throw err;
	}

	clientSession.sendSms({
		'from':    '46701113311',
		'to':      '46709771337',
		'message': '«baff»',
		'dlr':     true
	}, function(err, smsId, retPduObj) {
		if (err) {
			throw err;
		}

		console.log('Return PDU object:');
		console.log(retPduObj);
	});

	clientSession.on('dlr', function(dlr, dlrPduObj) {
		console.log('DLR received:');
		console.log(dlr);

		console.log('DLR PDU object:');
		console.log(dlrPduObj);

		// Gracefully close connection
		clientSession.unbind();
	});
});

Server

Simplest possible

This will setup a password less server on localhost, port 2775 and console.log() incomming commands.

const larvitsmpp = require('larvitsmpp');

larvitsmpp.server(function(err, serverSession) {
	if (err) {
		throw err;
	}

	serverSession.on('data', function(data) {
		console.log('command: ' + data.command);
	});
});

With auth and custom logging, returning smsId and DLR

Example code below:

const larvitsmpp = require('larvitsmpp');
const LUtils = require('larvitutils');
const lUtils = new LUtils();
const log    = new lUtils.Log('debug');

// This should of course be replaced with your preferred auth system
function checkuserpass(username, password, cb) {
	if (username === 'foo' && password === 'bar') {
		// The last parameter is just user meta data that will be attached to the session as "userData" and is optional
		cb(null, true, {'username': 'foo', 'userId': 123});
	} else {
		cb(null, false);
	}
}

larvitsmpp.server({
	'checkuserpass': checkuserpass,
	'log':           log
}, function(err, serverSession) {
	if (err) {
		throw err;
	}

	// Incoming SMS!
	serverSession.on('sms', function(sms) {
		// It is important to run the sms.resp() since this is a part of the protocol
		sms.sendResp(
			// Status code
			// Default is ESME_ROK == no error
			// See SMPP spec for all available status codes
			// For example: ESME_RINVDSTADR == "Invalid destination address".
			'ESME_ROK'
		);

		// Oh, the sms sender wants a dlr (delivery report), send it!
		if (sms.dlr === true) {
			sms.sendDlr(); // Equalent to sms.sendDlr('DELIVERED');

			// To send a negative delivery report for example do:
			sms.sendDlr('UNDELIVERABLE');
			// Possible values are:
			// SCHEDULED
			// ENROUTE
			// DELIVERED <-- Default
			// EXPIRED
			// DELETED
			// UNDELIVERABLE
			// ACCEPTED
			// UNKNOWN
			// REJECTED
			// SKIPPED
		}
	});
});

Session Events

connect

Triggered when the socket is connected to a client. This is server specific.

data

Triggered when data is comming in on the socket.

close

Triggered when the socket is closed.

error

Generic error event.

sms

Incoming SMS.

incomingPdu

Incoming PDU.

incomingPduObj

Incoming PDU Object. Same as incomingPdu, but it have been converted into an object instead of a buffer.

Session commands

send

Send a PDU to the remote.