Moved smsDlr function to utils
This commit is contained in:
+2
-83
@@ -78,87 +78,6 @@ function smsResp(status, callback) {
|
|||||||
async.parallel(tasks, 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() {
|
function incOurSeqNr() {
|
||||||
this.ourSeqNr = this.ourSeqNr + 1;
|
this.ourSeqNr = this.ourSeqNr + 1;
|
||||||
|
|
||||||
@@ -519,7 +438,7 @@ function checkLongSmses() {
|
|||||||
'message': '',
|
'message': '',
|
||||||
'dlr': Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery),
|
'dlr': Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery),
|
||||||
'sendResp': smsResp,
|
'sendResp': smsResp,
|
||||||
'sendDlr': smsDlr
|
'sendDlr': utils.smsDlr
|
||||||
};
|
};
|
||||||
|
|
||||||
// Concatenate all the parts messages to one and set references to the session
|
// 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,
|
'message': pduObj.params.short_message,
|
||||||
'dlr': Boolean(pduObj.params.registered_delivery),
|
'dlr': Boolean(pduObj.params.registered_delivery),
|
||||||
'sendResp': smsResp,
|
'sendResp': smsResp,
|
||||||
'sendDlr': smsDlr
|
'sendDlr': utils.smsDlr
|
||||||
};
|
};
|
||||||
|
|
||||||
if (pduObj.params.data_coding === 0x10) {
|
if (pduObj.params.data_coding === 0x10) {
|
||||||
|
|||||||
@@ -687,6 +687,87 @@ function splitMsg(msg) {
|
|||||||
return msgs;
|
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
|
// Expose some functions
|
||||||
exports.decodeMsg = decodeMsg;
|
exports.decodeMsg = decodeMsg;
|
||||||
exports.encodeMsg = encodeMsg;
|
exports.encodeMsg = encodeMsg;
|
||||||
@@ -696,3 +777,4 @@ exports.pduReturn = pduReturn;
|
|||||||
exports.smppDate = smppDate;
|
exports.smppDate = smppDate;
|
||||||
exports.bitCount = bitCount;
|
exports.bitCount = bitCount;
|
||||||
exports.splitMsg = splitMsg;
|
exports.splitMsg = splitMsg;
|
||||||
|
exports.smsDlr = smsDlr;
|
||||||
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
"url": "https://github.com/larvit/larvitsmpp",
|
"url": "https://github.com/larvit/larvitsmpp",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
},
|
},
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"readmeFilename": "README.md",
|
"readmeFilename": "README.md",
|
||||||
"readme": "larvitsmpp",
|
"readme": "larvitsmpp",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|||||||
Reference in New Issue
Block a user