Reputation: 175
I am having an issue with Twilio not sending a message to all the values in an array.
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."
}
});
}
}
When I console log a[index] it logs all the numbers which are stored but when the client.send message is used, only one of the numbers is sent and not all. Any reason for this?
Upvotes: 1
Views: 403
Reputation: 1486
The Issue occurs due to you using the Free version. If you want to send an SMS to all the numbers you have to verify them in order to proceed.
In order to verify a number go your Twilio console, Numbers, Verified caller IDs and the plus sign. You can choose the option to either get a call or an SMS.
You can also upgrade your Twilio account anytime you like from the Dashboard.
Upvotes: 1