Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138134

Sending messages to multiple numbers using twilio Passthrough API

$
0
0

I am using twilio to send messages to multiple phone numbers in a single API call.

client.notify.services(notifyServiceSid)
  .notifications.create({
    toBinding: JSON.stringify([
      binding_type: 'sms', address: '** First phone number here **',
      binding_type: 'sms', address: '** Second phone number here **'
    ]),
    body: 'You just sent your first message with the Passthrough API!'
  })
  .then(notification => console.log(notification.sid))
  .catch(error => console.log(error));

The above example code snippet sends same message('You just sent your first message with the Passthrough API!') to array of phone numbers though what I'm trying to do is send different message to each phone number. That doesn't seems to possible with above code snippet. I couldn't find anything in the given blog either: Passthrough API. So is there anyway to send different message to each phone number. I also have an implementation that sends different message to each recipient:

const prepareSendingMessages = async (body) => {
    //parse message input and send message in loop
    try {
        console.log(body.data)
        for (const sms of body.data.messages) {
            await sendMessage(sms.to, sms.message)
        }
    } catch (error) {
        console.log(error);
    }

};

const sendMessage = async (to, message) => {
    let messageResult = await client.messages
        .create({
            body: message,
            from: process.env.TWILIO_NUMBER,
            to
        });

    console.log(messageResult);

    return true;
};

But I am looking if it is possible through Twilio's Passthrough API


Viewing all articles
Browse latest Browse all 138134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>