You can utilize the Twilio API to communicate with your customers using SMS messaging. Let’s look at how you can do that:

Setting up Twilio

  1. First, go to Twilio and create an account, probably starting with their free trial.
  2. You’ll be asked to verify your email and your phone number. Get them verified.
  3. Once you’re done with that, you’ll get an option to ‘get a Twilio phone number’ from your Twilio console.
  4. Click on it to get your Twilio phone number.

When first using Twilio there should be an option to get a Twilio phone number in the main console. Otherwise, you may have to Buy a number from that link to begin using it. Assuming this is the first run though, utilize the free number given to us.

Simply follow one of their many Tutorials within their docs to understand every part of the process.

Irrespective of the language you use, the process is the same:

  • Load the Account SID and Auth token into the code, using some sort of safe environment such as .env variables. Nobody should have access to this but you.
  • Create a client object from Twilio that take the SID and Token as variables then create a message with the client.
  • A message is an object that has three things:
    • that free number from earlier,
    • the number you would like to send to, and
    • a body message that you want to send through SMS.

Creating a Twilio integration with Novu

Creating a Twilio integration with Novu is quite simple. Just follow these steps:

  • Visit the Integrations Store on Novu.
  • Click the “Add a provider” button.
  • Locate Twilio and click on the Disabled button and mark it as Active.
  • Click on the Connect button.
  • Go to your Console on Twilio and access the Account Info section at the bottom of the page
  • Enter your Account SIDAuth Token and Twilio Phone Number.
  • Click on the Save button.
  • You should now be able to send SMS notifications using Twilio in Novu.

Sending an WhatsApp message with Twillio

To send a WhatsApps message with Twillio integration prefix the phone number of the subscriber with whatsapp: as shown below.

await novu.trigger("<WORKFLOW_TRIGGER_IDENTIFIER>", {
  to: {
    subscriberId: "<UNIQUE_SUBSCRIBER_IDENTIFIER>",
    phone: "whatsapp:555-4242",
  },
});

Read more about sending a Message with the Twilio API for WhatsApp.

Was this page helpful?