Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass extra data to submit_sm options #27

Closed
sukhrobkhakimov opened this issue Jul 22, 2015 · 3 comments
Closed

How to pass extra data to submit_sm options #27

sukhrobkhakimov opened this issue Jul 22, 2015 · 3 comments

Comments

@sukhrobkhakimov
Copy link

I want to insert an SMS to the database after submitting. How to pass extra data (custom data like client_id which is specific to my app) to submit_sm options.

@ti24horas
Copy link

@Sukhrob you're doing the inverse.
Normally, you wait for the response for submit_sm (submit_sm_resp) and associate the message_id with your database.

@sukhrobkhakimov
Copy link
Author

Thanks for your response @ti24horas. Here is the code:

var sms = JSON.parse(data); // Coming from RabbitMQ consumer

// Send an SMS
session.submit_sm({
    registered_delivery: true,
    source_addr: sms.sender,
    destination_addr: sms.recipient,
    short_message: sms.message
}, function (pdu) { // Here, I would want to bind each client to their own SMSs like this if possible: function (pdu, sms) {
    var parameters = {
        client_id: sms.client_id, // Is it safe to put client_id here directly as it is an asynchronous request?
        sender: pdu.source_addr,
        recipient: pdu.destination_addr,
        message: pdu.short_message,
        message_id: pdu.message_id,
        status: pdu.command_status,
        created_at: new Date()
    };

    // Save an SMS to the database
});

Say, if there are 10 clients which send a lot of SMSs per second, can one client overwrite another one's SMS?

@farhadi
Copy link
Owner

farhadi commented Sep 13, 2015

If your code is inside a function scope and you call submit_sm once in this scope (i.e. not in a loop) and you don't alter sms variable in this scope later, it's most likely safe to use the code you quoted.

@farhadi farhadi closed this as completed Sep 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants