Skip to contentSkip to navigationSkip to topbar
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, UNSUBSCRIBE, END, QUIT, STOPALL 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(link takes you to an external page) 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

create-a-messaging-service page anchor
(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 ServiceLink to code sample: Create a Messaging Service
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createService() {
11
const service = await client.messaging.v1.services.create({
12
friendlyName: "My First Messaging Service",
13
});
14
15
console.log(service.sid);
16
}
17
18
createService();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"date_created": "2015-07-30T20:12:31Z",
5
"date_updated": "2015-07-30T20:12:33Z",
6
"friendly_name": "My First Messaging Service",
7
"inbound_request_url": "https://www.example.com/",
8
"inbound_method": "POST",
9
"fallback_url": "https://www.example.com",
10
"fallback_method": "GET",
11
"status_callback": "https://www.example.com",
12
"sticky_sender": true,
13
"smart_encoding": false,
14
"mms_converter": true,
15
"fallback_to_long_code": true,
16
"scan_message_content": "inherit",
17
"area_code_geomatch": true,
18
"validity_period": 600,
19
"synchronous_validation": true,
20
"usecase": "marketing",
21
"us_app_to_person_registered": false,
22
"use_inbound_webhook_on_number": true,
23
"sending_windows": [],
24
"links": {
25
"phone_numbers": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers",
26
"short_codes": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ShortCodes",
27
"alpha_senders": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AlphaSenders",
28
"messages": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
29
"us_app_to_person": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p",
30
"us_app_to_person_usecases": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p/Usecases",
31
"channel_senders": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ChannelSenders"
32
},
33
"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

purchase-an-sms-capable-phone-number page anchor

Sending SMS messages requires an SMS capable phone number. You can search for and purchase available phone numbers(link takes you to an external page) 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

add-a-number-to-number-pool page anchor

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(link takes you to an external page).

find_phone_number_sid.

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

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createPhoneNumber() {
11
const phoneNumber = await client.messaging.v1
12
.services("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.phoneNumbers.create({
14
phoneNumberSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
15
});
16
17
console.log(phoneNumber.sid);
18
}
19
20
createPhoneNumber();

Output

1
{
2
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"date_created": "2015-07-30T20:12:31Z",
6
"date_updated": "2015-07-30T20:12:33Z",
7
"phone_number": "+987654321",
8
"country_code": "US",
9
"capabilities": [],
10
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
11
}

Add a WhatsApp-enabled number to your Messaging Service

add-a-whatsapp-enabled-number-to-your-messaging-service page anchor

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

enable-advanced-opt-out-for-your-messaging-service page anchor
(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(link takes you to an external page).

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

make-changes-before-enabling-advanced-opt-out page anchor

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

double-check-your-keywords-for-short-codes-and-advanced-opt-out page anchor

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

configuring-advanced-opt-out-keywords page anchor

There are three ways in which you can edit the keywords 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

edit-the-standard-opt-out-keywords page anchor

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

keywords-are-case-insensitive page anchor

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

editing-the-opt-out-keywords-and-confirmation-message page anchor

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

edit-the-opt-in-keywords-and-confirmation-message page anchor

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

edit-the-help-keywords-and-confirmation-message page anchor

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

special-behavior-for-toll-free-numbers page anchor

If your Messaging Service includes Toll-Free US numbers and you are sending to or receiving from the US or Canada, 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

add-language-specific-keywords-for-opt-out-opt-in-and-help-messages page anchor

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

supported-languages-for-opt-out-keywords page anchor

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

create-keywords-and-confirmation-messages-per-country-code page anchor

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

keeping-track-of-your-users-status page anchor

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.


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:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.