Moved smsDlr function to utils
This commit is contained in:
+83
-1
@@ -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;
|
||||
Reference in New Issue
Block a user