SMPP server on NodeJS doesn't send SMS to phone number

Viewed 13

I configured my SMPP server on nodejs, to send an SMS directly to my phone number, without using a gateway, but it fails to send it. It doesn't even show any errors.

CLIENT

var smpp = require("smpp");
var session = smpp.connect(
  {
    url: "smpp://localhost:2775",
    auto_enquire_link_period: 10000,
  },
  function () {
    session.bind_transceiver(
      {
        system_id: "username",
        password: "password",
      },
      function (pdu) {
        console.log(pdu)
        session.submit_sm(
          {
            dest_addr_ton: 1,
            dest_addr_npi: 1,
            destination_addr: "+...........", // number
            source_addr_ton: 5,
            source_addr_npi: 0,
            source_addr: "Test",
            short_message: "Hello!" ,
          },
          function (pdu2) {
            if (pdu2.command_status == 0) {
                console.log("message sent OK");
                return;
                // Here it succeeds
              }
              console.log("message sending failed");
              console.log(pdu2);
          }
        );
      }
    );
  }
);

SERVER

const smpp = require('smpp');

const server = smpp.createServer((session) => {
  session.on('error', (err) => {
    console.log(err);
  });
  session.on('bind_transceiver', (pdu) => {
    session.pause();
    if (pdu.system_id === process.env.USERNAME && pdu.password === process.env.PASSWORD) {
      session.send(pdu.response());
      session.resume();
      // here it succeeds
    } else {
      session.send(
        pdu.response({
          command_status: smpp.ESME_RBINDFAIL,
        }),
      );
      session.close();
    }
  });

  session.on('submit_sm', (pdu) => {
    const receivedAt = new Date();
    const randomMath = Math.floor(Math.random() * (99 - 10) + 10);
    const msgID = `${receivedAt.getTime()}-${randomMath}`;

    session.send(
      pdu.response({
        message_id: msgID,
      }),
    );

      session.deliver_sm({
        source_addr: pdu.source_addr,
        source_addr_ton: pdu.source_addr_ton,
        source_addr_npi: pdu.source_addr_npi,
        dest_addr_ton: pdu.dest_addr_ton,
        dest_addr_npi: pdu.dest_addr_npi,
        destination_addr: pdu.destination_addr,
        short_message: pdu.short_message,
        esm_class: smpp.ESM_CLASS.MC_DELIVERY_RECEIPT,
        sequence_number: pdu.sequence_number,
      });
  });

 // This isn't triggered
  session.on('deliver_sm', (pdu) => { 
    if (pdu.esm_class == 4) { 
      const shortMessage = pdu.short_message; 
      console.log("Received DR: %s", shortMessage);
      session.send(pdu.response()); 
    }
  });

  session.on("pdu", (pdu) => { 
    console.log('GOT PDU ', pdu);
  });

  session.on('enquire_link', (pdu) => {
    session.send(pdu.response());
  });

  session.on('unbind', (pdu) => {
    session.send(pdu.response());
    session.close();
  });
});

server.listen(settings.port);
console.log(`Server is listening on ${settings.port}`);

Here you find some PDU responses. How can you read these to know if an sms has been successfully sent (I see that command_status on submit_sm is 0, so should that mean it's fine) ?

PDU {
  command_length: 17,
  command_id: 2147483657,
  command_status: 0,
  sequence_number: 1,
  command: 'bind_transceiver_resp',
  system_id: ''
}

GOT PDU  PDU {
  command_length: 39,
  command_id: 9,
  command_status: 0,
  sequence_number: 1,
  command: 'bind_transceiver',
  system_id: 'username',
  password: 'password',
  system_type: '',
  interface_version: 80,
  addr_ton: 0,
  addr_npi: 0,
  address_range: ''
}

GOT PDU  PDU {
  command_length: 56,
  command_id: 4,
  command_status: 0,
  sequence_number: 2,
  command: 'submit_sm',
  service_type: '',
  source_addr_ton: 5,
  source_addr_npi: 0,
  source_addr: 'Test',
  dest_addr_ton: 1,
  dest_addr_npi: 1,
  destination_addr: '+........',
  esm_class: 0,
  protocol_id: 0,
  priority_flag: 0,
  schedule_delivery_time: '',
  validity_period: '',
  registered_delivery: 0,
  replace_if_present_flag: 0,
  data_coding: 1,
  sm_default_msg_id: 0,
  short_message: { message: 'Hello!' }
}

GOT PDU  PDU {
  command_length: 16,
  command_id: 21,
  command_status: 0,
  sequence_number: 3,
  command: 'enquire_link'
}

GOT PDU  PDU {
  command_length: 16,
  command_id: 21,
  command_status: 0,
  sequence_number: 4,
  command: 'enquire_link'
}

// and so on

Am I missing something? Or it just couldn't work this way?

0 Answers
Related