12

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

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
user1357157
  • 131
  • 1
  • 1
  • 4
  • They have notify api as well. That might work in your case. At your end, it could be one call but they will take care of the distribution. – johnny Aug 27 '18 at 20:10
  • https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-node-js#send-a-message-to-multiple-recipients – AMIC MING Nov 01 '19 at 19:59

5 Answers5

14

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).

Tim Lytle
  • 17,549
  • 10
  • 60
  • 91
0

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

Chet
  • 134
  • 1
  • 11
-1

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)
});
-2

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);
});

});
JJJ
  • 32,902
  • 20
  • 89
  • 102
  • 1
    Nope. This makes one HTTP call per number. The OP wants one HTTP call in total. – Julian Apr 17 '17 at 00:55
  • this is what he asked he didn't want to do it. He wants all in one call... – johnny Jun 23 '18 at 21:38
  • This sends a message to each user at one HTTP call per number. This is a unrealistic and expensive solution. – NicholasByDesign Jun 14 '20 at 22:40
  • @NicholasByDesign while its not the solution the OP asked for I wouldn't call it unrealistic or expensive. Its quite realistic as this is the only way Twilio allows you to send multiple messages and since it is the only way the expense is just the reality of the situation. Kick it off async to some server and dont think about it again. – AtheistP3ace Oct 30 '21 at 18:06
-2

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
    )
SamithaP
  • 90
  • 1
  • 1
  • 13