Making alexa skills in .net
Ok so I’ve been in the alexa skills market recently, and obviously amazon wants you to use AWS Lambda for your skills. If you are like me, you have a ton of stuff in azure app service (the PaaS of azure). Azure app service supports nodejs, java, python, and of course .net. The two sdk’s amazon ships (node, java) do not tie in with a web stack, and are obviously thought of as being used with Lambda.
When you don’t host your code in aws, or use the alexa sdk’s you must use crypto magic to authenticate the requests from amazon, are actually from amazon. I was going to use the ruby sdk’s the community has put out, but I didnt see any code that verified requests. I noticed the alexa .net sdk supports verifying requests from amazon, and since its .net I know it will work great in azure.
Ok, so the alexa .net sdk is for the full framework only, and its built for webapi. The best way to get going is in visual studio
file -> new project -> ASP.NET Web Application .net framework A dialog comes up, and I picked
Azure API App.
Now you have an empty webapi project. We don’t need swashbuckle/swagger so lets get rid of that
In the package manager console
Tools -> NuGet Package Manager -> Package Manager Console
now go to
WebApiConfig.cs and delete this block of code, we’ll stick with attribute routing only.
Now Rename the
AlexaController and delete all the methods in the file.
Your AlexaController should look like this:
First lets install the alexa sdk.
The sdk requires us to make a class that inherits from speechlet. Speechlet, the base class gives us everything we need to make a skill. The base class has a bunch of methods we can override. We usually have to return a SpeechletResponse which is simply an object that describes to alexa what to say back. Usually this is just some simple text to read back to the user.
Ok now we need to add an endpoint to take traffic from amazon on. Amazon will do a post with a json document to
/ so we need to allow that. We should also make a livecheck interface for get’s and head requests.
That is basically it. the SDK will handle verifying the requests from amazon, and will call the overriden methods to deal with your alexa skill. Now you can deploy this to something like azure app services, and register yours skill in the developer console. Once registered, the skill should be avalible to you assuming you signed into your alexa device with the same account. You can see a working sample here.