Skip to content

Instantly share code, notes, and snippets.

@Kreshnik
Last active March 18, 2022 19:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kreshnik/07ed9803165fbdebc237df2de0f8641a to your computer and use it in GitHub Desktop.
Save Kreshnik/07ed9803165fbdebc237df2de0f8641a to your computer and use it in GitHub Desktop.
Receive SMS through SMPP with NodeJS
var smpp = require('smpp');
var session = smpp.connect('smpp://SEVER_IP');
var request = require('request');
var connected = false;
session.on('connect', function () {
connected = true;
session.bind_transceiver({
system_id: 'SYSTEM_ID',
password: 'PASSWORD'
}, function (pdu) {
if (pdu.command_status === 0) {
connected = true;
console.log('Successfully bound transceiver.');
}
});
});
session.on('close', function () {
if (connected) {
session.connect();
}
});
session.on('error', function (error) {
connected = false;
});
session.on('pdu', function (pdu) {
if (pdu.command == 'data_sm') {
var sms = {
from: null,
to: null,
message: null
};
sms.from = pdu.source_addr.toString();
sms.to = pdu.destination_addr.toString();
if (pdu.message_payload) {
sms.message = pdu.message_payload.message;
}
console.log(sms);
session.deliver_sm_resp({
sequence_number: pdu.sequence_number
});
}
});
{
"name": "node-smpp-receive-sms-through-smpp",
"version": "0.0.1",
"description": "Receive SMS through SMPP with NodeJS",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kreshnik Hasanaj",
"license": "BSD-2-Clause",
"dependencies": {
"smpp": "~0.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment