Receiving two-way SMS messages with Twilio

What is two way SMS text messaging?

Two way SMS is where you can both send and receive a text message to let you have a conversation with the recipient. This would let a contact center agent carry on a text-based chat with a customer or let people reschedule appointments via text. Customers expect communication to be two-way no matter how complex or simple the interaction. 

How does two way SMS text messaging work?

Two-way SMS has two parts, inbound and outbound.

Inbound

Programmable SMS is where people can send SMS text messages to your Twilio phone numbers and Twilio passes that message onto your software.

When Twilio receives incoming text messages, it sends an HTTP request to your web application to get instructions on what to do next. This is called a webhook.

Outbound

There are two ways to send an outbound message.

  1. REST API: The first way to send an outbound message is with an HTTP POST to Twilio’s Message API resource. This can be in response to an inbound message or initiated independently. You simply specify the phone number you want to send to, the phone number you’re sending from, and the content of the message (i.e. text, pictures, links, etc)
  2. TwiML: The second way to initiate an outbound message is in direct response to an inbound message with TwiML. TwiML is an XML-like language as the format of the responses and you send it to us as a response to our webhook containing the inbound message.

How do I set up to receive inbound SMS text messages?

You need to define where you want the received message sent to, i.e. what URL we should GET or POST the content to. You do that in Phone Numbers in the console, in the messaging section of one of your phone numbers or via the API.

Then you need to know what to expect from our two way SMS API. We’ll send you all the details of the message, including to, from, body and any media they sent such as pictures. We also try and share information about the phone number when available., like the city, state and country.

What Phone Numbers can I use for two-way SMS?

The main numbers you can use for two-way SMS are:

  • Long codes / DID’s / phone numbers that indicate geography
  • Shortcodes
  • Toll-free phone numbers

Bear in mind there might be some quirks with sending two-way SMS internationally. The best practice is to always use a local number, where available. For example you can’t send international messages from a shortcode and some countries might change your sender ID for recipients. Check out the country capabilities site to check what’s possible in countries you’re sending to and from.

In many countries, Alphanumeric sender ID is great for identifying your business but can’t be used for responses as it’s one-way messaging only.

What do I do next?

You might want to check out our quickstarts for examples of how to receive a text message and howtos for lots more examples of both sending and receiving SMS messages.

Have more questions? Submit a request
Powered by Zendesk