-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessageCenter.js
39 lines (39 loc) · 1.42 KB
/
messageCenter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var smpp = require("smpp");
var auth = require("./auth.js");
var server = smpp.createServer(function (session) {
console.log("Creating Server.");
session.on("bind_transceiver", function (pdu) {
console.log("Transceiver bound: ");
console.log("Pausing for auth.");
session.pause();
auth.checkUserCredentialsAsync(pdu.system_id, pdu.password, function (error) {
if(error){
console.log(error);
session.send(pdu.response({
command_status : smpp.ESMS_RBINDFAIL
}));
session.close();
return;
}
console.log("Auth success.");
console.log("Sending PDU response.");
session.send(pdu.response());
console.log("PDU response sent.");
console.log("Resuming...");
session.resume();
console.log("connected.");
});
});
session.on("submit_sm", function (pdu) {
console.log("Sending '" + pdu.short_message.message + "' to " + pdu.destination_addr + ".");
// console.log("PDU Command: ", pdu.command);
//TODO: Generate a message id
var messageId = new Date().getUTCMilliseconds().toString();
session.send(pdu.response({
message_id:messageId
}));
});
session.on("error", function (error) {
});
});
server.listen(2017);