Twilio - Updating the usage of the phone library

Can this be implemented to be ran with multiple numbers or do I need to add an array?
I used the template to get a single phone number to work but I want it to be ran with multiple numbers. Around 20-25 numbers will be added to the automation.

I’ve attached a link to the Pipedream code for SMS with Twilio.

@zone6nft are you familiar with Node.js? I looked and Twilio’s API doesn’t appear to support sending SMS to multiple messages at one time. But you can add a Node.js code step to your workflow, link your Twilio account to that step, and write custom code to loop through your phone numbers, sending a message for each. I’d recommend taking a look at the Twilio docs for more information, but something like this should work:

const { phone } = require("phone");
const twilioClient = require("twilio");

const client = twilioClient(auths.twilio.Sid, auths.twilio.Secret, {
  accountSid: auths.twilio.AccountSid,
});

 // Enter all numbers in an array here
const numbers = ["+123...", "+456..."]

for (const num of numbers) {
  const toParsed = phone(num);
  if (!toParsed || !toParsed.phoneNumber) {
    throw new Error(`Phone number ${num} couldn't be parsed as a valid number.`);
  }

  const data = {
    to: toParsed.phoneNumber,
    from: <your from number here>,
    body: <your message here>,
  };

  await client.messages.create(data);
}
1 Like

I am not but will look into it. Thank you for your help!

1 Like

if i connect my Twilio account, do i need to add anything for the “from” section? I added the body path to the discord message content.

const data = {

to: toParsed.phoneNumber,

from: <+17865656499>,

body: <steps.trigger.event.content>,

};

I got it to work thank you!