Births are Spectacular but Sharing births is difficult

On Jan 24th, 2017 my wife and I added a baby boy to our family. When he arrived, we felt overwhelming joy from bringing a new baby into the world, and were anxious to share this with our friends and family who were about three thousand miles away. Then came the challenge – how should we share this new experience with them?

This is the part where the question “ever heard of Facebook or Instagram?” comes up but that didn’t quite fit my need. See we already have a two year old daughter who didn’t stop needing us when her brother was born. Combining that with the significant drop in sleep meant less energy and desire to do much else. I wanted a solution that could automate this for me with as little intervention as possible. With this in mind, we will build an API that allows people to text a Twilio phone number and receive picture messages with photos from a cloud storage account.

Twilio makes it Easier

We’re going to build this solution by doing three things:

Purchasing a Twilio phone number with SMS and MMS capabilities on Twilio.com Creating an API to send the photos from a cloud storage account using Visual Studio 2017 , C#, and the latest version of the Twilio Nuget package Connecting our API to our Twilio number using ngrok before sharing the number and taking more pictures

Let’s get started.

Purchasing Your Twilio Number

To purchase a Twilio phone number that can send MMS messages, log in to twilio.com, scroll down to the Super Network section of the console, and then click on Phone Numbers. You will next click on the Purchase a Number link (or the ‘+’ symbol if you already have other numbers already purchased), enter in an area code of your choice, select the SMS & MMS check boxes, and then click on the Search button. When eligible numbers are returned, select one of your choosing and then click on the Buy button. The same steps are shown in our animated gif below:

Keep in mind, this will only work with US based phone numbers. If you’re considering sending messages from or to non US based phone numbers, check out Twilio’s MMS Converter. This tool enables Twilio to send a URL in place of the picture message in countries where MMS support is limited. With our Twilio number purchased, Step 1 is complete!

Setting Up Your Visual Studio Web API Project

Let’s start Visual Studio and create an ASP.NET Web Application targeting the .NET Framework as shown in our animated GIF below. We will then create an empty Web API project. If you are unfamiliar with Visual Studio and would like more detailed steps, check out Create a Web API Project at docs.microsoft.com.

Next we will add the Twilio and JSON.Net Nuget packages to our project. The Twilio package contains the Twilio helper library, which provides objects to interact with Twilio’s APIs. The JSON.Net package allows us to do some JSON parsing in our code.

In the Solution Explorer window, right click on the References folder and from the context menu select Manage Nuget Packages. That should open up the Package manager window where you can search for Twilio followed by Newtonsoft.Json and then install the latest stable versions available.

Time to Write Some Code