I am working on a bulk SMS application that will send one message to a group of people in case of an emergency. I have reviewed the Twilio Docs and implemented their code, at which point I was getting a 429 error from the API. So I've added the exponential backoff code to prevent that, but when I run the script, it's only sending to the second number listed in the array.
const accountSid = '[ACCOUNT SID]';
const authToken = '[AUTH TOKEN]';
const client = require('twilio')(accountSid, authToken);
var numbersToMessage = ["+1800XXXXXXX", "+1888XXXXXXX"]
numbersToMessage.forEach(function(number){
var message = client.messages.create({
body: 'This is test #2 from August 21, 2020.',
from: '[TWILIO SENDER NUMBER]',
statusCallback: '[PIPEDREAM API URL]',
to: number
})
.then(message => console.log(message.status))
return((err) => {
// assumes that the error is "request made too soon"
backoffTime *= 2;
i--;
console.log(err);
return delay(backoffTime);
});
done();
});
Exponential backoff is completely new to me, so I'm fairly certain that's where the issue is, but that's as far as I get. I've tried using the npm package exponential-backoff, too, without any luck.