Most Popular
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
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:
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.
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.
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.
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.
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.
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”.
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:
1const { CourierClient } = require("@trycourier/courier");2const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });34const packageRef = "<PACKAGE_REFERENCE>";5const startTimeHours = "<START_TIME_HOURS>";6const startTimeMins = "<START_TIME_MINS>";7const endTimeHours = "<END_TIME_HOURS>";8const endTimeMins = "<END_TIME_MINS>";9const rescheduleOrSafePlaceUrl = "<RESCHEDULE_OR_SAFE_PLACE_URL>";1011const { requestId } = courier.send({12message: {13to: {14data: {15packageRef : packageRef,16startTimeHours : startTimeHours,17startTimeMins : startTimeMins,18endTimeHours : endTimeHours,19endTimeMins : endTimeMins,20rescheduleOrSafePlaceUrl : rescheduleOrSafePlaceUrl21},22phone_number: "<PHONE_NUMBER>",23},24template: "<NOTIFICATION_TEMPLATE_ID>",25routing: {26method: "single",27channels: ["sms"],28},29},30});
packageRef
with your own values. Note: the time-based variables such as startTimeHours
should each contain two digits, as they use military time.<AUTH_TOKEN>
with your Courier API key.<PHONE_NUMBER>
with your own phone number, so you can test that the SMS sends correctly.<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:When you run your code, it will send an SMS:
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.
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:
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.
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.”
Navigate to the automations designer and click New Automation. Rename your automation from “Untitled Automation” to “Order Confirmation.”
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:
refs.data.user_id
as the user.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"
---
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.
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.
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
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
November 17, 2023
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
November 01, 2023
Free Tools
Comparison Guides
Send up to 10,000 notifications every month, for free.
Get started for free
Send up to 10,000 notifications every month, for free.
Get started for free
© 2024 Courier. All rights reserved.