首页 > 解决方案 > Twilio 函数错误 20429 - 请求多条短信

问题描述

我正在使用 Twilio 功能和可编程 SMS 将 SMS 消息发送到我的 iOS 应用程序中的数字列表。列表中只有 100 多个手机号码(出现此错误时为 113 个)。这些消息中的大多数都会发送,但随后该函数说它在 502 毫秒后超时。

我正在使用 Twilio 中的示例代码发送到组消息(我已在下面复制)并从我的 iOS 应用程序发出 URLSession 请求。

有没有办法可以解决这个问题,以便我可以发送到这个相当大的电话号码列表或使功能运行更长时间?

非常感谢您的帮助。汤姆

要求:

let messagesPhoneNumberString = [+447987654321abc,+447123789456def,+447123456789ghi]
"https://myfunction.twil.io/send-messages?phoneAndID=\(messagesPhoneNumberString)&globalID=\(current globalID)"

我的 Twilio 功能代码:

exports.handler = function(context, event, callback) {

    let phoneAndIDString = event['phoneAndID'];
    let globalID String = event['globalID'];
    let numbersArray = phoneAndIDString.split(",");

Promise.all(
  numbersArray(number => {

      let phoneNumberSplit = "+" + number.slice(1, 13);
      let idSplit = number.slice(13);

      console.log('Send to number: ' + phoneNumberSplit + ' - with ID: ' + idSplit);

    return context.getTwilioClient().messages.create({
      to: phoneNumberSplit,
      from: 'Example',
      body: 'Hello World: ' + idSplit
    });
  })
)
  .then(messages => {
    console.log('Messages sent!');
    callback(null, response);
  })
  .catch(err => console.error(err));
    };

标签: iosswiftsmstwiliotwilio-functions

解决方案


Twilio 开发人员布道者在这里。

Twilio Functions 的超时时间为 5 秒,因此使用 Twilio 函数一次性发送这么多消息可能不是最好的主意。

不过,您有一些选择。

如果您向所有这些号码发送相同的消息,那么您可以使用 Twilio Notify passthrough API。查看这篇博文中关于使用 Node.js 发送大量消息的详细信息。

否则,如果您必须发送不同的消息,那么您可以将数字分成批次并多次使用相同的功能。

最后,您可以使用不同的平台来发送没有 5 秒限制的消息。


推荐阅读