'Is it possible to send a single message to multiple numbers at a time using Twilio?

I'm developing an app that allows users to add people, info, and Name/phone, or select multiple numbers from their iPhone contact list to send SMS messages to the selected numbers. the problem is Twillio API needs to be call every time per number. Is their any way to call the API once for multiple numbers?

  • Is it possible to send message to multiple number at a time?
  • Is it possible to send multiple messages?

Thanks in advance



Solution 1:[1]

It's not possible, you need to iterate through the list and make one request per message (which is probably better than batching it and dealing with the potential of multiple errors / resends).

Solution 2:[2]

Each new SMS message from Twilio must be sent with a separate REST API request. To initiate messages to a list of recipients, you must make a request for each number to which you would like to send a message. The best way to do this is to build an array of the recipients and iterate through each phone number.

const numbersToMessage = ["+15558675310", "+14158141829", "+15017122661"]

numbersToMessage.forEach(async number => {
  const message = await client.messages.create({
    body: 'message body',
    from: '+16468635472',
    to: number
  });
  console.log(message.status)
});

Solution 3:[3]

Yes it is possible. You have to provide the numbers as a list and iterate API call. For example send a message to two numbers.

numbers = ['+1234562525','+1552645232']
for number in numbers:
    proxy_client = TwilioHttpClient()
    proxy_client.session.proxies = {'https': os.environ['https_proxy']}
    client = Client(account_sid, auth_token, http_client=proxy_client)
    message = client.messages \
        .create(
        body="Your message",
        from_='Your Twilio number',
        to=number
    )

Solution 4:[4]

Yes this is possible. Infact i'm trying to do the same thing at the moment(which is why i'm here) and Twilio has some advanced stuff that lets us achieve this.

Assuming you have a twilio ssid, twilio auth token and a twilio phone number, the next thing you have to do is create a "Twilio Messaging Service" from the dashboard. You can use the ssid of the created messaging service and use or if you want to send a message to like 10k numbers in one go, you create a "Twilio Notify Service" from the dashboard which takes the previously created messaging service as part of its configuration. Once this is done you can call the twilio.notifications.create() and pass bindings({ binding_type: 'sms', address: number }) for each phone number to it.

Complete explanation found in this twilio blog right here with perfectly working code.

https://www.twilio.com/blog/2017/12/send-bulk-sms-twilio-node-js.html

Solution 5:[5]

Yes it is possible to send message to multiple user's from your Twilio Number.

You can try this for your node.js file:

var arr = ["+1xxxxxxxxxx","+1xxxxxxxxx"];

arr.forEach(function(value){console.log(value);

client.messages.create({
    to:value,

    from: "+19253504188",

    body: msg,
}, function(err,message){   
    console.log(err);
});

});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Lytle
Solution 2 Tân Nguy?n
Solution 3 SamithaP
Solution 4 Chet
Solution 5 JJJ