farhadi / node-smpp

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

Addition of more example on node-smpp usage #232

Closed elhananjair closed 1 year ago

elhananjair commented 1 year ago

Hello there, I loved using this package, I could send SMS easily, but it would be best if the Readme includes examples on how to receive SMS and auto-replies on received SMS.

Thank you.

guicuton commented 1 year ago

If your broker support 2-ways message, you will receive it on deliver_sm PDU. I think that is something more related to your user-case/business logic then the lib feature itself.

WIth that you do whatever you want such as some auto-reply rule. A small example of how to do it:

session.on('deliver_sm', (pdu) => {
    const { short_message, destination_addr, esm_class } = pdu
    if(esm_class !== 4 && short_message.message == 'hi') {
        session.submit_sm({
            destination_addr,
            short_message: 'Welcome'
        });
    }
});
elhananjair commented 1 year ago

@guicuton thank you so much for the support,

Something I couldn't understand is, isn't deliver_sm PDU sent from SMSC after submit_sm request sent to SMPP Server? shouldn't my SMPP Client listen for any arrived SMS?

I am sorry am new to SMPP world.

guicuton commented 1 year ago

On deliver_sm PDU you will receive the further data of DLR of your provider (delivery report) from messages that you have sent by submit_sm.

The MO (message originator - the arrived messages) your provider will sent you by the same PDU, the deliver_sm.

These messages you will receive every time that one destination answer some of message that you sent or when they sent directly for your number that you have with your provider.

This is the "default" scenario but is always good ask your provider by which PDU they will sent the MO data.

elhananjair commented 1 year ago

They have already said that they will invoke the deliver_sm API to send MO SMS messages to the App(SMPP Client), therefore I think the scenario you have specified is correct. Can I please add something that's a little bit confusing related to MO and MT, they have already provided me e.g 7922 as MT and 7233 as MO.

when I send I will use MT code (7922) as a source address right? and use MO (7233) as a destination address for SMSC (SMPP Server) will send SMS to my app, or in which my app receives SMS?

guicuton commented 1 year ago

Probably on both.

7929 the MO will be related to some MT that you sent (like one answer) 7233 the MO that the originator send for you regardless of a MT. (like one request)

But these are assumptions based on what i've already saw outthere. So the best hint that i can give to you about it is check with them how it will works the flow of these shortcodes that they provide to you 😄

elhananjair commented 1 year ago

Thanks a lot, I will do that they are not that cooperative tbh, they just sent me a document that is identical to the SMPP V5 specification 😄.

I have no idea how I get the total number of subscribers from my App, I don't think SMPP can provide such implementation. But I will try my best. THank you so much for the support, would you mind adding the code snippet you shared above to Readme just incase...

guicuton commented 1 year ago

Have in mind that the SMPP are responsible just for send and/or receive SMS messages. Nothing else.

Any additional control like auto-reply, count users, etc, etc you will need to develop your own solution rules with caching, dabatases and so on.

would you mind adding the code snippet you shared above to Readme just incase...

As the code snippet is to particular with your user-case imho it might not be relevant made one PR with this suggestion, but Im glad that were helpfull for you 😄

elhananjair commented 1 year ago

Have in mind that the SMPP are responsible just for send and/or receive SMS messages. Nothing else.

Any additional control like auto-reply, count users, etc, etc you will need to develop your own solution rules with caching, dabatases and so on.

This is good info thank you so much, now I am getting the idea. I thought the SMSC will provide such info but I understand now.

Thanks again.

elhananjair commented 1 year ago

Hello @guicuton I am sorry to bother you, but I don't where else I should go, there is no great forum regarding SMPP.

I was trying to connect to a real SMSC and I keep getting command_status=14 here is my code:

var smpp = require('smpp');
var session = smpp.connect({
        url: 'smpp://HOST_NAME:PORT',
        auto_enquire_link_period: 10000,
        debug: true
}, function() {
        session.bind_transceiver({
                system_id: 'ID', //Some number
                password: 'password', //8 
                interface_version: '0x34',
                system_type: '0x00',
                addr_ton: '0x00',
                addr_npi: '0x00',
                address_range: '0x00'
        }, function(pdu) {
                if (pdu.command_status === 0) {
                        // Successfully bound
                       console.log("Successfully Created Bound");
                }else if(pdu.command_status === 14){  
                      console.log("Invalid Password");
                }
        });
});

session.on('deliver_sm', (pdu) => {
    const { short_message, destination_addr, esm_class} = pdu;
    if(esm_class !== 4 && short_message.message === 'ok') { //Indicates Message Type and enhanced network services, if it's 4 then it's a delivery receipt >
        console.log("Recieved SMS");
    }
    console.log("PDU IS : " + pdu);
})

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}` );
    }
})
session.on('debug', function(type, msg, payload) {
        console.log({type: type, msg: msg, payload: payload});
});

I just read about command_status = 14 and it's about an invalid password but I really couldn't understand how that is possible. Can such restrictions be applied on the SMPP Server side? The password is right as far as I know.

elhananjair commented 10 months ago

It turned out I was using an incorrect password although the error message is misleading.