In this tutorial, we will set up global opt-in and opt-out keywords and messages with Messaging Service’s Advanced Opt-Out feature. Configuring these keywords is an effective way to localize the experience for your customers 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 tutorial covers customizing opt-in/opt-out keywords and messages for a Messaging Service.
If you already have set up your Messaging Service, skip ahead to configuring Advanced Opt-Out keywords.
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.
When viewing the search results, you can see the which numbers are SMS capable.
With your shiny new Twilio phone number, you can start sending messages to mobile devices.
Now, associate your SMS-enabled Twilio number with the Messaging Service that you created. 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:
Configuring Advanced Opt-Out keywords
Now that you have your Messaging Service, locate Advanced Opt-Out in the Features Section. This is where you can configure your Advanced Opt-Out preferences:
Please note: Advanced Opt-Out currently does not support changing or reporting on blacklisted phone numbers via the Console or the REST API.
Global defaults apply to any country for which you have not specified an override, which the next section covers. Since you have not added any country overrides yet, all incoming messages are handled according to the global defaults.
When configuring Advanced Opt-Out, developers should make sure not to include any Personally Identifiable Information (PII) in the response messages to customers.
Some opt-out keywords are non-removable; however, if your use case requires more keywords than Twilio recognizes by default, you can add them here, separated by commas.
Twilio tries to match keywords in a case insensitive way. ‘Stop’ will be handled the same way as ‘STOP’ or ’stop’.
When receiving an opt-out keyword from one of your users, Twilio adds a blacklist entry containing their number.
Twilio checks this blacklist before sending any future outgoing messages. Any subsequent outgoing messages from your account to this user will fail with error code 21610 asynchronously.
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
- Only the keywords START and UNSTOP can fully undo this blacklisting. 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.
You can specify what keywords Twilio will interpret as opt-in keywords. When one of your users sends an opt-in keyword, Twilio removes the blacklist entry containing the user’s number (if it exists) and sends the message you defined to notify the customer that they have opted back in. Any subsequent outgoing messages to this user from your account will not be blocked.
With help keywords, you can let your users know 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 blacklist. However, if the user has opted out previously, they won't receive your defined help message in response.
You can set global defaults in more than one language. If a user texts in using one of your configured keywords, Advanced Opt-Out will match the keyword and return the message that you configured. For example, you can set English and Spanish defaults if you want to localize the user opt-in/opt-out keywords for your global Spanish-speaking users, rather than setting country-specific Spanish overrides for every Spanish-speaking country.
If you have users in a country where you would like to provide a localized experience, you can easily do that by creating a country override. Please note: a Country Override replaces the Global Defaults for a specific country. Be sure to add all keywords and responses that you wish to support for this country.
Note: When specifying Country Overrides, 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 blacklist 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.
Please 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 Override.
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 value is
HELP, depending on the incoming keyword.
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: