Twilio sendMessage不发送到数组中的所有值

时间:2016-10-12 18:24:31

标签: javascript arrays node.js express twilio

我遇到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."

    }
});


}
}

当我控制日志[index]时,它会记录所有存储的数字,但是当使用client.send消息时,只发送其中一个号码,而不是全部。有什么理由吗?

1 个答案:

答案 0 :(得分:1)

由于您使用的是免费版本,因此会出现问题。如果您想向所有号码发送短信,您必须验证它们才能继续。

为了验证号码,请转到Twilio控制台,Numbers,验证来电显示 和加号。您可以选择接听电话或短信。

您也可以随时从信息中心升级Twilio帐户。