Send Branded SMS Messages Using Twilio Alphanumeric Sender ID

It’s been a few months since we hosted Signal (if you missed it, don’t forget that videos from all the sessions are available online) and in this post I wanted to spend some time exploring one of the announcements that I found pretty exciting: alphanumeric sender ID’s. Being based in the UK and traveling often in Europe I regularly receive SMS messages with a business name as the sender ID instead of a phone number. This is great as I instantly recognize the name of the business sending me the message instead of seeing an incoming message from an unknown number.

In my SMS inbox right now there are no less than 3 messages using a business name as the sender ID instead of a phone number Now I can use Twilio to enhance the experience I provide users receiving my SMS messages by sending text messages with an alphanumeric sender ID to any of 145 countries around the world. In this post I’m going to show you how.

A word of warning

Before we dive into the code, there are a few things you should know about alphanumeric sender IDs. This style is great for alert or broadcast type messages, but no use for interactive applications as users cannot respond to an alphanumeric sender. As such, if you choose to use an alphanumeric sender ID you will need to provide alternative ways for users to opt out. You should also think carefully about the sender ID that you choose. Your business name or brand is fine, but if you try to get too creative things can really backfire.

Ready to start sending branded SMS messages? Let’s get on with it then.

Today’s toolbox

I’m going to demonstrate sending an SMS message from an alphanumeric ID using Ruby, so if you want to follow along, you’ll need the following:

and that’s it, so let’s get on with sending some SMS messages!

Sending SMS messages

You may have seen how to send an SMS message from a phone number before, but here’s a quick recap:

You can save that to a file and run it or just type it straight into irb, either way it will just work. Pretty straightforward, right? How about sending an SMS message from an alphanumeric sender ID then?

If you run the code, you should receive a message from the name you use instead of the number.As you can see, there’s only one change. We replaced the phone number with a string of text and that was all there was to it.

145 countries is not all all the countries

Well, ok, it’s that simple only if you are sending SMS messages to one of the 145 countries that support this feature. If you are sending to multiple countries and one of them, like the US, doesn’t support alphanumeric sender IDs then there is a bit more work to do.

Send a message using an alphanumeric sender ID to a number in a country that doesn’t support it and the Twilio API will respond with an HTTP 400 response. The body of the response will contain the Twilio specific error details, including a Twilio error code and error message. The error code that represents our problem, sending an SMS message from an alphanumeric sender ID to a country that doesn’t support it, is Twilio error code 21612.

The HTTP response will manifest itself in the Ruby library as a  Twilio::REST::RequestError. We can rescue the exception and query the error for the code to check it is the error we expect by making sure it has code 21612. If it is we can retry sending the message using a Twilio number as the sender. Here’s how that would work:

You can now try this script against a number from a country that doesn’t support these messages, like the US, Japan or Belgium. Once the API responds with the error the script will fallback to using the supplied phone number as the sender.

If other errors are raised they will cause this script to crash and you should handle those errors in an appropriate manner for your application.

Brand those SMS messages

There we go, you can now:

  • Improve the user experience for SMS alerts and broadcasts by branding your SMS message sender
  • Fallback successfully in cases where the receiver is in a country that won’t accept an alphanumeric sender ID

Remember that using an alphanumeric sender ID is not appropriate in all possible uses of SMS as recipients cannot respond and in cases where you can use this feature it is important to provide alternative ways for users to opt out of these messages.

As always, if you have any further questions about this drop a comment below, give me a shout on Twitter or shoot me an email.

  • Very good post Phil!

    As a first and proactive approach, I would check the recipient country to use – or not – an alphanumeric sender ID (ASID). The good point is that we spare one API call to send a sms to a country not supporting ASID. But the downside is that if new countries will support ASID in the future, my application will need a code update to use it.

    Because I like to implement features that persist during time and resist to the future, we will finally use the fallback method, as described in your post. So thank you! :)

    • Hey Michaël,

      Thanks for your comment! You have reminded me of a post that I intended to write more recently to follow up on this. If you use a Messaging Service (https://www.twilio.com/docs/api/rest/sending-messages-copilot#alpha-sender) to send your messages with an ASID, you can specify numbers to fallback to. That way you don’t have to catch the error as I describe above and it will not only be future proof for countries allowing ASIDs in the future, but the geo-match functionality means you can fallback to a local number. So give that a look!

      • Hi Phil,

        Good news! I just configured my Messaging Service and will try it soon. Thank you again.

  • Wei Miin Chie

    Hi Phil, I’m using the codes from Twillo Blog https://www.twilio.com/blog/2016/02/send-sms-from-a-google-spreadsheet.html to send SMS from Google Sheet. In the same way as your above example, I changed the mobile number in “From” to an alphanumeric ID (enabled and verified in co-pilot) but it’s not working. Is there something missing?

    • Hi! Are you seeing an error somewhere? Are you sending to countries that support alpha numeric sender IDs?

  • marketing solutions

    Great, love this post, thanks for sharing such a useful information, keep sharing like that ..

    http://www.marketingsolutions.pk

  • Hartmut

    Hi @philnash:disqus are you sure the error code is correct?
    > Error 21612
    > The ‘To’ phone number is not currently reachable via SMS

  • vijayaraj s

    hi,, i did twilio sms gateway in php.. as of now i receiving sms. but in number my client needs in name as of my know can anyone say how to use alphanumeric_id . so ican get message in client name instead of number in php. is it supported in india

  • Alastair Budge

    Hi Phil. Great post, thank you very much!

    Do you have any tips on how to implement this when using a Google Spreadsheet to store the phone numbers, and sending through Google App Script? (as per this walkthrough: https://www.twilio.com/blog/2016/02/send-sms-from-a-google-spreadsheet.html)

    Can’t figure out how to get the callback error…