我创建了一个控制器,它将消息发送到传入消息中指定的列表。当我完成发送所有消息后,我想返回一个TwiML响应。
但是,如果列表太大,看起来Twilio会超时。如果列表包含10个数字,则返回响应,如果它包含40个数字,则Twilio会在仪表板中显示11200错误。
始终发送传出消息,它只是响应失败。
我做过这样的事情:
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);
有谁知道为什么会这样?有没有其他方法可以做到这一点?
Twilio开发者传道者在这里。
Twilio将等待15秒钟以响应您的应用程序。如果您的应用需要超过15秒,Twilio will record an 11200 error。在您的情况下,将消息发送到10个号码所需的时间不到15秒,但对于40个号码,则需要更长的时间。
如果所有消息都相同,那么我建议使用Twilio Notify通过一个API请求发送所有消息。我写了一篇关于how to send bulk SMS messages with Twilio and Node.js的博客文章。我知道你正在使用C#,但这对于解释和演练是值得阅读的。
您将用于send bulk SMS with C#的代码应该看起来像这样:
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);
}
}
如果这有帮助,请告诉我。
https://www.twilio.com/docs/api/errors/11200
看起来它使Twilio执行操作的时间比你的应用程序愿意等待它执行该操作要长。