Platform
Docs
Solutions
ContactLog In

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

sms notification system header
TUTORIAL

How to Create an Automated SMS Notification System

The Courier Team

August 17, 2023

When you need to send important alerts from your web or mobile app, text messages via SMS can be very useful, especially for time-sensitive notifications, e.g. to quickly warn users about things like possible fraud or payment issues. It can also be helpful to pair SMS notifications with other types of messages, such as email, Slack messages, or push notifications. This allows you to take a more layered approach to your notifications, adding notification logic that considers whether a user has read your earlier SMS attempts before deciding to notify them on these other channels.

While there are excellent SMS APIs like Twilio and MessageBird that let you send an SMS with a few lines of code, these services don't handle all the complexities of an automated SMS that will require an SMS notification system like Courier.

You will need to add extra logic around your notifications if you want to:

  • Send the message to additional channels like a push notification or in-app message.
  • Trigger your notifications based on a schedule, a product event or collection of events.
  • Integrate notifications with your Customer Data Platform or Reverse ETL.
  • Send a sequence of notifications based on certain conditions
  • Accommodate user communication preferences (which channels they want to be notified by, and how often)
  • Include data from third party systems in your notifications
  • Implement automatic failover between SMS providers, if one goes down. Or between channels if the SMS isn’t read.

Without an SMS notification system to help you manage this work, you’ll be left developing and maintaining all this logic yourself.

This article shows how to use the Courier SMS notification system to easily send basic SMS notifications, as well as how to add automation logic around your notifications and read user preferences to avoid bombarding them with an excess of messages.

Components of an SMS notification system

SMS notification systems provide a powerful set of features that extend far beyond SMS delivery. Here are some of the capabilities supported by Courier, which may be useful if you’re building a product requirements document (or developing against one) for product notifications.

  • Multiple channels: Offers a wide range of notification channels, such as email, push, Slack, MS Teams and an in-app notification inbox.
  • User preferences: Your users can decide how often and by which channels (e.g. SMS, email, Slack etc.) they wish to be communicated with, and Courier will automatically honor these preferences.
  • Integration with other software: Has deep integrations with adjacent systems in your stack (like Customer Data Platforms, for example).
  • Delivery tracking and retry mechanisms: Ensures reliable message delivery.
  • Monitoring and logging: Provide comprehensive monitoring and logging for debugging delivery issues, in a way that looks at SMS in the context of other channels.
  • Delivery options: Gives you the flexibility to trigger messages in a way that aligns with your use case: including api-driven, event-driven, or one-time send.
  • Cross channel synching: Sync delivery status across channels, so when a user opens an email, the related inbox message can automatically be marked as read.
  • Channel/provider failover: Easily failover between SMS providers (e.g. from Twilio to MessageBird) or between channels (e.g. from SMS to Email or Slack) if a notification has failed.
  • Testing capabilities: Provides easy ways for you to test that your notifications have been sent properly.
  • Integration with your coding language: Offers SDKs for most languages. It’s easy to integrate Courier with both front-end and back-end code for web, as well as mobile application code for Android and iOS.
  • Scalability: Can handle increased message volume as your application grows.
  • Advanced send logic: Features such as throttling and send limits to prevent overrun of messages that have both cost and user experience implications.
  • Internationalization: Allows you to automatically select different message templates and timing restrictions for different regions.
  • Template design and management
    • can you design and manage templates for all your notifications in one place?

Send with SMS using an SMS notification system

In this example, we will use Courier, with Twilio as the SMS provider. We’ll build automated SMS notifications into a Node.js application. Although we are using Node.js, there are a number of quick start guides for other languages available.

Step 1: Set up Twilio

Twilio offers a free trial with no credit card required, so we will use Twilio as our example SMS service provider. Start by signing up to Twilio. Once you have signed up, you will be directed to the Twilio console, where there is a basic tutorial for creating a new phone number for your Twilio messages. Once you have done this, continue with the tutorial and run the command to send yourself a test SMS, just to check that Twilio is working correctly.

Next, scroll down the Twilio console homepage to find your Twilio account SID, auth token, and phone number — which you will need to use Twilio with Courier.

Screenshot of the Twilio SMS notification system showing how to find the account SID, auth token, and phone number.

Step 2: Integrate Twilio with Courier using the web UI

Sign up to Courier and add Twilio as a channel, by selecting Twilio under configured providers. Now, enter your Twilio account SID, auth token, and phone number that you previously found in the Twilio console, and click the Save button.

Screenshot showing how to input the Twilio details into Courier.

Step 3: Create your SMS notification template

We will be using an e-commerce package delivery notification for our example. Navigate to Designer → Create Template and name your template “Package delivery.” You will now be prompted to say which channel you want to use for sending your message. Select SMS and select Twilio as your SMS provider in the drop-down box.

Next, click on SMS under Channels to begin writing your notification for the SMS channel. Either use the AI-powered content generator or enter this text into the notification designer:

“Your package with reference {packageRef} is estimated for delivery between {startTimeHours}: {startTimeMins} and {endTimeHours}:{endTimeMins} today. Not going to be in? {rescheduleOrSafePlaceUrl}” and then click “Publish changes”.

How to create an SMS notification template in Courier.

Step 4: Install the Courier Node.js SDK

Step 5: Send SMS using Node.js

Now you are going to write some code that will send an SMS notification to your phone from your Node.js code, using Courier (with Twilio as the SMS provider).

Inside your package-notification directory, create a file called package.js and add the following code:

1
const { CourierClient } = require("@trycourier/courier");
2
const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });
3
4
const packageRef = "<PACKAGE_REFERENCE>";
5
const startTimeHours = "<START_TIME_HOURS>";
6
const startTimeMins = "<START_TIME_MINS>";
7
const endTimeHours = "<END_TIME_HOURS>";
8
const endTimeMins = "<END_TIME_MINS>";
9
const rescheduleOrSafePlaceUrl = "<RESCHEDULE_OR_SAFE_PLACE_URL>";
10
11
const { requestId } = courier.send({
12
message: {
13
to: {
14
data: {
15
packageRef : packageRef,
16
startTimeHours : startTimeHours,
17
startTimeMins : startTimeMins,
18
endTimeHours : endTimeHours,
19
endTimeMins : endTimeMins,
20
rescheduleOrSafePlaceUrl : rescheduleOrSafePlaceUrl
21
},
22
phone_number: "<PHONE_NUMBER>",
23
},
24
template: "<NOTIFICATION_TEMPLATE_ID>",
25
routing: {
26
method: "single",
27
channels: ["sms"],
28
},
29
},
30
});
  • Replace all the template variables like packageRef with your own values. Note: the time-based variables such as startTimeHours should each contain two digits, as they use military time.
  • Replace <AUTH_TOKEN> with your  Courier API key.
  • Replace <PHONE_NUMBER> with your own phone number, so you can test that the SMS sends correctly.
  • Replace <NOTIFICATION_TEMPLATE_ID> with the ID of the template you just created. This can be found by going to your template in the Courier app and navigating to the notification settings:

Using Node.js code to send an SMS notification in Courier.

When you run your code, it will send an SMS:

An example SMS about an expected package delivery.

As you can see, it’s pretty simple to send an SMS using Courier. It's worth noting that Courier offers multiple notification channels — so you can use the same notification platform for communicating via email, Slack, MS Teams, push notifications, and more. For example, the user may have wanted this parcel notification as both a mobile push notification and an SMS.

Using Courier automations to simplify complex SMS logic

Courier automations allows you to abstract complex SMS (or multi-channel) notification workflows into a no-code designer in the Courier web UI, which can then be invoked via Courier’s Automations API. Workflows are easily created as templates via drag-and-drop components. These templates contain all the logic needed for a notification sequence. It consists of a trigger and a number of actions. Once you’ve created the template, you can later run an automation from it.

Some examples of automation templates that can be created in the automation designer include:

  • Send an SMS on a time-based schedule — for example, send an SMS 10 days before Black Friday to notify customers of an impending sale.
  • Send an SMS that is triggered by an event in your customer data platform (Courier accepts Segment and RudderStack events as triggers, meaning you don’t need to integrate their APIs into your code).
  • Branching logic: sending one SMS if one condition is met, and a different one if it’s not — for example, if a new user signs up to a gym, they could be sent different workout suggestions based on age.
  • Applying throttles to your SMS messages to avoid notification fatigue — if an automation template involves sending multiple notifications, a throttle can be added to place a limit on the number of SMS messages that can be sent.

In this tutorial, we will create an automation template that causes an order confirmation SMS to be sent when an “order completed” event occurs in Segment, the Customer Data Platform from Twilio. We will use Courier’s Segment integration to achieve this.

Step 1: Create a notification template in Courier

Navigate to Designer and click Create Template. Name your template “Order confirmation.”  Select SMS as the notification channel and choose Twilio as a provider from the drop-down box.

Now, click the SMS channel on the left to add your message content to your template. Add the following text to the notification designer, then click Publish changes.

“Your recent order of {productName} (#{orderNumber}) has been completed. We hope you enjoyed your purchase and thank you for shopping with us.”

Step 2: Create your automation in Courier

Navigate to the automations designer and click New Automation. Rename your automation from “Untitled Automation” to “Order Confirmation.”

Creating an automation in Courier.

Start with a trigger for your automation. For this example, we will choose a Segment event as the trigger. Drag the Segment trigger onto the automation designer canvas. You will need to select a particular Segment event within this. In this example, we will use an e-commerce Segment event called “order completed.”

Next, add a Send action to your automation and fill in the following information in this node:

  • “To” field: Enter refs.data.user_id as the user.
  • Select a template: Choose your Order confirmation template from the drop-down box.

Adding a Send action to the automation in Courier.

To use Segment dynamic data in the variables of your notification template, click on Advanced in the Send node, and enter the following in the data field:

{ "productName": "data.products.name" ---

Adding Segment dynamic data to the automation in Courier.

Finally, click Publish changes.

When an order gets marked as completed in Segment, this will invoke the automation, and cause your SMS to be sent. You can also test your automation template by invoking it yourself: click the Invoke button at the top of your automation template to find a cURL command that you can run to check your automation is working properly.

Conclusion

We have covered why you need an SMS notification system and how to automatically trigger an SMS using Courier with Twilio.

You can get started immediately using Courier’s free tier and Twilio’s free trial. Courier allows you to integrate with many of the big SMS notification providers, which means that you don’t have to decide right away which provider to use. If you’ve been working along with this coding example and have decided you want to use Courier to send more notifications, you can sign up today or contact us to discuss your specific use case.

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

More from Tutorial

How to set up automatic push notifications based on Segment events thumbnail
TUTORIAL

How to Set Up Automatic Push Notifications Based on Segment Events

Push notifications have carved their own niche as a powerful tool for continuous user engagement. Regardless of whether an app is actively in use, they deliver your messages straight to your user's device. Two key players that can combine to enhance your push notification strategy are Segment and Courier. In this tutorial, we show you how to set up Courier to listen to your Segment events and then send push notifications to an Android device based on data from these events.

Sarah Barber

Sarah Barber

November 17, 2023

image14
TUTORIAL

How to Send Firebase Notifications to iOS Devices Using Courier

This tutorial explains how to send push notifications to iOS devices from your iOS application code using Firebase FCM and Courier’s iOS SDK.

Martina Caccamo

Martina Caccamo

November 01, 2023

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.