SMS/Providers

Twilio

Learn how to use the Twilio provider to send sms notifications using Novu

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

Create a Twilio Account
  1. Go to Twilio and create an account, starting with their free trial.
  2. You'll be asked to verify your email and your phone number. Get them verified.
Get a Twilio Phone Number
  1. Once verified, you'll get an option to 'get a Twilio phone number' from your Twilio console.
  2. 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 to begin using it. For first-time users, utilize the free number provided.

For more detailed instructions, follow one of their many Tutorials within their docs.

Understand the Key Components

Irrespective of the language you use, the process requires:

  1. Account SID and Auth token loaded into the code using secure environment variables

  2. A Twilio client object that takes the SID and Token as variables

  3. A message object containing:

    • Your Twilio phone number
    • The recipient's phone number
    • The SMS message body

Creating a Twilio integration with Novu

Connect Twilio to Novu
  1. Visit the Integrations Store on Novu
  2. Click the "Add a provider" button
  3. Locate Twilio and click on the Disabled button and mark it as Active
  4. Click on the Connect button
Configure Twilio Credentials
  1. Go to your Console on Twilio and access the Account Info section
  2. Enter your:
    • Account SID
    • Auth Token
    • Twilio Phone Number
  3. Click on the Save button

Sending WhatsApp messages with Twilio

To send WhatsApp messages with Twilio 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",
  },
});

On this page