Moved smsDlr function to utils

This commit is contained in:
2015-06-16 20:11:54 +02:00
parent 96a9e2c46a
commit 0228adb98c
3 changed files with 86 additions and 85 deletions
+2 -83
View File
@@ -78,87 +78,6 @@ function smsResp(status, callback) {
async.parallel(tasks, callback);
}
/**
* Send a dlr to an sms
* This must be called from an sms object context
*
* @param str status - see list at defs.consts.MESSAGE_STATE - defaults to 'DELIVERED'
* @param func callback(err, retPdu)
*/
function smsDlr(status, callback) {
var shortMessage,
dlrPduObj,
err,
sms = this;
if (typeof status === 'function') {
callback = status;
status = undefined;
}
if (status === undefined || status === true || status === 2 || status === 'true') {
status = 2;
} else if (defs.consts.MESSAGE_STATE[status] !== undefined) {
status = defs.consts.MESSAGE_STATE[status];
} else if (defs.constsById.MESSAGE_STATE[status]) {
status = parseInt(status);
} else {
status = 5; // UNDELIVERABLE
}
if (typeof callback !== 'function') {
callback = function() {};
}
if (sms.smsId === undefined) {
err = new Error('Trying to send DLR with no smsId.');
log.warn('larvitsmpp: lib/session.js: smsDlr() - ' + err.message);
callback(err);
return;
}
shortMessage = 'id:' + sms.smsId + ' sub:001 ';
if (status === 2) {
shortMessage += 'dlvrd:1 ';
} else {
shortMessage += 'dlvrd:0 ';
}
shortMessage += 'submit date:' + utils.smppDate(sms.submitTime);
shortMessage += ' done date:' + utils.smppDate(new Date());
if (status === 2) {
shortMessage += ' stat:DELIVRD err:0 text:xxx';
} else {
shortMessage += ' stat:UNDELIVERABLE err:1 text:xxx';
}
dlrPduObj = {
'cmdName': 'deliver_sm',
'params': {
'source_addr': sms.from,
'destination_addr': sms.to,
'esm_class': 4,
'short_message': shortMessage
},
'tlvs': {
'receipted_message_id': {
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': sms.smsId
},
'message_state': {
'tagId': 0x0427,
'tagName': 'message_state',
'tagValue': status
}
}
};
sms.session.send(dlrPduObj, false, callback);
}
function incOurSeqNr() {
this.ourSeqNr = this.ourSeqNr + 1;
@@ -519,7 +438,7 @@ function checkLongSmses() {
'message': '',
'dlr': Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery),
'sendResp': smsResp,
'sendDlr': smsDlr
'sendDlr': utils.smsDlr
};
// Concatenate all the parts messages to one and set references to the session
@@ -654,7 +573,7 @@ function session(sock) {
'message': pduObj.params.short_message,
'dlr': Boolean(pduObj.params.registered_delivery),
'sendResp': smsResp,
'sendDlr': smsDlr
'sendDlr': utils.smsDlr
};
if (pduObj.params.data_coding === 0x10) {
+83 -1
View File
@@ -687,6 +687,87 @@ function splitMsg(msg) {
return msgs;
}
/**
* Send a dlr to an sms
* This must be called from an sms object context
*
* @param str status - see list at defs.consts.MESSAGE_STATE - defaults to 'DELIVERED'
* @param func callback(err, retPdu)
*/
function smsDlr(status, callback) {
var shortMessage,
dlrPduObj,
err,
sms = this;
if (typeof status === 'function') {
callback = status;
status = undefined;
}
if (status === undefined || status === true || status === 2 || status === 'true') {
status = 2;
} else if (defs.consts.MESSAGE_STATE[status] !== undefined) {
status = defs.consts.MESSAGE_STATE[status];
} else if (defs.constsById.MESSAGE_STATE[status]) {
status = parseInt(status);
} else {
status = 5; // UNDELIVERABLE
}
if (typeof callback !== 'function') {
callback = function() {};
}
if (sms.smsId === undefined) {
err = new Error('Trying to send DLR with no smsId.');
log.warn('larvitsmpp: lib/session.js: smsDlr() - ' + err.message);
callback(err);
return;
}
shortMessage = 'id:' + sms.smsId + ' sub:001 ';
if (status === 2) {
shortMessage += 'dlvrd:1 ';
} else {
shortMessage += 'dlvrd:0 ';
}
shortMessage += 'submit date:' + smppDate(sms.submitTime);
shortMessage += ' done date:' + smppDate(new Date());
if (status === 2) {
shortMessage += ' stat:DELIVRD err:0 text:xxx';
} else {
shortMessage += ' stat:UNDELIVERABLE err:1 text:xxx';
}
dlrPduObj = {
'cmdName': 'deliver_sm',
'params': {
'source_addr': sms.from,
'destination_addr': sms.to,
'esm_class': 4,
'short_message': shortMessage
},
'tlvs': {
'receipted_message_id': {
'tagId': 0x001E,
'tagName': 'receipted_message_id',
'tagValue': sms.smsId
},
'message_state': {
'tagId': 0x0427,
'tagName': 'message_state',
'tagValue': status
}
}
};
sms.session.send(dlrPduObj, false, callback);
}
// Expose some functions
exports.decodeMsg = decodeMsg;
exports.encodeMsg = encodeMsg;
@@ -695,4 +776,5 @@ exports.objToPdu = objToPdu;
exports.pduReturn = pduReturn;
exports.smppDate = smppDate;
exports.bitCount = bitCount;
exports.splitMsg = splitMsg;
exports.splitMsg = splitMsg;
exports.smsDlr = smsDlr;
+1 -1
View File
@@ -29,7 +29,7 @@
"url": "https://github.com/larvit/larvitsmpp",
"type": "git"
},
"version": "0.1.4",
"version": "0.1.5",
"readmeFilename": "README.md",
"readme": "larvitsmpp",
"bugs": {