Fun Project: Amazon Alexa Skill for New Relic Insights

As a fun project in some spare time, I recently worked on a way to tell Amazon Alexa how to talk to New Relic Insights and retrieve some high-level information about an account. I was just curious on what it would take to get Alexa to access our Insights API with a voice command and Alexa to speak out some result of this query.

You typically start by creating an Amazon developer account and register a new Alexa Skill with the Alexa Skills Kit.

Since I am a C# .NET guy by heart, of course I wanted to ideally develop this using Visual Studio and my favorite programming language. I found this a blog post to be very useful as a starting point “Write your Amazon Alexa Skill using C# on AWS Lambda services“. It not only highlights the basic steps to get started using .NET Core, but also targets a serverless function in AWS Lambda to run this code.

The Alexa Skill specifies an invocation name that you can use in a start of an interaction with Alexa. In my case, I used the invocation name “new relic insights”:

One of the next steps is then to define how the interaction model looks like for your skill. In my sample, I created a so called intent named “NewRelicInsights” that you can then use to identify in the code.

As you can see in the above screenshot, I have added some sample utterances that you can later use to ask to Alexa. This is not an exhaustive list, but should only show some basic examples.

You will notice that in line 10, I first check whether it is an intent request at all. In line 18 I then actually check to see whether or not Alexa identified the request as a “NewRelicInsights” request given the invocation name above.

Another thing you’ll notice is that I also have a parameter defined in my interaction model. This is useful to specify the New Relic account you want to query against. In the code above, I specified a default account for ease of use and also try to retrieve this account number from the Alexa request inside the requests slots.

Once I identified it as a New Relic Insights request and know what account to query against (default or provided by the user), I can then execute the request using our Insights Query API:

Once the HTTP client has executed the request, I then simply parse the result and let Alexa speak out a result. Optionally, I could also ask additional follow-up questions and so on which is not handled in this post.

The idea was to just give you a high-level understanding what it would take to integrate with Amazon Alexa. The full code is available in Visual Studio Team Services. Let me know if you would like to check it out … I am happy to provide access to it.