Creating an SMS Notification

Last edit: Aug 16, 2019
  • Contributors:
  • pavelloz
  • Slashek

This guide will help you create an SMS Notification to send a text message to a newly signed up user using our Twilio integration.

Requirements

To follow the steps in this tutorial, you should understand the concept of notifications. You'll also use the sign-up form you created in a previous tutorial. As you'll use our Twilio integration, you need to ensure that the to number is formatted according to Twilio's phone number format guideline.

Steps

Creating an SMS Notification is a three-step process:

Step 1: Extend sign up form with mobile number

As you haven't collected the mobile phone number in the sign-up form yet, as a first step, extend the sign-up form forms/developer/sign_up.liquid:

---
fields:
  mobile_number:
    validation:
      presence: true
      phone_number: true
---

<label for="mobile_number">Mobile number</label>

<input name="{{ form.fields.mobile_number.name }}"
  value="{{ form.fields.mobile_number.value }}"
  id="mobile_number"
  type="text">

{% if form.errors.mobile_number %}
  <p>{{ form.errors.mobile_number }}</p>
{% endif %}

On the production site, you have to take into consideration that users might not know their country code, or what a country code is. For simplicity in this example though, assume that the user provides correct input.

Step 2: Create SMS Notification

Create a notification file in notifications/sms_notifications/welcome_user.liquid:


---
name: welcome_user
to: '{{ form.mobile_number }}'
delay: 0
enabled: true
trigger_condition: true
---
Hello {{ form.first_name }} via sms.

Step 3: Add SMS Notification to sign up form

Add the SMS Notification you created to the sign-up form:

---
sms_notifications:
  - welcome_user
---

Important

We do not send real text messages on staging by default. Because any error with sending real text messages on staging might be more costly than sending emails. If you want to test SMS on staging, please change enable_sms_and_api_workflow_alerts_on_staging flag to true in your Partner Portal instance configuration.

Next steps

Congratulations! You have created an SMS Notification. Now you can learn about creating an API Call Notification.

Questions?

We are always happy to help with any questions you may have.