Search code examples
c#twiliotwilio-apitwilio-twiml

Twilio send sms to a list with 100+ numbers. Twilio throwing 11200 Error


I have made a controller that sends a message to a list specified in an incoming message. When I'm finished sending out all the messages, I want to return a TwiML response.

However, if the list is too big it looks like Twilio is timing out. If the list contains 10 numbers a response is returned, if it contains 40 numbers Twilio then shows me a 11200 error in the dashboard.

The outgoing message is always sent, its just the response that fails.

I have done something like this:

foreach (var receiver in receivers)
{
    try
    {
        await MessageResource.CreateAsync(
            from: new PhoneNumber(SomeGroupName),
            to: new PhoneNumber(receiver.Mobile),
            body: SomeOutgoingMessage);
    } 
    catch (SomeException e)
    {
        //Errorhandling
    }
}
response.Message("Message sent to all members")
return TwiML(response);

Do anyone know why this is happening? Is there any other way to do this?


Solution

  • Twilio developer evangelist here.

    Twilio will wait 15 seconds for a response from your application. If your app takes longer than 15 seconds, Twilio will record an 11200 error. In your case, it takes less than 15 seconds to send the message to 10 numbers, but for 40 numbers it takes longer.

    If all the messages are the same, then I can recommend using Twilio Notify to send them all with just one API request. I wrote up a blog post on how to send bulk SMS messages with Twilio and Node.js. I know you're using C#, but that is worth reading for the explanation and walkthrough.

    The code you would use to send bulk SMS with C# should look a bit like this:

    using System;
    using System.Collections.Generic;
    using Twilio;
    using Twilio.Rest.Notify.V1.Service;
    
    public class Example
    {
        public static void Main(string[] args)
        {
            // Find your Account SID and Auth Token at twilio.com/console
            const string accountSid = "your_account_sid";
            const string authToken = "your_auth_token";
            const string serviceSid = "your_messaging_service_sid";
    
            TwilioClient.Init(accountSid, authToken);
    
            var notification = NotificationResource.Create(
                serviceSid,
                toBinding: new List<string> { "{\"binding_type\":\"sms\",\"address\":\"+15555555555\"}",
                "{\"binding_type\":\"sms\",\"address\":\"+123456789123\"}" },
                body: "Hello Bob");
    
            Console.WriteLine(notification.Sid);
        }
    }
    

    Let me know if this helps at all.