How to build an Alexa Skill using C# and Azure

First of all this seems to be surprising. How and why would you build an Alexa Skill using Microsoft Technologies. Weird ? Hmm…. Well Alexa and Cortana are by now friends and buddys („Hey Alexa, ask Cortana how to build an Alexa Skill“ – https://techcrunch.com/2017/08/30/amazon-and-microsoft-agree-their-voice-assistants-will-talk-to-each-other/).
For you as a user and/or developer this is great news. Indeed the industrie is getting closer and closer and enabling Alexa to work with Cortana and vice versa makes a lot of sense in this pretty new industrie of Voice User Interfaces.
Some years back I wrote a blog post of the future of interfaces and how user interaction / user experience will be in the years to come. I think now it’s earlier then anticipated and Alexa, Cortana, Siri and others have basically arrived in every household in the western world. Of course data protection, privacy and security is key and this is where you find the differences between all the Voice User Interfaces (VUIs) and there consumer devices. When I look into my home I see it know quite a bit automated. We basically removed all RCs from the living room. Old technology is no longer present and Alexa is being used on several Echo and Echo Dots to make the digital live easier. So if we want to watch TV or listen to music we have to ask Alex to turn on TV (actually a beamer, XBox, T-Entertain and our Sonos) with a single command. The alarm clock in the sleeping room is Alexa, shopping list is done + maintained by Alexa etc etc.

If we look a couple of years – if not month – into the future you will see VUIs in cars to get finally rid of all the buttons, touch displays etc which can distract you from driving the car – and hey in some years you will also see the full autonomous car steered by AI and controlled by a VUI.

So why not look into techniques how to build a skill for Alexa ? Usually it’s been done using node.js and AWS (AWS Lambda) to lock you in the Amazon eco system. As I still don’t get a long very well with Java/Javascript and as I think Azure has done great in the last couple of years I started a project to build an Alexa Skill in C# (yes I used to build Software in the past with unmanaged C++ code…) running on Azure. BTW this has nothing to do with the new friendship between Alexa and Cortana. It worked before as well.

So if you look into my Repo (https://github.com/pjaegerhh/HalloAlexa) it shows how to build an Alex Skill in C# hosted as a Web API Service on Azure.
In /SpeechAssets you can find the Intents (Actions) and Utterances (synonyms) to invoke Alexa on an Echo Device. Yes it’s simply a „Hello World“ but didn’t we all start a new technology doing a „Hello World“ ?

In /Controllers you can find AlexaController.cs which is actually the service for the intents (or functions)
Instead of default AWS Lambda we make use of Azure Web API Services.
To start a new project select the ASP.NET WebApp template in VS2017 and in the following dialog you should use Azure-API-App. You could also use „Web API“ but usually after 15min of inactivity of the App Azure deletes it from memory and the next user invoking your service might get an App Timeout.
This is actually not nice if you are in the middle of certification for your new Alexa Skill ­čÖé

First thing you should do after creating the Web API Service is to update your NuGet packages and make sure that „Swashbuckle“ is installed (this should be the default). >ou find many outdated packages – update them all. If you’re asked to Update SwaggerConfig.cs push Yes.

Next step should be a publish of the empty App to Azure.
Use a good name for your Web App, make sure that the type is „API App“, select a ressource group (or create a new) and create a new App Service-Plan. The free tier is good enough for an average Alexa Skill.
After you hit publish you will get your empty App published on Azure and if done without errors your default browser will open and show the App.
Swagger should be installed by default (just type after your web service URL /swagger and see if it’s working.) Its quite a handy tool to check if your AlexaController is working well and to do some testing on HHTP Post messages.

Now you might want to switch to the Alexa Dev console.
https://developer.amazon.com/edw/home.html#/ Please make sure to logg in with your Amazon credentials. Best would be to use your normal credentials which you are also using for your Echo’s

Go to „Alexa Skill Kit“ and „Add a new Skill“
Now it’s getting quite easy and straight forward. Best if you look into /jpgAssets and enter all the information needed for your new skill as soon as you’re done go to your Echo Config on the web (https://alexa.amazon.de) and see if your newly developed skill shows up under „Your Skills“.
This should be the default if your Echo’s are using the same Amazon ID which you have used for developping your Skill. Otherwise you need to use the „Beta Test“ funtion.

„Hi Alexa open Hello World“ should now work. Wow. That easy ? A complete VUI developed in 5mins ? 

Congrats ! You have developped your first Alexa Skill using C# and Azure !

So this „Hello World“ seems quite easy but you have everything you need to develop a even more sophisticated Skill. Please watch my Github Repos at https://github.com/pjaegerhh/ as I will add a more complex scenario very soon.