<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anand Mukundan</title>
    <description>The latest articles on DEV Community by Anand Mukundan (@anandmukundan).</description>
    <link>https://dev.to/anandmukundan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F97053%2F5e975d2c-1711-445b-ad53-6cd98d5d9563.png</url>
      <title>DEV Community: Anand Mukundan</title>
      <link>https://dev.to/anandmukundan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anandmukundan"/>
    <language>en</language>
    <item>
      <title>Building for Alexa - 4 - Progressive Response</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Mon, 10 Sep 2018 11:00:00 +0000</pubDate>
      <link>https://dev.to/anandmukundan/building-for-alexa---4---progressive-response-leg</link>
      <guid>https://dev.to/anandmukundan/building-for-alexa---4---progressive-response-leg</guid>
      <description>&lt;p&gt;This post looks at a specific functionality that you can add to your skills called Progressive Response.&lt;/p&gt;

&lt;p&gt;These allow you to show the user that the skill is working on something that may take some time. For example, if you are looking up an order delivery status, but you need to check with multiple logistic providers to get the final status. This whole operation may take maybe 30 seconds for you and then you need to package this information into a useful voice response. So it may make sense when you are half way thru your third-party checks to let the user that you are working thru the request and it may take you some more time to get the information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fi.stack.imgur.com%2FD2alZ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fi.stack.imgur.com%2FD2alZ.gif" alt="See the source image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Think of this are the voice equivalent of the hourglass in a windows application or the animated circle you find in web applications (Like the ones you see here).&lt;/p&gt;

&lt;p&gt;The way you send a progressive dialog is to call the API endpoint /directives with a VoicePlayer.Speak command.&lt;/p&gt;

&lt;p&gt;Currently, you do not have an out of the box way to do this via the AlexaSkillKit.NET library, but as this is a normal REST endpoint, you can directly call it like any other REST service.&lt;/p&gt;

&lt;p&gt;Below is a function I wrote that you can use to send progressive dialogs as part of your Alexa Skill (This uses the RestSharp Library for the API calling). The apiToken,requestId and apiURL are part of the request you get from Amazon. You need to use the token you receive or the REST call will fail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt; &lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SendProgressiveResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;apiToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;apiBaseUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;speechText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speechText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="m"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Progressive Text cannot be more than 600 characters"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"speechText"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;restClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RestClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apiBaseUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;RestRequest&lt;/span&gt; &lt;span class="n"&gt;restRequest&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RestRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Resource&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"v1/directives"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;RestSharp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;POST&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Bearer "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;apiToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;requestId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requestId&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="n"&gt;directive&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"VoicePlayer.Speak"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;speech&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;speechText&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;};&lt;/span&gt;
            &lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddJsonBody&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;restClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;restRequest&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HttpStatusCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NoContent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Progressive was successful"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Progressive failed withe code - &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StatusDescription&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can get more information on Progressive Responses &lt;a href="https://developer.amazon.com/docs/custom-skills/send-the-user-a-progressive-response.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;..&lt;/p&gt;

</description>
      <category>net</category>
      <category>alexa</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Building for Alexa - 3 - Structuring your Code</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Mon, 03 Sep 2018 17:12:12 +0000</pubDate>
      <link>https://dev.to/anandmukundan/building-for-alexa-ndash-3-ndash-structuring-your-code-4i8j</link>
      <guid>https://dev.to/anandmukundan/building-for-alexa-ndash-3-ndash-structuring-your-code-4i8j</guid>
      <description>&lt;p&gt;In this post I want to discuss the way I like to structure my code when developing the Skill handling backend. As mentioned in previous posts, the handler is based on the ASP.NET WebAPI project template, which is based on MVC. So out of the box the structure is like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://manand.typepad.com/.a/6a00d83451a61969e2022ad38e45df200d-pi"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V99noCKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://manand.typepad.com/.a/6a00d83451a61969e2022ad36825b9200c-pi" alt="image" title="image"&gt;&lt;/a&gt;I like to structure the Intent Handling code in a way that I think makes it more maintainable and easier to debug. Again this is just my personal approach and is not in any way dictated by MVC or other patterns.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/AreYouFreeBusy/AlexaSkillsKit.NET/"&gt;AlexaSKillKit.net&lt;/a&gt; GitHub page has a get started section that would get you to the above structure and a working Skill handling backend.&lt;/p&gt;

&lt;p&gt;So if you follow this structure you will have a basic Speechlet class that handles all of your intents and returns a SpeechletResponse to the Controller.  The Controller is very light weight and just contains code to receive a POST and returning, what your Speechlet implementation returns, after converting it to a API response(HTTPResponseMessage).&lt;/p&gt;

&lt;p&gt;Since all the intents land up in the single speechlet implementation class, I prefer to create separate handlers for each intent. I usually declare a IHandler interface that contains something a single method like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="n"&gt;SpeechletResponse&lt;/span&gt; &lt;span class="nf"&gt;handleIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IntentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Session&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="n"&gt;Context&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So for each category of intents (not always each intent, but in a lot of cases it ends up being that), there is a handler.  The Speechlet implementation then hands off to the handler based on the intent received.&lt;/p&gt;

&lt;p&gt;So our structure changes to something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://manand.typepad.com/.a/6a00d83451a61969e2022ad38e45e5200d-pi"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s_YIrJ70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://manand.typepad.com/.a/6a00d83451a61969e2022ad3adf049200b-pi" alt="image" title="image"&gt;&lt;/a&gt;This has some advantages. Since handler logic is separated out, it is easier to maintain and debug  this code, instead of everything being in a big class. Also when later you want to do something like IOC, this structure will help make that possible.&lt;/p&gt;

&lt;p&gt;I also prefer to have a set of service gateway classes that links up our handlers to the actual business services your may end up calling.  These could be SOAP or REST  based on your business, but most skills end up calling some kind of business services. So having a gateway pattern implementation would make future expansion and management of  these interfaces easier.&lt;/p&gt;

</description>
      <category>alexa</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>CallerMemberName and Interfaces</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Fri, 24 Aug 2018 11:51:20 +0000</pubDate>
      <link>https://dev.to/anandmukundan/callermembername-and-interfaces-5gj1</link>
      <guid>https://dev.to/anandmukundan/callermembername-and-interfaces-5gj1</guid>
      <description>

&lt;p&gt;[CallerMemberName] is a attribute that is available in C# 5.0. It is a very useful functionality especially when doing common app framework components like logging, auditing etc.&lt;/p&gt;

&lt;p&gt;One of the things that you usually try to do in your common logging infrastructure is to log the function that generated that log.&lt;/p&gt;

&lt;p&gt;So before C# 5.0 it was most common to interrogate the stack to find the caller, which can be an expensive operation. Or the caller information is passed from the source function, which hard codes its name in the call.&lt;/p&gt;

&lt;p&gt;Something like&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;_logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Message"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"myFunctionName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This becomes hard to maintain and so in most cases the logger actually interrogates the stack to get this information and as mentioned before that comes with a performance penalty.&lt;/p&gt;

&lt;p&gt;Using this new attribute, you can write something like the following for your log function:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CallerMemberName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;callerFunction&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"NoCaller"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The second parameter here is not passed by the caller, but is rather filled up by the infrastructure (i.e. .NET Framework). The parameter needs to be an optional parameter for you to be able to use this attribute. And this does not have a performance penalty as the compiler will fill in this parameter at compile time and so no run-time overheads.&lt;/p&gt;

&lt;p&gt;This works fine, except when you use Interfaces. Again interfaces are generally a pattern that is often used in framework components like logging. So you will have a ILogger interface that will have a definition like about which is implemented by your actual Logger class and the caller use the Interface to talk to your implementation.&lt;/p&gt;

&lt;p&gt;If you do something like this, the gotcha is that the interface also needs to have the attribute defined, or the value will not be auto filled. This is something that is easy to miss and is not well documented from whatever I could find. So your interface definition for this function will have the attribute defined like below:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CallerMemberName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;callerFunction&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;for the caller value to flow through to your implementation.&lt;/p&gt;

&lt;p&gt;When you are designing your interfaces this is so easy to miss and can take a long time to figure out why.&lt;/p&gt;


</description>
      <category>net</category>
      <category>softwarearchitecture</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Building for Alexa - 2 - Creating a Skill</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Sun, 22 Jul 2018 19:42:14 +0000</pubDate>
      <link>https://dev.to/anandmukundan/building-for-alexa-ndash-2---creating-a-skill-2bf8</link>
      <guid>https://dev.to/anandmukundan/building-for-alexa-ndash-2---creating-a-skill-2bf8</guid>
      <description>

&lt;p&gt;This is the second post on the series about developing Alexa Skills using .NET.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding A Skill
&lt;/h2&gt;

&lt;p&gt;Developing a skill is made up of two major parts. You setup what is know as the intent, utterances configuration. This is done in the amazon skill website console. The &lt;a href="http://manand.typepad.com/.a/6a00d83451a61969e2022ad3a2e550200b-pi"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MaVJ80kM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://manand.typepad.com/.a/6a00d83451a61969e2022ad3831eba200d-pi" alt="image" title="image"&gt;&lt;/a&gt;new iterations of this console is vastly improved and is easier to use from a newbie perspective. (It used for be a text box into which you typed in a huge JSON).You need to have a registered Amazon developer account to develop a skill and it is free.&lt;/p&gt;

&lt;p&gt;The other part is the building of the backend that would actually process the request from  Amazon. So Amazon parses the actual voice input and then maps into the intents and structures we had configured and then calls our backend service with that data.&lt;/p&gt;

&lt;p&gt;All data from and to the Amazon Alexa Skill system is via JSON and our backend is just a REST endpoint that is called by Amazon. So if you are a .NET  developer at this point you are thinking Web API, right? Well you are correct.&lt;/p&gt;

&lt;p&gt;So we need to start with a Web API project. It does not matter what framework and Core vs. Non-Core, the Alexa service just needs a REST Endpoint that supports https (&lt;em&gt;Important, if you are planning to host your endpoint&lt;/em&gt;). There are some other rules that are documented in the Amazon site for &lt;a href="https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html"&gt;custom hosted endpoints&lt;/a&gt;, but if you starting off with a skill, the this is the only major rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Alexa Requests
&lt;/h2&gt;

&lt;p&gt;I am going to assume you read thru the developer documentations and setup the intent mappings and utterances for your Alexa skill. This is quite well documented in the Amazon site.&lt;/p&gt;

&lt;p&gt;Though the interface between the Alexa service and your backend is purely REST/JSON based, it is helpful if you use a library that helps parse those requests and also create response requests. This will greatly simplify the amount of plumbing code you will have to write for everything to work.&lt;/p&gt;

&lt;p&gt;The most common library I found is the &lt;a href="https://github.com/AreYouFreeBusy/AlexaSkillsKit.NET"&gt;AlexaSkillsKit.NET&lt;/a&gt; kit. This supports most of the commonly used Skill kit requests and would be quite easy to start with.&lt;/p&gt;

&lt;p&gt;It is not very well documented, but you should be able to get started with the documentation available and then you will have to jump into the code or use GitHub forums to get around using more complex features.&lt;/p&gt;

&lt;p&gt;You can get this from GitHub or as a &lt;a href="https://www.nuget.org/packages/AlexaSkillsKit.NET/"&gt;NuGet&lt;/a&gt; package&lt;/p&gt;

&lt;p&gt;Once you have a basic WebAPI project with this library integrated correctly, you should be able to host a backend that can handle requests coming in from the Alexa service.&lt;/p&gt;

&lt;p&gt;If you are just checking it out, I would recommend you use Azure App service hosting to get a sample working. It allows you to easily have a HTTPS endpoint available which will work with the Alexa service.&lt;/p&gt;

&lt;p&gt;The future articles in this series will be focused of specific scenarios and how you can handle those when you are building your backend.&lt;/p&gt;


</description>
      <category>net</category>
      <category>alexa</category>
    </item>
    <item>
      <title>Building for Alexa - 1 - Anatomy of a Skill</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Sun, 15 Jul 2018 21:08:53 +0000</pubDate>
      <link>https://dev.to/anandmukundan/building-for-alexa-ndash-1---anatomy-of-a-skill-2oj</link>
      <guid>https://dev.to/anandmukundan/building-for-alexa-ndash-1---anatomy-of-a-skill-2oj</guid>
      <description>&lt;p&gt;This is the first of a series of posts that talk about building an Alexa Skill using .NET.&lt;/p&gt;

&lt;p&gt;I have been playing around with building Alexa skills for the last couple of years, but never wrote about it. The idea for this set of blog posts came as I was building one recently and found that is was very difficult to find information around this. The idea here is to have enough information to get started, rather than in-depth information of different aspects. I may also post about some problems I had, as .NET is not a supported platform from Amazon Skill Kit perspective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of a Skill
&lt;/h2&gt;

&lt;p&gt;An Alexa Skill flow has four major entities involved in each flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user who speaks a command to the echo or Alexa enabled device (I will use echo for simplicity in my posts, but it mean any Alexa enabled device should work).&lt;/li&gt;
&lt;li&gt;The echo device, which receives the initial voice input and also plays back the final voice output.&lt;/li&gt;
&lt;li&gt;The Amazon Alexa service, which receives the data from the devices, decodes it and then forwards it for processing to the backend. It also converts what it receives from the backend and sends it over to the actual echo device.&lt;/li&gt;
&lt;li&gt;The actual back end services which contains the business logic for the skill itself. This can be hosted either in Amazon or outside. Amazon provides hosting in its cloud based Lambda service if you want to build these backends in Node.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, basically when you are talking about building a skill one you are actually building of the back end service and configuring the Amazon Alexa service. A simple diagrammatic representation is a below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://manand.typepad.com/.a/6a00d83451a61969e2022ad38151ff200d-pi" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fmanand.typepad.com%2F.a%2F6a00d83451a61969e2022ad3815204200d-pi" title="image" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Amazon Alexa Service maps the incoming request to what are called Intents (that the developer defines) and then creates a JSON with data that you need and then sends it over to the back end services. The backend service does whatever process it is supposed to do and then returns the data back as a JSON. The JSON formats that are part of this interchange is defined by Amazon.&lt;/p&gt;

&lt;p&gt;In this series, I am going to talk about building this Back End service using .NET, c# and  then hosting it as a Azure API service. So this will be built using the default Web API MVC project type. You can deploy this to any publicly accessible endpoint and Azure just happens to be something that was easily accessible for me.&lt;/p&gt;

&lt;p&gt;In the next post, I will talk about the different ways you can create the backend service and what you will need to do this in .NET&lt;/p&gt;

</description>
      <category>alexa</category>
      <category>net</category>
    </item>
    <item>
      <title>Open SSH on Windows</title>
      <dc:creator>Anand Mukundan</dc:creator>
      <pubDate>Mon, 02 Apr 2018 12:16:18 +0000</pubDate>
      <link>https://dev.to/anandmukundan/open-ssh-on-windows-2i5h</link>
      <guid>https://dev.to/anandmukundan/open-ssh-on-windows-2i5h</guid>
      <description>&lt;p&gt;I had a scenario a week or two ago where I wanted to connect from a Mac to a Windows machine and run some PS scripts. (Well the discussion on why not use PowerShell Core is for a different post).&lt;/p&gt;

&lt;p&gt;So the easiest way is to do SSH. The windows machine I needed to connect to was a Win 7 machine and so did not ship with SSH built in. So I just downloaded &lt;a href="https://github.com/PowerShell/Win32-OpenSSH"&gt;Open SSH&lt;/a&gt; that the powershell team had ported to Windows and deployed it. And then connected from the Mac, no problem, everything worked great.&lt;/p&gt;

&lt;p&gt;Now I wanted to integrate this into a script and did not want to enter a user name/password combo and SSH has a way to support this using public/private key pairs. If you search the internet, there are hundreds of articles on how to generate a key pair and copy the public key over to the server to allow the client to connect. The problem is I could not find what to do on the Windows Server side of SSH as the directory structure it uses differs slightly from what the UNIX version.&lt;/p&gt;

&lt;p&gt;So some debugging and log analysis later found out the Windows version uses the .ssh (i.e. C:\Users\xxx) directory to find the pub key file (file should be named authorized_keys). The only gotcha is that the user directory is the user who logs in via the SSH. I had setup a local user that the SSH script will use to log in, and I was initially trying to put the file into my user dir, when it needs to be in the "trying to log in user's" user dir. The authorized keys file is just a text file containing all public keys. So if you have more than one public key, just append to your authorized keys file.&lt;/p&gt;

&lt;p&gt;Once the file was in the right place, you still need to run the powershell scripts the PS team provides to fix the Host and User File permissions(These are available in the directory where you installed OpenSSH). These are both very easy to run and should get you started quickly.    &lt;/p&gt;

&lt;p&gt;&lt;a href="http://feedproxy.google.com/~r/DotNetFromIndia/~3/lBZOQKtHGvA/open-ssh-on-windows.html"&gt;Original Post&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>windows</category>
    </item>
  </channel>
</rss>
