how to send long message using node smpp?

冷暖自知 提交于 2019-12-11 14:59:52

问题


exports.sendSMS = function (session, to, text, sourceAddress, jsonMessageHistoryIds, callback) {

     console.log('messege',text);

    session.submit_multi({
        source_addr: sourceAddress,
        dest_address: to,
        short_message: text

    }, function (pdu) {
        console.log('submit_multi: ', pdu.command_status);
        console.log("PDU", pdu);
        if (pdu.command_status == 0) {
            // insert into sms smpp logs
            var values = {
                type: 'bulk',
                message: text,
                numbers: JSON.stringify(to)
            };

        console.log(pdu.message_id);
            callback(null, pdu.message_id);
        }
    });
};

If the messege is below 160 character it is okey .Messege will be sent but if messege is above 160 character then it will throw new TypeError value argument is out of bounds in buffer.js if sms messege is too long.Please Help .will really appreciate any help


回答1:


solved this problem by this ..hope it helps someone someday

npm install gsm
The above module also splits the message into parts:

//We need to split the message and send it in many parts
var gsm = require('gsm');

var info = gsm("Your message string here");

//This is a unique id present in each message part
var concat_ref = this.concat_ref++; 

var part_id = 0;
info.parts.forEach(function(part) {
    part_id++;
    var udh = new Buffer(6);
    udh.write(String.fromCharCode(0x5), 0); //Length of UDF
    udh.write(String.fromCharCode(0x0), 1); //Indicator for concatenated message
    udh.write(String.fromCharCode(0x3), 2); //  Subheader Length ( 3 bytes)
    udh.write(String.fromCharCode(concat_ref), 3); //Same reference for all concatenated messages
    udh.write(String.fromCharCode(info.sms_count), 4); //Number of total messages in the concatenation
    udh.write(String.fromCharCode(part_id), 5); //Sequence number ( used by the mobile to concatenate the split messages)

    var submit_pdu = {
        source_addr:msg.from,
        destination_addr: msg.to,
        short_message: { udh:udh, message:part },
        registered_delivery:1 //If you want a delivery report
    };

    this.getSession().submit_sm(submit_pdu, function(pdu) {
        if (pdu.command_status == 0) {
            console.log("SMPP Gateway[" + this.getOptions().address + "] - SUMBIT[" + submit_pdu.source_addr + ">>>" + submit_pdu.destination_addr + "] - " + pdu.message_id);
        }
        if(callback) {
            callback(pdu);
        }
    }.bind(this));
}.bind(this));


来源:https://stackoverflow.com/questions/48060832/how-to-send-long-message-using-node-smpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!