SMPP Error - RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received 279

47 Views Asked by At

I am getting the following error when trying to send an SMS message, i have tried to change the source_addr_ton,source_addr_npi,dest_addr_npi,dest_addr_ton, 1 but still am getting the same error when sending some messages.

    error: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received 272     at new NodeError (node:internal/errors:393:5)
         at writeU_Int8 (node:internal/buffer:738:11)
         at Buffer.writeUInt8 (node:internal/buffer:748:10)
         at Object.write (C:\Users\Administrator\Documents\smpp\node_modules\smpp\lib\defs.js:87:11)
         at PDU.toBuffer (C:\Users\Administrator\Documents\smpp\node_modules\smpp\lib\pdu.js:194:20)
         at Session.send (C:\Users\Administrator\Documents\smpp\node_modules\smpp\lib\smpp.js:247:19)
         at Session.submit_sm (C:\Users\Administrator\Documents\smpp\node_modules\smpp\lib\smpp.js:317:15)
         at C:\Users\Administrator\Documents\smpp\index.js:45:21
         at new Promise (<anonymous>)
         at sendMessage (C:\Users\Administrator\Documents\smpp\index.js:44:12) {
       code: 'ERR_OUT_OF_RANGE'
     },
    

function createSmppSession() {
    const session = smpp.connect(`smpp://${process.env.SMPP_HOST}:${process.env.SMPP_PORT}`);
    session.on('connect', () => {
        console.log('Connected to SMPP server');
        smppSession.bind_transceiver({
            system_id: process.env.SMPP_SYSTEM_ID,
            password: process.env.SMPP_PASSWORD,
            system_type: "SMPP",
            source_addr_ton: 5,
            source_addr_npi: 0,
            dest_addr_npi: 1,
            dest_addr_ton: 1
        }, (bindPdu) => {
            if (bindPdu.command_status === 0) {
                console.log('Successfully bound to SMPP server - ' + process.env.SMPP_HOST);
            } else {
                console.error('Failed to bind to SMPP server:', bindPdu.command_status);
            }
        });
    });
    session.on('close', () => {
        console.error('SMPP session disconnected - ' + process.env.SMPP_HOST);
        setTimeout(() => {
            console.log('Attempting to reconnect to SMPP server...');
            smppSession = createSmppSession();
        }, 2000);
    });
    return session;
}

async function sendMessage(message, from, destination) {
    return new Promise((resolve) => {
        smppSession.submit_sm(
            {
                source_addr: from,
                destination_addr: destination,
                short_message: message,
                source_addr_ton: 5,
                source_addr_npi: 0,
                dest_addr_npi: 1,
                dest_addr_ton: 1
            },
            (submitPdu, error) => {
                console.log(submitPdu, error)
                if (error) {
                    resolve({
                        success: false,
                        statusCode: 400,
                        message: error,
                        response: null
                    });
                } else {
                    resolve({
                        success: true,
                        statusCode: 200,
                        message: "Message sent successfully",
                        response: submitPdu
                    });
                }
            }
        );
    });
}

I am not sure what is causing this error, Can you please help me resolve this error?

0

There are 0 best solutions below