Azure / azure-webjobs-sdk-extensions

Azure WebJobs SDK Extensions
MIT License
342 stars 206 forks source link

Send multiple messages with twilio binding #493

Closed julielerman closed 6 years ago

julielerman commented 6 years ago

Twilio API lets you send one message per request. (https://support.twilio.com/hc/en-us/articles/223181548-Can-I-set-up-one-API-call-to-send-messages-to-a-list-of-people-)

I've used their API direclty with azure functios in C# to iterate thorugh a list of phone numbers and send messages. And I had to wait 1 second in between each message. (Easy enough with C#)

Now I'm using this binding and I'm in NodeJS (where my skills are not as strong a C#). I can't figure out how to loop through numbers and push the messages out. Is the binding limited to one message on the context? Is tehre a explicit SEND method? Here is my function. It is only sending out ONE message.

module.exports = function (context, documents, subscriberList) {
    if (!!documents && documents.length > 0) {
        context.log('Document Id: ', documents[0].id);
        //context.bindings.message = {};
        subscriberList.forEach(
            subscriber => {
                context.log(subscriber.phone);
                context.bindings.message = {
                    body : "Hello" + subscriber.phone,
                    to : subscriber.phone
                }
             }
        )
    }
    context.done();
}

I did try to place the message into a SetTimeOut method but still only got one text.

Thanks for any help. I'm currently doing this in the portal with Azure Functions v1 and the built in Twilio binding. I will move this to 2 using the webjobs 3.0.0-rc1 package (in VS Code, not the portal, for testing)

julielerman commented 6 years ago

oh maybe some clues in #421 I'll see if messages (plural) is working in either API

julielerman commented 6 years ago

ahh , just set message= an array of messages!! duh. :)