farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
417 stars 177 forks source link

Getting esm_class === 4 for every sent SMS #241

Closed elhananjair closed 1 year ago

elhananjair commented 1 year ago

Hello friends, I have successfully sent SMS to mobile phones through connecting with SMSC, I was expecting a delivery report as the client received the SMS. In my situation, the client (mobile user) will be charged on receiving SMS from my web app, and I can only be sure that the user has been charged when my application receives a delivery report, but in my case, I am always getting esm_class === 4 even while the user didn't receive the SMS because of low in balance.

Is there anything I am missing here?

const smpp = require('smpp');

const session = smpp.connect({url: 'smpp:IP"', auto_enquire_link_period: 10000,});
// const session = smpp.connect({url: 'smpp://127.0.0.1:2775"', auto_enquire_link_period: 10000,});
// session.bind_transceiver({system_id: "Y9Clav9OoiWu3I0", password: "wmpvI02g"}, function (pdu) {
session.bind_transceiver({system_id: "ID", password: "PASSWORD"}, function (pdu) {
    if (pdu.command_status === 0) { //Successfully bound
        console.log("Successfully bound!");
            session.submit_sm({
                destination_addr: '251967455657', // The destination phone number you want to send a message to
                source_addr_ton: 5, // Type of number of the source address
                source_addr_npi: 0, // 0 = Unknown, 1 = ISDN, 3 = Data, 4 = Telex, 5 = SMS, 6 = Radio, 7 = Fax, 8 = Videotelephony
                dest_addr_ton: 1, // Type of number of the destination phone number
                dest_addr_npi: 1, // 0 = Unknown, 1 = ISDN, 3 = Data, 4 = Telex, 5 = SMS, 6 = Radio, 7 = Fax, 8 = Videotelephony
                source_addr: '9923',       // The Sender ID or Address, This will be displayed to the destination phone number
                registered_delivery: 1, // Set registered delivery (0 = no, 1 = yes)
                // message_id: ID, // Message ID
                short_message: "Check SMS",  // The message body, Replace it with the message you want to send.
                data_coding: 8
            }, function(pdu) {
                if(pdu.command_status === 0){
                    console.log("The message successfully sent! ");
                }else {
                    console.log("Message didn't sent " + pdu.command_status);
                }
            })
    }
})

session.on('deliver_sm', (pdu) => {
    if(pdu.esm_class === 4){ //esm_class Indicates Message Mode and Message Type,
        console.log("Delivery report: " + pdu.source_addr);
        console.log(pdu.esm_class)
        session.send(pdu.response()); //// Send the response to the SMSC, I think every command have response, and for deliver_sm there is deliver_sm_resp, ESME will respond with deliver_sm_resp PDU as a means of acknowledging the delivery.
        //session.close();
    }
})

//Error Handling
session.on('error', (e) => {
    if(e.code === 'ETIMEOUT') {
        console.log("Connection to SMS-C Timeout");
    }else if(e.code === 'ECONNREFUSED'){
        console.log("Connection to SMS-C Refused")
    }else if(e.code === 'EAI_AGAIN'){
        console.log("Connection to internet is lost!");
    }else {
        console.log(`There is something wrong connecting to SMS-C, Error code: ${e.code}` );
    }
})
guicuton commented 1 year ago

Hey,

Idk if i understand you well but the charge of message sent is a common flow on every SMSC provider.

Differ from email that usually are billed by delivery, the sms are billed by sent, no matter was the final status

Soon as your SMSC vendor confirm the acceptance of message, they will charge you.

The ESM_CLASS 4 will be given you for DLR (delivery reports) from messages that you had sent.

If isn't 4, then it's a message originated (MO) from a mobile to your shortcode or as reply from some message that you have sent

If you are creating an app that allows user to send SMS, the best way you can do it about the billing is charge by sent, not by delivery.

Keep in mind that lot of carriers around the globe don't send the DLR , so make your whole system dependent on DLR to charge your user it's not a good idea.

To read the final status of message, you will need read the short_message param given in your deliver_sm.

Netherless, any doubt about the params, status, esm_class, TLVs, given on yours deliver_sm with this SMSC provider, you'll sure find best match answers with their support :-)

elhananjair commented 1 year ago

@guicuton thanks for your reply.

Soon as your SMSC vendor confirms the acceptance of a message, they will charge you. My idea was opposed to this one, From my app I send a submit_sm request to SMSC and then SMSC will charge the end user for every SMS received not me.

So the whole point I was making was, that delivery_report is with esm_class=0 means the end user has received the SMS right? The SMSC won't send the text unless the end-user has a balance on the phone, so in that case, my app shouldn't receive a delivery report or pdu_command status shouldn't be = 0 right?

EDIT

To read the final status of the message, you will need to read the short_message param given in your deliver_sm.

oh God this one, I had no idea about that, I was thinking just if I get the delivery receipt it indicates successfully delivered SMS, but now I see a stat string inside the short_message param just like you said.

Thank you so much I will re-edit my code to only depend on that value.