Too Many Requests in sending Bulk Messages using Twilio Message Service - twilio

I am getting the error below when I send bulk messages using Twilio Message Service.
[HTTP 429] Unable to create record: Too Many Requests
I have around 50 numbers in the sender pool in this Message Service.
And I am trying to send about 5K messages at once, some delays are Okay,
But the messages couldn't be sent due to this error,
Thanks in advance,

Twilio developer evangelist here.
A 429 error means that you are exceeding the number of concurrent connections to the Twilio API. By default, this is 100, though it can vary depending on your account.
To counteract this, you should aim to make less than 100 concurrent requests to the API and implement retries with an exponential back off to allow for your other requests to finish.
There is more information on the 429 error here including further links for implementing the above strategies.

Related

Is there a Twilio outbound SMS magic number that hits a timeout value?

I'm testing some flows that use outbound SMS via Twilio and have been really pleased and impressed by the magic numbers provided e.g. https://www.twilio.com/docs/iam/test-credentials
However, I'm interested to see how our application responds if there's some issue sending an SMS to a number where it essentially hits a timeout value. I haven't found a magic number such as this or know of a way to recreate the scenario, can anyone help me here?
Even if you were using a real auth credentials and real phone number (instead of magic number), I suspect Twilio just queues the request on their side and responds with a HTTP 201, so you'll always get a very fast response from Twilio, but it doesn't necessarily mean the message has been sent to a carrier and delivered to a device.
If you're using Twilio messaging services, you can subscribe to delivery status callbacks to get the status of a SMS e.g. sending, sent, delivered, failed, etc - see here. Note: I don't know if you'd receive callbacks with magic numbers - I suspect not... either way you can provision a Twilio phone number pretty cheaply to test e.g. in Australia (where I'm from) I can purchase a AU phone number for $6 per month and I can release the phone number when ever I want to stop getting billed for it...
If you just want your app to timeout on invocation of the Twilio API you can do something like the following (in .NET core) to force timeout a request in a specified amount of time (1 second in example below):
using var tokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(1000));
response = await twilioHttpClient.PostAsJsonAsync($"2010-04-01/Accounts/{accountSID}/Messages.json", request, jsonSerializerOptions, tokenSource.Token);
If timeout is exceeded, an exception will be thrown that you can handle. Note: there's various networking tools that can be used to block or limit outbound requests, which you can use to test timeout scenarios.

Increase Twilio Total Timeout from 15000ms - SMS

When an API call is made after receiving an SMS via Twilio, I occasionally get the error below -
Error: Total timeout is triggered. Configured tt is 15000ms and we attempted 1 time(s)
The API call occasionally takes longer than 15 seconds to return a response (this is due to having to process the SMS etc.). How can I configure the total timeout to say 25000ms?
It is possible to override the timeout settings for a webhook. However, the maximum total time (tt) for webhooks is 15 seconds and you cannot increase it beyond there.
If you find your service cannot respond within that time, you might want to hand off the processing of the SMS to a job and respond to the webhook quicker. If you then intend to reply to the SMS, you can do so using the REST API message resource instead of TwiML.

Clearing/Deleting messages in Twilios SMS Message Queues

We had some sort of bug that queued up the same message thousands of times, each of them is undelivered because of the spam carrier restrictions, because it was a not real number or something.
We've looked around their docs and stack overflow but can't find anything that looks relevant.
It seems like Twilio keeps trying though - over and over - so it's send out thousands of the same message and keeps queueing them. Or at the very least
How can we clear our whole SMS message queue? We're happy if we never send it again, as nothing in there is mission critical.
The best approach is a ticket to Twilio support via the Twilio Console or help#twilio.com as a P1 (with you Account SID), indicating you have an out of control process queuing up thousands of SMS messages.
They will ask that you fix the process and fail the messages in queue.

Increase the wait time of Twilio messaging?

Let's assume a server has a lag in its internet network. Whenever, Twilio is attempting to message it, then the messaging are succceding 50% of the time , while the other 50% are failing because of HTTP: connection timed out.
Is there any way to tell TWilio to increase the wait-time or retry messaging the server?
Twilio developer evangelist here.
You won't be able to increase the timeout on Twilio or have it retry but what you can do is check the response you get from Twilio using the callback url. That is obviously providing Twilio is able to make a request to your server at that time.
Twilio will then make a request to your server to tell you whether it was able to send the message or not.
You could then add those messages into a queue, and try to resend them later on.
What you could also do is use the API to get the error logs for your application, and try to resend the messages for any message that wasn't sent. Have a look at the Events Monitor API for this.
Let me know if this helps you.

How many times Twilio will try sending texts to a number which has been, out of range, network disconnected?

I am trying to understand before twilio generated error #30003, how many times it tried reaching the end cellphone #, if the subscriber's cell phone is out of range, not available? switched off, temporary disconnected and so on?
Twilio developer here.
Twilio only spends a few seconds trying to deliver an SMS message before determining that the message delivery failed. The exact amount of time varies based on which carrier is used for the delivery.
So if your first attempt to deliver a message failed but you want to try again later, you should add some logic to your application that resends the message to Twilio at a time that makes sense.
Note that Twilio does not charge you for failed attempts to send a message.
Let me know if that helps!

Resources