【问题标题】:Twilio sendMessage not sending to all values in an arrayTwilio sendMessage 未发送到数组中的所有值
【发布时间】:2017-02-21 16:18:52
【问题描述】:

我遇到了 Twilio 没有向数组中的所有值发送消息的问题。

    var index;
var a = req.body.numbers;
console.log(a);

if (req.body.numbers.indexOf("undefined") > -1) {
console.log("No numbers stored");
} else {
for (index = 0; index < a.length; ++index) {
    console.log(a[index]);
client.sendMessage({

    to: a[index], // Any number Twilio can deliver to
    from: '+19179246693 ', // A number you bought from Twilio and can use for outbound communication
    body: req.body.title + ": " + req.body.message // body of the SMS message

}, function(err, responseData) { //this function is executed when a response is received from Twilio

    if (!err) { // "err" is an error received during the request, if any

        // "responseData" is a JavaScript object containing data received from Twilio.
        // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
        // http://www.twilio.com/docs/api/rest/sending-sms#example-1
        console.log(responseData.to);
        console.log(responseData.from); // outputs "+14506667788"
        console.log(responseData.body); // outputs "word to your mother."

    }
});


}
}

当我控制台记录 a[index] 时,它会记录所有存储的数字,但是当使用 client.send 消息时,只发送一个数字而不是全部。这有什么原因吗?

【问题讨论】:

  • 免费版还是付费版?
  • 我使用的是免费版本。
  • 尽管我使用的是免费版本,但它完全忽略了其他数字,尽管它们在那里。

标签: javascript arrays node.js express twilio


【解决方案1】:

问题是由于您使用免费版本而发生的。如果您想向所有号码发送短信,您必须对其进行验证才能继续。

要验证号码,请转到您的 Twilio 控制台、号码、已验证的来电显示 和加号。您可以选择接听电话或发短信。

您还可以随时从仪表板升级您的 Twilio 帐户。

【讨论】:

  • 如果我使用付费版本,我必须这样做吗?
  • 不,你没有。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
相关资源
最近更新 更多