Account SID and Auth Token:
Go to Dashboard and click on Messaging Overview:
Get Service Instance ID: We have created SID above. You can go to this link and copy your Instance ID.
https://www.twilio.com/console/notify/services
Note: Service Instance id will start with: ISxxxxxxxxxxxxxx
npm install
const twilio = require('twilio');const accountSid = 'ACXXXXXXXXXXXXXXXXXX';const authToken = '12sadf2323424232sdfa23';const notifySID = 'ISXXXXXXXXXXXXXXXXXXX';const client = require('twilio')(accountSid, authToken);const data = require('./import-data.js');/* Lets format the data into desired array :[ '{"binding_type":"sms","address":"+44XXXXXXXXXX"}', '{"binding_type":"sms","address":"+44XXXXXXXXXxx"}' ]*/let
formattedData = [];data.forEach(function(value){formattedData.push(JSON.stringify(value));});console.log(formattedData);const notificationOpts = {toBinding: formattedData,body: 'YOUR MESSAGE HERE!',};client.notify.services(notifySID).notifications.create(notificationOpts).then(binding => console.log(binding.sid)).catch(error => console.log(error)).done();
Create import-data.js and add your sms list into that:
module.exports = [{binding_type: 'sms',address: '+44555555555'},{binding_type: 'sms',address: '+440777777777'},];
node send_sms.js
It will queue all the messages at once and twilio will process the queue.
Resource: https://codedrill.in/twilio-send-notification-messages-nodejs-sdk/