Your First SMS Campaign in Less than 5 Minutes

Developer setting up SMS campaign on his computer
September 20, 2022
Reviewed by
Paul Kamp
Twilion

Twilio is a unique platform offering flexible APIs to communicate on different channels, including SMS, using our Programmable SMS product. Generally, using our APIs requires programming.

Your CRM or internal tools are not necessarily natively connected with Twilio. In this article, we will show you how to deploy and use a turnkey application to send your first SMS campaigns from data (numbers and variable fields) contained in a CSV file, all without writing a line of code.

This application will be deployed on the Twilio Runtime platform, a serverless platform that makes it so you don't have to worry about hosting infrastructure.

Solution: CSV to SMS Campaigns

Below is a screenshot of the application we are going to use and the result for one of the recipients.

CSV to SMS app

This article describes how to set up and use the CSV to SMS application. Below is a video that explains how it works and shows the setup steps (from 6:00).

Prerequisites

To follow this tutorial, you will need the following items:

Deployment of the Twilio Function

Twilio can host dynamic code as Functions as well as static resources represented as Assets.

The code of the application is available on GitHub and can be directly cloned and hosted on Twilio by following the steps below:

  1. Download or clone source code from the GitHub repository by typing the following in your command prompt:
    git clone https://github.com/evanTheTerribleWarrior/Twilio-Outbound-Messaging
  2. In your prompt, move to the folder containing the code:
    cd Twilio-Outbound-Messaging
  3. Create a .env file and using a text editor set the USERNAME, PASSWORD, JWT_SECRET. Ensure they are not easy to guess:
    cp .env.example .env
  4. Then using Twilio CLI deploy the code to your Twilio account:
    twilio serverless:deploy --production --service-name=msg

This last command will build on the configuration for the function, and deploy it on the Twilio platform.

As a result, your account credentials will automatically be taken into account (Account SID and Auth Token).

You can access the app from the URL of the index.html resource.

index.html ressource

From your Twilio console, you can also find the application's code and its URL by navigating to Functions then Services.

Twilio Console - Services

Using the app

The use of the CSV file format allows you to start your SMS campaigns very quickly, indeed many tools allow the export of data in this format.

Here is an example of a file in CSV format:

Number,Name,Age,City
+33612345678,Raphael,26,Paris
+33789012345,Sacha,28,Nantes
+447911123416,Jerome,24,London

The telephone numbers must be written in E164 format, while the other columns will be interpreted as variables that can be used in the body of the message.

Before you get started, you'll have to authenticate using the credentials you define in the .env file at deployment stage.

Then, once logged in (and when a file is selected), the number of numbers and variables taken into account is displayed:

Data loaded

You'll have to pick the column of your CSV file containing the phone numbers from the list .

Phone number selection

In the Sender field, you can type the phone number, short code, or alpha-sender ID associated with your Twilio account you want to use for this campaign.

In multiple countries and regions, using an alpha-sender ID is appropriate for marketing campaigns. This might require a preregistration of the sender name. Please refer to the best practices for your area.

You can then enter the message that will be delivered to your various recipients, while including variables from your CSV file.

Be careful with the length of your SMS especially with the use of special characters, as this can result in the sending and billing of several message segments. See What is GSM7 encoding for more, and the Message Segment Calculator to calculate the length of your messages.

The application also displays a table allowing you to visualize the source file. A simple click on the name of one of the variables will add it to the body of the message.

User data table

Sending form

Once the body of the message is ready, you can use the Check Numbers button to validate that the numbers coming from your file are properly formatted. Errors will be displayed on the User Data section on the right panel, and you'll be able to remove rows causing errors.

When the data is clean and all numbers pass validation, you can hit the Send Message button to deliver the messages through Twilio services.

We describe in a section below how to monitor and ensure messages have been properly delivered.

WhatsApp campaigns

The application not only supports SMS, but brings in another channel offered by Twilio : WhatsApp. This is enabled via checking the WhatsApp button under the Channel Type section.

While the behavior of the services and API are very similar, WhatsApp doesn't work in the same manner as SMS for initial messages. Outbound messages initiating a new conversations can't be free form with WhatsApp, they need to match predefined and approved templates (to align with Meta's rules for messaging).

To submit, review, and manage your templates you should go to your Twilio console and follow these steps: Creating message templates and submitting them for approval

One of the main advantages for WhatsApp is the ability to fetch read receipts for your messages. It also adds more formatting and dynamic content options.

Advanced Options

In the following sections, we will describe several advanced options available in the app.

Check carrier type

This feature relies on Twilio Lookup services to check a phone number carrier and type, which helps avoid you sending messages to landline or VoIP numbers.

Please note Line type Intelligence has its own pricing.

Media/MMS

As the name suggests, this feature lets you add media content to your campaign.

Note that in some regions Twilio doesn't support MMS sending and images will be replaced by a URL.

Opt-out Management

Authorities often require you manage user consent for SMS campaigns. That includes collecting consent before sending messages, but also including the option to opt-out.

Most companies will manage that through other systems, for instance a customer portal where customers can decide which kind of messages they'd like to receive via mail or SMS.

Enabling the Add Twilio Opt Out URL option will let the application handle this part, by including a specific STOP URL at the end of your message, with a link for users to unsubscribe.

Opt out URL example

This list is stored on the Twilio Sync service, and will prevent numbers receiving additional messages coming from your campaigns. When using the Check Number features, opted-out numbers will be highlighted and will be ignored at the sending stage.

Messaging services

Messaging Services are designed to help you scale your application’s messaging from your first SMS to messages sent globally, in multiple languages, from more than just one phone number. This is helpful to ensure high deliverability for your largest global campaigns.

Once the messaging services have been created and configured from your Twilio Console, the application will let you select them straight away, replacing the sender field and automatically picking the best senders for each number, based on your Messaging Service.

Messaging service selection

Delivery Analysis

For every message that is sent, Twilio is capable of retrieving its status, if it was sent, queued, delivered, or maybe failed.

All this information is available to you in the Graph tab of the application, where in a glance you can notice how your campaign has been delivered.

As this status can change overtime, you can refresh the data by clicking the Get Status button at the top of the data table. You can also view indicators next to each row to see its status.

Graph and message status

Conclusion

Congratulations, you have sent your first SMS campaign with Twilio, all hosted in the cloud with our serverless solution! We can't wait to see how you use the service.

To go further:

  • Browse our documentation and see how Twilio can be integrated into your existing applications.

Raphaël and Evangelos are Solution Engineers at Twilio. They help companies develop and optimize their customer engagement experiences with Twilio products.