Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Customizing Users’ Opt-in and Opt-out Experience with Advanced Opt-Out


In this tutorial, we will set up opt-in, opt-out, and help keywords and confirmation messages with the Advanced Opt-Out feature of Messaging Services. Configuring these keywords is an effective way to localize the experience for your customers and end users all over the world.

Twilio, by default, handles standard English-language reply messages such as STOP, UNSTOP, UNSUBSCRIBE or CANCEL for Toll-Free and Long Code numbers, in accordance with industry standards. (Please consult our support documentation on Twilio's support for opt-out keywords for more.)

This guide covers customizing opt-in/opt-out keywords and messages for your Messaging Service using the Advanced Opt-Out feature.


Create a Messaging Service

(information)

Info

If you already have set up your Messaging Service, skip ahead to enabling Advanced Opt-Out for your Messaging Service.

Global opt-in and opt-out keywords are a feature of Twilio Messaging Services. A Messaging Service is a higher-level "bundling" of messaging functionality around a common set of senders, features, and configuration.

If you haven't already done so, create a new Messaging Service:

Create a Messaging Service

Create a Messaging Service and give it a name

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function createService() {
_18
const service = await client.messaging.v1.services.create({
_18
friendlyName: "My First Messaging Service",
_18
});
_18
_18
console.log(service.sid);
_18
}
_18
_18
createService();

Output

_34
{
_34
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"date_created": "2015-07-30T20:12:31Z",
_34
"date_updated": "2015-07-30T20:12:33Z",
_34
"friendly_name": "My First Messaging Service",
_34
"inbound_request_url": "https://www.example.com/",
_34
"inbound_method": "POST",
_34
"fallback_url": "https://www.example.com",
_34
"fallback_method": "GET",
_34
"status_callback": "https://www.example.com",
_34
"sticky_sender": true,
_34
"smart_encoding": false,
_34
"mms_converter": true,
_34
"fallback_to_long_code": true,
_34
"scan_message_content": "inherit",
_34
"area_code_geomatch": true,
_34
"validity_period": 600,
_34
"synchronous_validation": true,
_34
"usecase": "marketing",
_34
"us_app_to_person_registered": false,
_34
"use_inbound_webhook_on_number": true,
_34
"sending_windows": [],
_34
"links": {
_34
"phone_numbers": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers",
_34
"short_codes": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes",
_34
"alpha_senders": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AlphaSenders",
_34
"messages": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
_34
"us_app_to_person": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p",
_34
"us_app_to_person_usecases": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p/Usecases",
_34
"channel_senders": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ChannelSenders"
_34
},
_34
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_34
}

Copy down the Messaging Service SID (It starts with MGXXX). You'll need it in the next step when you associate a phone number with this Service.


Purchase an SMS capable phone number

Sending SMS messages requires an SMS capable phone number. You can search for and purchase available phone numbers in the Console. When you search, make sure that the number you choose is SMS capable. Check the appropriate box in the search UI to filter available numbers to those that are SMS capable.

Search for SMS Capable Number.

When viewing the search results, you can see the which numbers are SMS capable.

Buy SMS Capable Number.

With your shiny new Twilio phone number, you can start sending messages to mobile devices.

Add a number to number pool

Now, associate your SMS-enabled Twilio number with the Messaging Service that you created.

You can do this in the Twilio Console in the Senders section under your Messaging Service. Click the Add Sender IDs button, select the Sender Type, and assign the senders to your Messaging Service. (Please see below for instructions for adding WhatsApp-enabled numbers to your Sender Pool.)

You can also use the Messaging Services REST API to add the Phone Number you purchased to your sender pool. To do this, you will need the Phone Number's unique SID, which starts with PNXXX. You can find this in the Phone Numbers Section of the Twilio Console.

find_phone_number_sid.

Use the Phone Number's SID to attach to the Messaging Service that you created:

Add Number to Numbers Pool

Associate a Phone Number with your Messaging Service

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createPhoneNumber() {
_20
const phoneNumber = await client.messaging.v1
_20
.services("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_20
.phoneNumbers.create({
_20
phoneNumberSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_20
});
_20
_20
console.log(phoneNumber.sid);
_20
}
_20
_20
createPhoneNumber();

Output

_11
{
_11
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"date_created": "2015-07-30T20:12:31Z",
_11
"date_updated": "2015-07-30T20:12:33Z",
_11
"phone_number": "+987654321",
_11
"country_code": "US",
_11
"capabilities": [],
_11
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_11
}

Add a WhatsApp-enabled number to your Messaging Service

The Advanced Opt-Out feature of Messaging Service also works with WhatsApp-enabled senders (phone numbers). To add a WhatsApp-enabled number to your Messaging Service Sender Pool, go to the Twilio Console under Messaging > Services and select the Messaging Service that you want to edit. From there, click the Add Senders button to add your WhatsApp-enabled phone number to the Messaging Service.

Add WhatsApp-enabled Sender to Messaging Service.
(warning)

Warning

Please note: Advanced Opt-Out currently does not support changing or reporting on blocked phone numbers via the Console or the REST API.


Enable Advanced Opt-Out for your Messaging Service

(error)

Danger

Advanced Opt-Out is disabled by default for your Messaging Service. Once you enable Advanced Opt-Out, the only way to disable it is to contact our support team.

Now that you have your Messaging Service, locate the Opt-Out Management section for your Messaging Service. This is where you can enable and configure your Advanced Opt-Out preferences.

Enable Opt out management.

To turn on Advanced Opt-Out for your Messaging Service, click the Enable Advanced Opt-Out button.

Make changes before enabling Advanced Opt-Out

To remain compliant and provide your customers with the best possible experience, make sure that you have correctly configured Advanced Opt-Out prior to enabling it.

Before enabling Advanced Opt-Out for your Messaging Service, you can change the configuration, such as the keywords and responses, and save your changes. These changes do not take effect on your Messaging Service until you enable Advanced Opt-Out. However, the changes that you make to keywords and responses are saved and reflected in the console.

Be aware that as soon as you enable Advanced Opt-Out for your Messaging Service, the configuration applies to all of the senders (long codes, short codes, and toll-free numbers) in your Sender Pool.

Double-check your keywords for Short Codes and Advanced Opt-Out

If you have short codes in your Messaging Service's Sender Pool, it is a good idea to confirm that the keywords (opt-out, opt-in, and help) listed in the Advanced Opt-Out configuration exactly match the stop-words that you included in your application for the short code. In order to remain compliant per the requirements of your short code application, make sure that you are addressing the keywords the customers will use to opt in and out of your Messages.

(warning)

Warning

Once you enable Advanced Opt-out, the changes apply to all of the senders in your sender pool, including your short codes. Your keywords and responses in Advanced Opt-Out will take precedence over the settings for your Short Code, which is a potential compliance risk.

We highly recommend verifying that the configuration in Advanced Opt-Out matches any keyword and confirmation message pairings that you may have previously set up in your application or that you specified when obtaining a short code.


Configuring Advanced Opt-Out keywords

There are three ways in which you can edit the keywords for for your Messaging Service:

  • Edit the Standard Opt-Out keywords
  • Add language-specific Opt-Out keywords
  • Add Country Code Opt-Out keywords

Edit the Standard Opt-Out keywords

Standard Opt-Out keywords apply to Messages in any country where you have not specified keyword and confirmation message pairs, which the next section covers. Since we have not added any country overrides yet, Advanced Opt-Out for your new Messaging Service currently handles all messages based on the Standard Keywords by default.

To change the Standard Opt-Out keywords, click the Edit text to the right of the section header. This opens up an editing interface where you can add, change, and remove the keywords and confirmation message for opt-out, opt-in, and help interactions.

Edit Opt Out.

Keywords are case-insensitive

Twilio tries to match keywords in a case insensitive way. "Stop" will be handled the same way as "STOP" or "stop".

(warning)

Warning

When configuring Advanced Opt-Out, developers should make sure not to include any Personally Identifiable Information (PII) in the response messages to customers.

Editing the Opt-out keywords and confirmation message

When Twilio receives an Opt-out keyword from one of your users, it adds this phone number to a list of blocked numbers. Twilio checks this list before sending any future outgoing messages. Any subsequent outgoing messages from your account to this user will fail with Error Code 21610 asynchronously.

The reserved Opt-out keyword "stop" is non-removable. If your use case requires more keywords than Twilio recognizes by default, you can add them in the textbox, separated by commas.

Edit the Opt-in keywords and confirmation message

You can specify which keywords Twilio will interpret as Opt-in keywords. When one of your users sends an Opt-in keyword, Twilio removes the blocked number entry containing the user's number (if it exists) and sends the confirmation message that you define. This confirmation message notifies the customer that they have opted back in. Any subsequent outgoing messages to this user from your account will not be blocked.

Please note: "start" and "unstop" are reserved Opt-In keywords and non-removable.

Edit the Help keywords and confirmation message

With help keywords, you can give your end users more information as to who owns a particular number as well as what actions are available. When Twilio receives a help keyword from one of your users, there is no impact on the block list. However, if the user has opted out previously, they won't receive your defined help message in response.

Keep in mind that the keyword "help" is reserved and cannot be removed.

Special behavior for Toll-Free numbers

If your Messaging Service includes Toll-Free US numbers, please be aware of the following special behavior:

  • Toll-Free US numbers always unsubscribe a user who replies STOP, so the Advanced Opt-out custom message will not display.
  • Toll-Free US numbers always opt-in a user who replies START, UNSTOP, so both the carrier opt-in message and the Advanced Opt-out custom message will be returned.
  • Only the keywords START and UNSTOP can fully undo the blocking. Twilio's supported keyword "YES" will not work to opt-in a previously unsubscribed user.

If using a Toll-Free US number to communicate with your users, make sure to communicate the STOP and START/UNSTOP keywords to them.


Add Language-specific keywords for Opt-out, Opt-in, and Help messages

If you are communicating with customers in more than one language, you can specify pairs of keywords and confirmation messages in the target languages of your end users. When an end user sends a Message using one of your configured keywords, Advanced Opt-Out matches the keyword and returns the confirmation message that you specified.

For example, let's say that you plan to send Messages internationally to both English-speaking and Spanish-speaking users. You can create keyword and confirmation message pairs under the Language-specific Opt-Out Keywords section for Spanish, rather than setting country-specific Spanish keywords for each Spanish-speaking country in which you plan to send Messages.

Edit Advanced opt out.

Click on Add Opt-Out Keywords under Language Specific Opt-Out Keywords to create language-specific pairings for Opt-out, Opt-in, and Help messages.

Supported Languages for Opt-Out Keywords

Twilio supports the following spoken languages in opt-out keywords and responses:

  • Afrikaans
  • Arabic
  • Bengali
  • Chinese
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • Estonian
  • Finnish
  • French
  • German
  • Greek
  • Hebrew
  • Hindi
  • Hungarian
  • Italian
  • Japanese
  • Korean
  • Latvian
  • Lithuanian
  • Malay
  • Malaysian
  • Norwegian
  • Polish
  • Portuguese
  • Russian
  • Slovak
  • Slovene
  • Spanish
  • Southern Ndelebe
  • Southern Sotho
  • Swati
  • Swedish
  • Tamil
  • Tswana
  • Tsonga
  • Venda
  • Xhosa
  • Zulu

Create keywords and confirmation messages per country code

If you correspond with users in a country where you would like to provide a localized experience, you can do that by creating a country code pairing for keywords and confirmation messages.

Please note: a Country Override replaces the Standard Keywords in the specified country. Be sure to add all keywords and confirmation responses that you wish to support for this country. Twilio first checks the list of keywords for the specified country. If it finds a match with a country-specific keyword, it will return the matching confirmation message. If not, it will check the list of Standard Opt-Out keywords.

You can add these keywords in the Country Code Opt-Out Keywords section under Advanced Opt-Out Management.

Edit country code opt out.

When specifying Country Code keywords, you must select at least one language to add keywords. If you wish to localize the behavior further, you can add another language.

When receiving an incoming message from one of your users, Twilio matches the country code of your user's phone number with the configuration that you specified. It then attempts to match one of the keywords listed in the pre-defined languages. If there is a match, Twilio applies any necessary opt-out action then replies with the message in the language of your user's keyword.

Therefore, all keywords in a country, across all languages, need to be unique.

Note: It is up to the developer to handle localization of keywords for Country Overrides. Twilio does not perform translation; it will only handle the literal keywords as specified in the Country Code Keywords.

(warning)

Warning

Be aware: the same keyword cannot be entered in two different languages for the same country. If a word is entered in one language, the same keyword won't be accepted in another language.


Keeping track of your users' status

With Advanced Opt-Out, you can keep track of the most up-to-date information about your users' opt-in and opt-out preferences. When an incoming message triggers one of your Opt-Out keywords, Twilio includes an OptOutType property in the request object sent to the webhook URL configured for your Messaging Service. The corresponding value is START, STOP, or HELP, depending on the incoming keyword.

If you see the OptOutType property in Twilio's request to your application, that indicates that Advanced Opt-Out has already matched one of your keywords and replied with the corresponding confirmation message. You may want to store this information, but because Twilio has already sent a confirmation message/reply to your end user, we do not recommend sending another Message back from your application to the end user. In the case of Opt-out keywords, for example, Twilio will not send any further Messages to the end user, failing with Error Code 21610.


What's Next?

You've now successfully added global keywords to your Messaging Service by configuring the Advanced Opt-Out feature.

Check out these other Messaging Service Resources to improve your users' experience:


Rate this page: