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.
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:
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.
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.
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.
Use the Phone Number's SID to attach to the Messaging Service that you created:
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.
Please note: Advanced Opt-Out currently does not support changing or reporting on blocked phone numbers via the Console or the REST API.
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.
To turn on Advanced Opt-Out for your Messaging Service, click the Enable Advanced Opt-Out button.
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.
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.
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.
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
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.
Twilio tries to match keywords in a case insensitive way. "Stop" will be handled the same way as "STOP" or "stop".
When configuring Advanced Opt-Out, developers should make sure not to include any Personally Identifiable Information (PII) in the response messages to customers.
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.
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.
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.
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.
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.
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.
Twilio supports the following spoken languages in opt-out keywords and responses:
- Southern Ndelebe
- Southern Sotho
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.
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.
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.
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
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: