Last active
March 18, 2022 19:12
-
-
Save Kreshnik/07ed9803165fbdebc237df2de0f8641a to your computer and use it in GitHub Desktop.
Receive SMS through SMPP with NodeJS
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 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 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