I need to parallelize our calls to send text messages so that we can send more than one at a time.
We have an existing long standing Twilio Account. When I try to parallel the call to send a text I get a "Too Many Requests" exception from Twilio.Exceptions.ApiExceptions (429) https://www.twilio.com/docs/api/errors/20429.
This is our method that calls Twilio to send the text:
public async Task<MessageResource> SendMessage(string body, string ToNumber)
{
Twilio.TwilioClient.Init(config.apiKey, config.apiSecret, config.accountSID);
var message = await MessageResource.CreateAsync(
body: body,
from: config.fromNumber,
to: new Twilio.Types.PhoneNumber(ToNumber)
);
return message;
}
This is the line from which I'm trying to invoke the method that calls the method above.
reminders.ToList().AsParallel().WithDegreeOfParallelism(2).ForAll(async r => { await ProcessReminders(r); });
Surely the API supports at least 2 concurrent requests? This is a similar question but its about a year old and I'm not sure it applies as this is a longstanding account. Twilio API - Too Many Requests when sending SMS
As of version 5 I believe twilio made the methods for creating the clients and sending messages went from instance to static. Is there some setting or new means of sending messages concurrently?