Twilio's Messaging Services is a free feature that simplifies sending messages at scale and across multiple countries by using a container for various Twilio message senders, such as phone numbers and WhatsApp senders. It enhances message sending with features like automatic number selection. The service supports A2P 10DLC in the U.S. without requiring code changes. To use the service, you create a Messaging Service, set up inbound message handling, add senders, and pass the Messaging Service SID in API requests. This allows Twilio to automatically select the best sender from your pool, although specific senders can be manually chosen if desired.
Overview
Messaging Services is a free Twilio feature designed to make it easier to send messages at-scale, as well as across multiple countries. In short, a Messaging Service is a container for multiple Twilio message senders (e.g. phone numbers, WhatsApp senders). It offers you additional message sending intelligence and content features, such as automatic number selection, when you pass your Messaging Service information in your API requests instead of a specific From
number.
By setting up one or more Messaging Service for your use cases, you ensure that you can grow your messaging use case with Twilio more easily.
Messaging Services also provide access to A2P 10DLC in the United States, although you are not required to make any code changes to the way you send messages. If you are currently setting up one or more Messaging Services in preparation for A2P 10DLC, you just need to complete Steps 1 through 3 below.
To learn more about what Messaging Services offers, see our Messaging Services documentation.
Procedure
Step 1: Create a Messaging Service
In Console, visit the Messaging Services page and click the button to create a Messaging Service, then follow the prompts.
You can also create a Messaging Service via the Messaging Services API.
Step 2: Set up inbound message handling (if desired)
When an incoming message arrives at one of your Twilio numbers in a Messaging Service, the Service can either refer to your phone number for how to handle inbound messages, or it can have their own incoming message handling setting that is shared across all numbers in the Messaging Service.
By default, Twilio will set your Messaging Service to "Defer to sender's webhook," meaning inbound messages will hit whatever inbound message handler is configured on your individual phone numbers.
If you want to set a webhook for the entire Messaging Service, you can specify this during creation.
To change the inbound message handling behavior (e.g. update the webhook) for an existing Messaging Service, visit the Messaging Services page, click the Messaging Service you want to configure, then click "Integration" in the left-hand navigation area.
You can also modify your inbound message handling settings via the Messaging Services API.
Step 3: Add senders to your Messaging Service
Your Messaging Service can contain Twilio phone numbers, short codes, WhatsApp senders, and even an Alphanumeric Sender ID.
In Console, navigate to the "Sender Pool" page for your Messaging Service and click the button to add one or more Twilio senders, such as phone numbers, to the pool.
You can also add senders programmatically via the Phone Numbers, Short Codes, and Alpha Sender IDs subresources on the Messaging Services API.
Step 4: Start passing your Messaging Service SID in your API requests to send messages
There is only one small code change needed to begin sending messages using your Messaging Service: instead of specifying a From
number in your API request, you specify a Messaging Service SID. The Messaging Service SID starts with "MG" and can be found in the Properties page for the Messaging Service in Console.
You can either pass the Messaging Service SID in your From
parameter, or you can use its SID as the MessagingServiceSid
parameter in your API request. Either one will work the same.
When you pass the Messaging Service SID instead of a specific From
number, Twilio automatically selects the most appropriate sender from your Messaging Service’s sender pool to reach the To
number. Generally, Twilio prioritizes senders in the following order: RCS and other messaging channel senders, short codes, Alphanumeric Sender IDs, local phone numbers, and finally, non-local phone numbers. Note: A sender will only be prioritized if it's both available in the Messaging Service and capable of reaching the destination.
If you wish, you can also pass a specific From
number anytime you want to bypass the automatic number selection that would otherwise be applied by your Messaging Service.
For full details, see Sending messages with a Messaging Service.
Comments
0 comments
Please sign in to leave a comment.