Recent Tweets

Post Categories

Post Archives

Blog Stats

Windows 10, UWP & Twilio for SMS retrieval

I’ve been wanting to try out Twilio for quite a long time. I’ve seen my colleague, Martin, make great use of Twilio in demonstrations at conferences for the longest time and I always fancied trying it out.

I’ve had a Twilio account for quite a while but, the other week, I went through and added a little bit of money to the account and I bought myself a Twilio phone number that supports both voice and SMS messaging.

The first thing that I found kind of ‘fun’ was that as soon as I’d purchased a phone number I could specify URLs to be invoked in order to return XML files containing ‘TwiML’ which controlled what happened when you called my number or sent an SMS to it. Here’s my SMS file;

and I found this to be a very immediate way of linking the world of SMS/voice straight through to the world of web servers and programmability and, clearly, while I’m currently returning a static response to a voice call or text message I could easily be dynamically generating that response.

The next thing that I wanted to do was to see if I could get hold of the text messages that had been sent to my Twilio number inside of a Windows 10, UWP app.

Twilio has a REST API for SMS messages documented and I went about making sure that I could;

Twilio has helper libraries for these APIs across technologies like PHP, Ruby, Java and there’s a .NET library on GitHub.

Now, it may be that I didn’t look hard enough at this package but I didn’t seem to find a variant of it which supported the UWP. The Twilio package itself didn’t seem to be right and I couldn’t find the Twilio.WinRT package that was mentioned and so I figured that I’d just write some code myself as I only wanted to support a simple scenario which is;

“Poll for text messages on an interval and return the newly arrived messages”

and I didn’t need any more than that so I wrote a little UWP app to do just that starting from a blank project and adding just a piece of XAML to display a list;

and that all works really nicely for me and I really like the simplicity/immediacy of being able to quickly add SMS message integration into an app and especially when I think of this coupled with Windows IoT Core and how (e.g.) you could build some kind of kiosk that easily accepts text messaging as a form of input.

The code for this post is here for download. You would need to edit the Constants.cs file in order to provide your own Twilio account details and phone number.