Coding Amazon Echo Skills for Alexa with C#

Amazon Echo

Amazon Echo

I was reading this months CODE Magazine and there is an article about coding new Skills for Amazon Echo and Echo Dot to extend Alexa’s functionality. When you think about how you could extend Alexa to fit into your life, it could be well worth adding C# into your life. Amazon Echo is currently on offer for Mothers Day, with a £15 discount, maybe the time to get one. 

Lets say you want to check if a domain is registered, you could say “Alexa ask NominetTool if steven.uk is registered ?” or Alexa ask NominetTool who steven.uk is Registered to ?”. I guess depending on how accurate Alexa turns out to be, you could even try “Alexa ask NominetTool to Register steven.co.uk”.

I don’t have an Echo or Echo Dot, nor do I code in C# but this article does make it seem like a fun reason to learn. Its been maybe 10 yrs or more since I last opened VC++, and probably longer than that since I last wrote any reasonable amount of code. Looking at C# it doesn’t look that difficult once the new syntax makes sense. If I can pick up a cheap Echo or Echo Dot, I may just delve in to this. 

Looking at the code sample they provided…

HowTo.prototype.intentHandlers = {
   "RecipeIntent": function (intent, session, response) {
      var itemSlot = intent.slots.Item, itemName;
      
      if (itemSlot && itemSlot.value) {
         itemName = itemSlot.value.toLowerCase();
      }
      
      var cardTitle = "Recipe for " + itemName,
         recipe = recipes[itemName],
         speechOutput,
         repromptOutput;
      
      if (recipe) {
         speechOutput = {
            speech: recipe,
            type: AlexaSkill.speechOutputType.PLAIN_TEXT
         };
      
         response.tellWithCard(speechOutput, cardTitle, recipe);
      } else {
         var speech;
      
         if (itemName) {
            speech = "I'm sorry, I currently do not know the
                       recipe for " + itemName + ". What else can I help
                       with?";
         } else {
            speech = "I'm sorry, I currently do not know that
                       recipe. What else can I help with?";
         }
      
         speechOutput = {
            speech: speech,
            type: AlexaSkill.speechOutputType.PLAIN_TEXT
         };
      
         repromptOutput = {
            speech: "What else can I help with?",
            type: AlexaSkill.speechOutputType.PLAIN_TEXT
         };
      
         response.ask(speechOutput, repromptOutput);
      }
   },
      
   "AMAZON.StopIntent": function (intent, session, response) {
      var speechOutput = "Goodbye";
      response.tell(speechOutput);
   },
      
   "AMAZON.CancelIntent": function (intent, session, response) {
      var speechOutput = "Goodbye";
      response.tell(speechOutput);
   },
      
   "AMAZON.HelpIntent": function (intent, session, response) {
      var speechText = "You can ask questions such as, what's the
                 recipe, or, you can say exit... Now, what can I help you
                 with?";
      
      var repromptText = "You can say things like, what's the
                 recipe, or you can say exit... Now, what can I help you
                 with?";
      
      var speechOutput = {
         speech: speechText,
         type: AlexaSkill.speechOutputType.PLAIN_TEXT
      };
      
      var repromptOutput = {
         speech: repromptText,
         type: AlexaSkill.speechOutputType.PLAIN_TEXT
      };
      
      response.ask(speechOutput, repromptOutput);
   }
};

It looks quite simple to program, I guess you would use a PHP or C# web interface to execute the Recipes section, or in the example I gave to handle the domain name queries. Port the Whois Family Parser over to C# and you would be able to ask questions about whois result. 

Exciting times ahead. 

One comment

  1. Will you be making this tool? May wish to check google home instead.

    I have never seen code mag before.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.