SMS

This section applies to Rebar only.

Introduction

The unit for sending SMS is based on the service provided by Twilio. It takes care of sending SMS and error handling.

Configuration

Settings

In /configuration/units/rb-sms/server/settings.js populate the SMSRecipientSubstitution setting with rules for replacement of an SMS recipient. This setting is useful in a development environment, where during testing one would like all SMS messages to be sent to only one phone number instead of the phone numbers of real users.

In the example below, for development environment (as specified by NODE_ENV), we would send all emails to (123) 456-7890:

export const SMSRecipientSubstitution = {
  'development': [
    { match: /[\s\S]*/, replacement: '+11234567890' }
  ]
}

Account setup

From the Twilio console https://www.twilio.com/console retrieve your account's SID and AUTH_TOKEN:

Twilio Console

In .env specify:

SMS_TWILIO_ACCOUNT_SID=abc
SMS_TWILIO_AUTH_TOKEN=xyz

using the values above.

In the SMS services section https://www.twilio.com/console/sms/services create a service:

Twilio SMS Service

Assign a number to it like shown below:

Twilio SMS Number

In .env specify:

SMS_TWILIO_PHONE_NUMBER=+1xxxyyyzzzz

using the value above.

Usage

In order to send an SMS use code like the following:

SMSSender.sendSMS(
  '+11234567890',                 // to
  'Reminder from Pacific Gadget', // body
)