Ahh the holidays are here. Christmas time makes me think of classic songs like Happy Holidays, Silver Bells, or It’s the Most Wonderful Time of the Year. Wouldn’t it be cool if we could crowdsource the music selection at holiday gatherings? This sounds like the perfect candidate for a serverless application powered by Twilio & Spotify. In this post, we will walk through creating an Azure Function to respond to text message requests.

Creating our Azure Functions project in Visual Studio

This project’s ingredients include:

After everything is installed, create a new Azure Functions project by starting up Visual Studio 2017 and going to File → New → Project. Click on the Cloud category and select the Azure Functions project.

I’ve named my project JukeboxFunctions. You can certainly use that or a different name for your project if you’d like.

When you click on the OK button, a prompt will pop up asking you to select a trigger and your desired Azure runtime version. Here’s where things get interesting. The premise of our Azure function is that it’s serverless. The code is deployed to Azure and will run when something triggers it to run. Azure functions support a number of triggers, which you can see here:

The runtime version we want is Azure Functions v2 (.NET Core) and the trigger we need is Http trigger since Twilio is going to make an HTTP request to our function when it receives a text message. Confirm that those two options are selected in the prompt and click the OK button. With our function created, time to reply to our text message request!

Add the Twilio Nuget Package in Visual Studio

Let’s add the Twilio library to our project. In the menu bar, click on Tools → Nuget Package Manager → Package Manager Console. When the Package Manager Console opens, type in Install-Package Twilio and hit enter.

Now to use the Twilio library, copy the code below to the very top of our code file, Function1.cs.