node.jsbuffersmpppdusmscaster

how to send long message using node smpp?


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


Solution

  • 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));