Search code examples
node.jstwiliotwilio-apitwilio-programmable-chattwilio-functions

How can I send notifications to multiple numbers with Twilio?


I'm trying to send sms notification with Twilio but i can't, it only send notification to one of the numbers(my number)that I add to my notification options ('notificationOpts') and always happens the same. It only works for my number but not for the others I have added. I don't know what I'm doing wrong.

const accountSid = 'xxxxxxxxxxxxxxxxxx';
const authToken = 'xxxxxxxxxxxxxxxxxx';
const notifyServiceSid = 'xxxxxxxxxxxxxxxxxx';

const client = require('twilio')(accountSid, authToken);
const notificationOpts = {
  toBinding: JSON.stringify({
    binding_type: 'sms',
    address: '+00000',
  }),
  toBinding: JSON.stringify({
    binding_type: 'sms',
    address: '+00001',
  }),
  body: 'HI',
};

client.notify
  .services(notifyServiceSid)
  .notifications.create(notificationOpts)
  .then(notification => console.log(notification.sid))
  .catch(error => console.log(error));

Solution

  • I just tried the code and it works fine here. Are you maybe still on a trial account? The trial account only allows sending numbers to verified numbers like most likely your own phone number.