const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.calls
.create({
twiml: '<Response><Say>Ahoy, World!</Say></Response>',
to: '+14155551212',
from: '+15017122661'
})
.then(call => console.log(call.sid));
How can I modify this to accept more than one number?
Twilio developer evangelist here.
You can only make one call per API request, so to make calls to more than one number you will need to loop and make a request for each number. Like so:
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
async function makeCalls(numbers) {
numbers.forEach(async (number) => {
await client.calls
.create({
twiml: '<Response><Say>Ahoy, World!</Say></Response>',
to: number,
from: '+15017122661'
})
.then(call => console.log(call.sid));
});
}
const numbers = []; // An array of the numbers you want to make calls to.
makeCalls(numbers);