komuw / naz

naz is an async SMPP client.
https://komuw.github.io/naz/
MIT License
39 stars 12 forks source link

Examples of using correlator #218

Closed Eudorajab1 closed 2 years ago

Eudorajab1 commented 2 years ago

Are there any examples of how to use the correlator as the documentation is not too clear on this particular issue. Would be good to have an example of say seeing which messages belong to a batch for example.

komuw commented 2 years ago

Hello, When you use naz it comes with correlator without you having to do anything; https://github.com/komuw/naz#usage
All the logs after that will have a log_id field.

Note that as stated in the documentation; https://komuw.github.io/naz/correlater.html#naz.correlater.BaseCorrelater ; This correlation is on a BEST effort basis

Would be good to have an example of say seeing which messages belong to a batch for example.

If you look at the end of the example at; https://komuw.github.io/naz/step_by_step_demo.html , you can see that some logs have "log_id": "kLqk248JSK8". All the logs with that log_id belong to the same batch.

I don't know if that answers your question.

Eudorajab1 commented 2 years ago

Hello again and thanks for the quick response. I guess I am getting a bit confused as I have the following requirement that I am struggling to resolve.

I am connecting to 3 MNO's A, B, C Operator C is effectively the failover (will accept all destination addresses and deliver off-net)

So if I send sms to operator A (according to the correct CC/AC (country code/area code) as per dest_addr) and it fails with an error code as the number has been ported I want to try to send the same message via operator B. If that fails due to MNP I need to send the number to operator C (as they deliver off-net but cost a lot more than the other 2)

Likewise if the number is sent to operator B first (based on dest addr) and it fails then I need to send to operator A then operator C.

So I need some way of (a) checking which was the last network I sent a spefic message to. (the rest is pretty much straight forward)

(b) resending the message to next operator in the chain base on response (either submit_sm_resp or deliver_sm)

Any thoughts you may have would be most appreciated

komuw commented 2 years ago

I think you could use hooks to try and achieve that; https://komuw.github.io/naz/hooks.html

import asyncio
import naz

my_client = None

class MyHook(naz.hooks.BaseHook):
    async def to_smsc(self, smpp_command: str, log_id: str, hook_metadata: str, pdu: bytes):
        pass

    async def from_smsc(
        self,
        smpp_command: str,
        log_id: str,
        hook_metadata: str,
        status: "state.CommandStatus",
        pdu: bytes,
    ):
        print("smpp_command: ", smpp_command)
        print("status: ", status)
        if smpp_command == "submit_sm":
            if status != "success":
                # previous sending did not succed. so lets try to send again.
                msg = naz.protocol.SubmitSM(
                    short_message="Hello World-{0}".format(str(i)),
                    log_id="myid12345",
                    source_addr="254722111111",
                    destination_addr="254722999999",
                )
                await my_client.send_message(msg)

loop = asyncio.get_event_loop()
broker = naz.broker.SimpleBroker(maxsize=1000)
my_client = naz.Client(
    smsc_host="127.0.0.1",
    smsc_port=2775,
    system_id="smppclient1",
    password="password",
    broker=broker,
    hook = MyHook(),
)

I haven't tested the code so I don't know if it would work.

Eudorajab1 commented 2 years ago

Thanks will see if I can get it working !!

Eudorajab1 commented 2 years ago

One more quick question ... how does naz deal with deliver_sm's .. I can only see deliver_sm_resp in the code?

komuw commented 2 years ago

does naz deal with deliver_sm

naz is an smpp client. So it never needs to send deliver_sm to an smsc server. deliver_sm is sent by servers not clients: https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2081-L2082

At least that is my understanding of SMPP version 3.4; I haven't looked at other smpp versions but I would expect them to have the same semantics.

Eudorajab1 commented 2 years ago

Okay but we need to get a DLR from the smsc_server right ? and also we can for sure get MO messages from the server I would imagine. My understanding of this and I may well be wrong but we send a submit_sm to the server that replies with a submit_sm_resp. If we have requested a delivery receipt then server should also send back a deliver_sm. As I say that is my understanding and could well be wrong and will also check the docs

On Sat, 3 Sept 2022 at 20:34, Komu Wairagu @.***> wrote:

does naz deal with deliver_sm

naz is an smpp client. So it never needs to send deliver_sm to an smsc server. deliver_sm is sent by servers not clients:

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2081-L2082

At least that is my understanding of SMPP version 3.4; I haven't looked at other smpp versions but I would expect them to have the same semantics.

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236178968, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZQNECJGR6JWMI2FYHBQK3V4OK3XANCNFSM6AAAAAAQDDSFIA . You are receiving this because you authored the thread.Message ID: @.***>

komuw commented 2 years ago

Yes, your understanding is correct. And naz does handle deliver_sm requests from the MNO correctly including sending back a corresponding deliver_sm_resp. https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2124

What I meant to say in my earlier response is that Naz never sends deliver_sm requests to MNO.

I hope this clarifies it

On Sun, Sep 4, 2022, 11:19 AM John Bannister @.***> wrote:

Okay but we need to get a DLR from the smsc_server right ? and also we can for sure get MO messages from the server I would imagine. My understanding of this and I may well be wrong but we send a submit_sm to the server that replies with a submit_sm_resp. If we have requested a delivery receipt then server should also send back a deliver_sm. As I say that is my understanding and could well be wrong and will also check the docs

On Sat, 3 Sept 2022 at 20:34, Komu Wairagu @.***> wrote:

does naz deal with deliver_sm

naz is an smpp client. So it never needs to send deliver_sm to an smsc server. deliver_sm is sent by servers not clients:

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2081-L2082

At least that is my understanding of SMPP version 3.4; I haven't looked at other smpp versions but I would expect them to have the same semantics.

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236178968, or unsubscribe < https://github.com/notifications/unsubscribe-auth/ADZQNECJGR6JWMI2FYHBQK3V4OK3XANCNFSM6AAAAAAQDDSFIA

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236286710, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHMWUKR4ZCG343YD2YBJR3V4RLQXANCNFSM6AAAAAAQDDSFIA . You are receiving this because you commented.Message ID: @.***>

Eudorajab1 commented 2 years ago

Okay great .. will take a look at the code and see if I can sort something out. Issue I have is I am waiting soemtiemes for a deliver_sm to tell me the status of the message .. either accepted, rejecected, undeliverable etc and can see no easy way to access the decoded deliver_sm pdu in the hook.

On Sun, 4 Sept 2022 at 11:16, Komu Wairagu @.***> wrote:

Yes, your understanding is correct. And naz does handle deliver_sm requests from the MNO correctly including sending back a corresponding deliver_sm_resp.

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2124

What I meant to say in my earlier response is that Naz never sends deliver_sm requests to MNO.

I hope this clarifies it

On Sun, Sep 4, 2022, 11:19 AM John Bannister @.***> wrote:

Okay but we need to get a DLR from the smsc_server right ? and also we can for sure get MO messages from the server I would imagine. My understanding of this and I may well be wrong but we send a submit_sm to the server that replies with a submit_sm_resp. If we have requested a delivery receipt then server should also send back a deliver_sm. As I say that is my understanding and could well be wrong and will also check the docs

On Sat, 3 Sept 2022 at 20:34, Komu Wairagu @.***> wrote:

does naz deal with deliver_sm

naz is an smpp client. So it never needs to send deliver_sm to an smsc server. deliver_sm is sent by servers not clients:

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2081-L2082

At least that is my understanding of SMPP version 3.4; I haven't looked at other smpp versions but I would expect them to have the same semantics.

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236178968, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ADZQNECJGR6JWMI2FYHBQK3V4OK3XANCNFSM6AAAAAAQDDSFIA

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236286710, or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABHMWUKR4ZCG343YD2YBJR3V4RLQXANCNFSM6AAAAAAQDDSFIA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236295499, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZQNEGSQMGA7U4P362HJ7LV4RSGXANCNFSM6AAAAAAQDDSFIA . You are receiving this because you authored the thread.Message ID: @.***>

Eudorajab1 commented 2 years ago

I am actually connecting via a gateway to multiple operators so the submit_sm_resp from the gateway is not really meaningfull as they either accept or reject before passing onto the MNO

On Sun, 4 Sept 2022 at 14:38, John Bannister @.***> wrote:

Okay great .. will take a look at the code and see if I can sort something out. Issue I have is I am waiting soemtiemes for a deliver_sm to tell me the status of the message .. either accepted, rejecected, undeliverable etc and can see no easy way to access the decoded deliver_sm pdu in the hook.

On Sun, 4 Sept 2022 at 11:16, Komu Wairagu @.***> wrote:

Yes, your understanding is correct. And naz does handle deliver_sm requests from the MNO correctly including sending back a corresponding deliver_sm_resp.

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2124

What I meant to say in my earlier response is that Naz never sends deliver_sm requests to MNO.

I hope this clarifies it

On Sun, Sep 4, 2022, 11:19 AM John Bannister @.***> wrote:

Okay but we need to get a DLR from the smsc_server right ? and also we can for sure get MO messages from the server I would imagine. My understanding of this and I may well be wrong but we send a submit_sm to the server that replies with a submit_sm_resp. If we have requested a delivery receipt then server should also send back a deliver_sm. As I say that is my understanding and could well be wrong and will also check the docs

On Sat, 3 Sept 2022 at 20:34, Komu Wairagu @.***> wrote:

does naz deal with deliver_sm

naz is an smpp client. So it never needs to send deliver_sm to an smsc server. deliver_sm is sent by servers not clients:

https://github.com/komuw/naz/blob/fa70c2981db2945e306a6401d6d8433819ed0228/naz/client.py#L2081-L2082

At least that is my understanding of SMPP version 3.4; I haven't looked at other smpp versions but I would expect them to have the same semantics.

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236178968, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ADZQNECJGR6JWMI2FYHBQK3V4OK3XANCNFSM6AAAAAAQDDSFIA

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236286710, or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABHMWUKR4ZCG343YD2YBJR3V4RLQXANCNFSM6AAAAAAQDDSFIA

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1236295499, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZQNEGSQMGA7U4P362HJ7LV4RSGXANCNFSM6AAAAAAQDDSFIA . You are receiving this because you authored the thread.Message ID: @.***>

komuw commented 2 years ago

I'll close this issue assuming you were able to resolve the problem; feel free to re-open if you deem necessary.

Eudorajab1 commented 2 years ago

Hi, Unfortunately I was pulled away from this issue but for sure please close it for now. Will open new issue if and when.

Thanks John

On Fri, 14 Oct 2022 at 15:00, Komu Wairagu @.***> wrote:

I'll close this issue assuming you were able to resolve the problem; feel free to re-open if you deem necessary.

— Reply to this email directly, view it on GitHub https://github.com/komuw/naz/issues/218#issuecomment-1278976412, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZQNEBJZLN54AKTG7G3JGLWDFKNFANCNFSM6AAAAAAQDDSFIA . You are receiving this because you authored the thread.Message ID: @.***>