-
-
Save YonathanMeguira/a5df3885b340f501041fe17c396551e1 to your computer and use it in GitHub Desktop.
Receive SMS through SMPP with NodeJS
This file contains hidden or 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 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 | |
}); | |
} | |
}); |
This file contains hidden or 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
{ | |
"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