ASP.Net Web API and Alexa Skills

Description

Late last month we highlighted how Alexa skills can be written with C#, Santa Brought Alexa? Skill it up with C#!.

Today we've got another example, this time using the ASP.Net Web API.

Having a merry, geeky Christmas… creating an Alexa skill with ASP.Net Web API

"Thanks to Santa Claus’ generosity and Amazon’s new Alexa voice assistant, our head of .NET development Andy Butland no longer has to wonder what his daughter is having for lunch tomorrow…

Along with, I suspect, a lot of other people, one of the Christmas presents I had most fun with this year was an Amazon Echo Dot.

Out of the box it comes with a number of voice activated features, such as answering questions, providing alarms and timers and even wittily responding when you ask it things like “who is the fairest of them all”. It’s extensible with a wide range of skills, provided by various third parties. And you can write your own, which is what I had a look at doing over Boxing Day.

The skill I built wasn’t one that’ll be useful to many people, so isn’t public, but will be a useful addition to our household. When my daughter eats lunch at school, it’s handy to know what she’s had or having so we can plan what to cook for the evening meal. The school has a four week rolling menu, so even with a copy on paper, it requires a bit of calculation to work out what she’s having on a given day. I wanted to be able to ask questions similar to “Alexa, ask ‘School Menu’ what they are eating tomorrow” and get an answer describing the menu for that day.

Effectively the skill is implemented as a web service — an HTTPS end-point that returns a specifically structured JSON response. The Echo Dot digitises the incoming voice message and passes it on to Amazon’s Alexa service, which parses out the message in order to figure out how to answer the question. If an “invocation name” is provided — in my case “school menu” — it looks for a third party or custom skill associated with the users account to pass the request on to, translating the voice message into an appropriate HTTPS request to the web service. The web service then responds with a text response, that’s translated back into voice and send back through the Echo Dot speaker.

The code for the skill described in this article this is up on Github and uses ASP.Net Web API.

...

Deploying

Once testing was complete I could shut down the temporary URL generated by Ngrok and push the service up to Azure, using an Api App. The default azure address come with HTTPS support, so for something low traffic like this it’s a cheap and easy place to host the service.

With that in place we’re going live at the start of the new term on 9 January, and hopefully those days of double portions of risotto are over for good!

..." [You're going to want to click through to read the entire tutorial]



The Discussion

Add Your 2 Cents