There are different options available which you can leverage to build the API backend. The recommended one from Amazon is AWS Lambda. Since my purpose for this blog is to exploit ways how we can implement Alexa skill, I am using Azure Functions to build the API backend. If you are not aware of Azure Functionits is a serverless offering from Microsoft Azure. The codebase I am portraying below is available in the Github link is in the end.
Just to bring in the context today we are talking about the middle segment which our API layer includes Azure Function, Application Insight, and Azure SQL DB.
I have build 3 main endpoints:
- nebulaswitchping: This endpoint is just used for verifying the availability of the API platform. It's vital for development and BAU support as one can validate if Azure Function is up and running using this
endpoint.
- nebulaswitch: This endpoint is the core that will serve the request coming from Alexa device to skill and then from skill to API endpoint. This endpoint also updates the switch status in the database based on users' intend.
- This method has core dependency on Alexa.NET, this package had a core library which can handle Alexa skill request/response.
- This snippet is invoked when we enable Alexa skill from the device, by speaking "Alexa Open Nebula Switch"
- Next, all the request go to Intent snippet as below for processing
- Last I have also included Azure Application Insight for managing application-level telemetry. Below code, snippet calls the helper class AppInsightHelper.cs and pushed the telemetry to Azure Application Insight. Before you run the application please provide Application Insight Key to the marked section in AppInsightHelper.cs
- getnebulaswitchstatus: This endpoint is used by the IoT device to get the updated status of the switch from DB.