<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amit Jotwani on Medium]]></title>
        <description><![CDATA[Stories by Amit Jotwani on Medium]]></description>
        <link>https://medium.com/@amit?source=rss-d538bce230c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*75ozXSKdrPeimCAtQ6g18w.jpeg</url>
            <title>Stories by Amit Jotwani on Medium</title>
            <link>https://medium.com/@amit?source=rss-d538bce230c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:15:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amit/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Identity Crisis]]></title>
            <link>https://amit.medium.com/identity-crisis-85b09e5a86ab?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/85b09e5a86ab</guid>
            <category><![CDATA[work]]></category>
            <category><![CDATA[entrepreneur]]></category>
            <category><![CDATA[lifestyle]]></category>
            <category><![CDATA[self-employment]]></category>
            <category><![CDATA[business]]></category>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Thu, 23 Dec 2021 21:47:48 GMT</pubDate>
            <atom:updated>2021-12-23T21:47:48.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXz9aCQiJFfFDe2lDXFdwg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@brett_jordan?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit">Brett Jordan</a> / <a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit">Unsplash</a></figcaption></figure><h3>The “What do you do” Identity Crisis</h3><p>When you work for someone else, the first sentence of your answer to the question — <em>“what do you do?”</em> (and your Twitter bio) is more or less taken care of. It’s on your business card. It’s on the org-chart. That’s who you are.</p><p>They provide you with an identity. How gracious.</p><p><strong>They</strong>: “So, what do you do?”</p><p><strong>You:</strong> I am the Assistant Regional Manager at Dunder Mifflin (or is it assistant to the Regional Manager?)</p><p>It’s that simple. You don’t think about it. It’s just ingrained. It becomes your identity. It’s who you are.</p><h3>“Oh, you work at Amazon?”</h3><p>Working for a big and well known organization like Amazon also makes for “feel good” starter conversations with strangers.</p><p>You get in an Uber ride, and engage in a friendly conversation with the driver. It’s now only a matter of time before they pop the question — “<em>so, what do you do”.</em></p><p>For years, I had the response to this question locked and loaded in my brain. No thinking required. Fractions of a second later, I answer — <em>“I work at Amazon”</em>.</p><p>That’s usually met with some sort of excited response — “oh, you work at Amazon?”.</p><p>Sometimes that’s followed up with — <em>“what do you do at Amazon?”</em>. So glad you asked. I’ve got that pre-packaged and ready to go too — “I work on the Alexa team”.</p><p>More excitement, more Amazon related conversations.</p><p>End of ride. You feel good about yourself. It’s a dopamine hit for your self-esteem. It’s exhilarating. You tweet about it. You go on about your life. Rinse and repeat.</p><h3>But, if you take that away, who am I now?</h3><p>This is a really hard question to answer when you’re working for yourself.</p><p>One approach to answer that is the Tim Ferris approach — <em>“I am a drug dealer”. </em>End of conversation.</p><p>I am realizing that part of the game of working for yourself is to break that glass, and re-wire that identity.</p><p>So, who the fuck am I, and what do I do exactly?</p><p><em>Thank you for reading</em>. <em>If you enjoyed this post, you can find me on Twitter at </em><a href="https://twitter.com/amit"><em>@amit</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85b09e5a86ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Deep Dive: Using the Display Directives in the ASK SDK for Node.js]]></title>
            <link>https://amit.medium.com/code-deep-dive-using-the-display-directives-in-the-ask-sdk-for-node-js-5e18f6ff01eb?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e18f6ff01eb</guid>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[display]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[multimodal]]></category>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 15:05:19 GMT</pubDate>
            <atom:updated>2018-08-26T15:05:19.793Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*XOxKP-ROIyMahvV9tCHvzA.png" /><figcaption>This article was originally posted on <a href="https://developer.amazon.com/it/blogs/alexa/post/c9cca5f8-5528-4992-aa32-8d1199669735/code-deep-dive-using-the-display-directives-in-the-ask-sdk-for-node-js">Amazon Alexa Blog</a></figcaption></figure><p><em>We recently released </em><a href="https://developer.amazon.com/blogs/alexa/post/decb3931-2c81-497d-85e4-8fbb5ffb1114/now-available-version-2-of-the-ask-software-development-kit-for-node-js"><em>version two of the Alexa Skills Kit (ASK) Software Development Kit (SDK) for Node.js</em></a><em>, which introduced a fresh approach to handling requests and responses (among many other enhancements to the SDK). In our new code deep dive series, we’ll show you the ins and outs of the new SDK by providing a step-by-step code overview of the new features. We will also build a listening retention memory game skill from scratch, bit by bit, as we progress through the series.</em></p><p>In our <a href="https://developer.amazon.com/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">first code deep dive</a>, we covered the basic concepts of the new Alexa Skills Kit (ASK) Software Development Kit (SDK) for Node.js, like `canHandle()`, `handle()`, and Response Builder. In the <a href="https://developer.amazon.com/blogs/alexa/post/f167aa0f-8abe-4602-b985-65118b3032ca/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js">second deep dive</a>, we looked at how to capture customer input using slots and session attributes for persistence. We will use the <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/index.js">final code</a> from the last deep dive as the starting point for today’s post on display directives.</p><p>As a skill builder, you can choose whether or not to specifically support a particular interface, such as screen display. For the best customer experience, however, you should plan to create a conditional workflow so that customers who use devices without a screen, like Amazon Echo or Echo Plus can have an optimized experience, and so can the customers accessing your skill from Echo Show, Echo Spot, or Fire TV Cube. Even if the screen experience is not the focus of your skill, you should still think about how visual components could <a href="https://developer.amazon.com/blogs/alexa/post/05a2ea89-2118-4dcb-a8df-af3d8ac623a8/building-for-echo-show-and-echo-spot-vui-gui-best-practices">enhance your skill on devices with screens</a>.</p><p>This post will build on top of the last couple deep dives, and provide a step-by-step walkthrough for delighting your customers by providing a screen experience for your skill.</p><p>In this walkthrough we will show you how to:</p><ol><li>Detect if the device has display. We will use this <a href="https://developer.amazon.com/blogs/alexa/post/6839eb1c-f718-41cd-ad0c-6ba59c5360f5/alexa-skill-recipe-making-the-most-of-devices-that-support-display">Alexa skill recipe</a> to do this.</li><li>Use the display directives provided by the ASK SDK to display relevant information on the screen, such as a background image when the skill is launched on Echo Show, Echo Spot, Fire TV Cube, or any other Alexa-enabled device with a screen. Or, how to display the current score along with a picture on the screen after each question.</li></ol><p>Here’s an example of what those screens may look like on a square and a round display:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*B5fPX_7YoWMKqnhJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*yKFHsdwMSb1rqk2d.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*jNDebLjlTyVOaTfH.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*MKRhkoHtucSEyIvV.png" /></figure><p>Let’s get started.</p><h3>Step 0: Enable the Display Interface for Your Skill</h3><p>First, for your skill to be able to serve on display devices, you need to enable it through the Alexa Developer Console, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ou3dgYCuY5jtHXX8.png" /></figure><h3>Step 1: Check If the Device Has a Screen</h3><p>Let’s first write the code to check if the requesting device has a display screen. We will do that by writing a helper function, which we can call from all our handlers whenever needed. We will call this hasDisplay() -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*jydYh3mgYdHLdGYz.png" /></figure><h3>Step 2: Write a Helper Function to Create a Display</h3><p>Next, let’s write a helper function that we can call from our handlers after checking that the requesting device has display screen our skill can use. We will call this getDisplay().</p><p>To generate our display response, we use Alexa SDK’s built-in ImageHelper() and RichTextContentHelper() methods. You can learn more about the display directives <a href="https://developer.amazon.com/docs/custom-skills/display-interface-reference.html">here.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*q2shT7YVAUq2DKlb.png" /></figure><h3>Step 3: Set Up the Handlers to Use These Display Helper Functions</h3><p>In our LaunchRequestHandler, we first use the supportsDisplay() function to check if the device supports a display, and then create our response accordingly. If the requesting device does support a display, we use our getDisplay() function to generate our response, which includes a display screen.</p><p><strong>Inside LaunchRequestHandler</strong></p><p>Using BodyTemplate7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*fjVvd6CnmG2Ri0Za.png" /></figure><p><strong>Inside StoryHandler</strong></p><p>Same treatment as LaunchRequestHandler — we check if the device supports display, and then respond accordingly.</p><p>Using BodyTemplate2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*lObzHFu_rC5nyEj1.png" /></figure><p><strong>Inside AnswerHandler</strong></p><p>Same treatment as LaunchRequestHandler and StoryHandler — we check if the device supports display, and then respond accordingly.</p><p>Using BodyTemplate2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*OU_jDmnzLs5vwAMz.png" /></figure><p><strong>Inside FinalScoreHandler</strong></p><p>Same treatment as LaunchRequestHandler, StoryHandler, and AnswerHandler — we check if the device supports display, and then respond accordingly.</p><p>Using BodyTemplate7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*FBgPOxlQ68TfakfO.png" /></figure><h3>Start Building</h3><p>If you would like to build this skill with us throughout the series, follow the steps below to kick-start your skill:</p><ol><li>Create the skill in the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>.</li></ol><ul><li>Create a new skill at developer.amazon.com. Call it “Memory Challenge.”</li><li>Give it an invocation name of “memory game.”</li><li>Click on JSON Editor and paste this <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/interaction-model.json">interaction model</a>.</li><li>Click Save and Build Model.</li></ul><p><a href="https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/instructions/2-lambda-function.md">2. Follow the steps here</a> to create a new AWS Lambda function, and then paste <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/index.js">this final code</a> in the section titled Function Code.</p><p>3. In the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>, test your skill in the Test tab by typing the phrase “<em>open memory challenge</em>”</p><h3>Source Code for This Deep Dive</h3><ul><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-3/index.js">Final Code for the Lambda Function</a></li><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-3/interaction-model.json">Interaction Model for the Skill</a></li></ul><h3>More Resources</h3><ul><li><a href="https://developer.amazon.com/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">Code Deep Dive: Introduction to the ASK Software Development Kit for Node.js</a></li><li><a href="https://developer.amazon.com/blogs/alexa/post/f167aa0f-8abe-4602-b985-65118b3032ca/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js">Code Deep Dive: Slots and Session Attributes in the ASK SDK for Node.js</a></li><li><a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs">Alexa Skills Kit SDK for Node.js</a></li><li><a href="https://developer.amazon.com/blogs/alexa/post/6839eb1c-f718-41cd-ad0c-6ba59c5360f5/alexa-skill-recipe-making-the-most-of-devices-that-support-display">Alexa Skill Recipe: Making the Most of Devices That Support Display</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e18f6ff01eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Deep Dive: Slots and Session Attributes in the ASK SDK for Node.js]]></title>
            <link>https://amit.medium.com/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js-d2b388991c81?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2b388991c81</guid>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[persistence]]></category>
            <category><![CDATA[session-attribute]]></category>
            <category><![CDATA[memories]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 15:03:26 GMT</pubDate>
            <atom:updated>2018-08-26T15:03:26.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*XOxKP-ROIyMahvV9tCHvzA.png" /><figcaption>This article was originally posted on <a href="https://developer.amazon.com/it/blogs/alexa/post/f167aa0f-8abe-4602-b985-65118b3032ca/code-deep-dive-slots-and-session-attributes-in-the-ask-sdk-for-node-js">Amazon Alexa Blog</a></figcaption></figure><p><em>We recently released </em><a href="https://developer.amazon.com/blogs/alexa/post/decb3931-2c81-497d-85e4-8fbb5ffb1114/now-available-version-2-of-the-ask-software-development-kit-for-node-js"><em>version two of the Alexa Skills Kit (ASK) Software Development Kit (SDK) for Node.js</em></a><em>, which introduced a fresh approach to handling requests and responses (among many other enhancements to the SDK). In our new code deep dive series, we’ll show you the ins and outs of the new SDK by providing a step-by-step code overview of the new features. We will also build a listening retention memory game skill from scratch, bit by bit, as we progress through the series.</em></p><p>In our <a href="https://developer.amazon.com/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">first code deep dive</a>, we covered the basic concepts of the new ASK SDK for Node.js, like `canHandle()`, `handle()`, and Response Builder. Be sure to check out the <a href="https://developer.amazon.com/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">first post in this series</a>. We will use the <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-1/index.js">final code</a> from the last deep dive as the starting point for today’s post on slots and session attributes.</p><p>Today’s deep dive will teach you how to capture user input using slots and cater responses accordingly. You’ll also learn about session attributes and how to add request handlers for built-in intents like AMAZON.StartOverIntent, and AMAZON.YesIntent.</p><p>Here’s a scenario that shows the capabilities we want to build into our listening retention memory game skill with this deep dive:</p><p><strong><em>Customer:</em></strong><em> Alexa, ask Memory Challenge to start the challenge [This will trigger </em><strong><em>StartStoryIntent</em></strong><em>].</em></p><p><strong><em>Alexa:</em></strong><em> Welcome to Memory Challenge. I will read you a short passage, and then ask you questions based on that. Are you ready?</em></p><p><strong><em>Customer:</em></strong><em> Yes [This will trigger </em><strong><em>AMAZON.YesIntent</em></strong><em>].</em></p><p><strong><em>Alexa:</em></strong><em> Jeff loves sports. His favorite sports in the Olympics are ice skating and skiing for the Winter Olympics, and basketball and volleyball for the Summer Olympics. What are Jeff’s favorite games for the Winter Olympics?</em></p><p><strong><em>Customer:</em></strong><em> Skiing [This will trigger </em><strong><em>AnswerIntent</em></strong><em>].</em></p><p><strong><em>Alexa:</em></strong><em> Yup! Skiing is correct. Here’s your 2nd question — While traveling, Samantha likes to take her tooth brush, hair brush, face cream, and hair dryer. What does Samantha like to carry when she travels?</em></p><p><strong><em>Customer:</em></strong><em> Wallet [This will trigger </em><strong><em>AnswerIntent</em></strong><em>]</em></p><p><strong><em>Alexa:</em></strong><em> Nope! Wallet is incorrect.</em></p><p><em>….</em></p><p><em>….</em></p><p><strong><em>Alexa:</em></strong><em> Thank you for playing Memory Challenge. Your final score is 2 out of 5.</em></p><p>Before we begin writing code for our skill, it’s a good idea to think through the conversation, and determine the three main acts that our skill will be handling. Much like writing a script for a play or a movie, this exercise helps figure out the request handlers we would need. For example, the three main acts of our skill will be –</p><ul><li>Act 1: Read the Memory Challenge Story to the Customer (StoryHandler)</li><li>Act 2: Capture the Response from the Customer, and Check If the Answer is Correct (AnswerHandler)</li><li>Act 3: Get the Final Score (FinalScoreHandler)</li></ul><p>With that out of the way, let’s start building.</p><h3>Act 1: Read the Memory Challenge Story to the Customer</h3><p>We will start off by creating a new handler that will be responsible for reading the memory challenge stories to the customer. We’ll call it `StoryHandler`.</p><p><strong>Step 1: Add a new handler — StoryHandler</strong></p><p>As we did with the `LaunchRequestHandler`, we will start off with the basic scaffold for our new handler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/0*X3VLW_AmOAmKqOYV.png" /></figure><p><strong>Step 2: Set conditions for the requests this handler is capable of handling</strong></p><p>As we mentioned in the last deep dirve, in the new Alexa SDK, the request routing is based on a “can you handle this?” concept, which means that every handler lays out the specific condition/s that it is capable of handling.</p><p>Let’s think about the conditions for our StoryHandler here. As you can see from the conversation above, our skill should read a new question in the following scenarios:</p><ol><li>Customer starts the skill by saying, “Alexa, ask Memory Challenge to start the challenge.” This will trigger `StartStoryIntent`, and our skill should respond with a new question.</li><li>Customer launches the skill by saying, “Alexa, open Memory Challenge,” and then answers Yes (triggers `AMAZON.YesIntent`) to the welcome message prompt, <em>“Welcome to Memory Challenge. I will read you a short passage, and then ask you question based on that. Are you ready?”</em>. This will trigger `AMAZON.YesIntent`, and our skill should respond with a new question.</li><li>Mid-way through the skill, the customer asks to “start over”. This will trigger `AMAZON.StartOverIntent`, and our skill should respond with a new question.</li></ol><p>Because all of these scenarios require the same execution logic, we can merge them all together to be handled by our `StoryHandler` request handler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/0*vL-AXQBAcjdKePRU.png" /></figure><p><strong>Step 3: Add the logic that should execute if canHandle returns true</strong></p><p><strong><em>Get the story by calling the function getNextStory()</em></strong></p><p>As we established in the last step, if the canHandle() function returns true for `StoryHandler`, our skill should begin narrating the story. To get the story, we make a call to a little helper function `getNextStory()`, which returns the story to be narrated as an object of the form:</p><pre>```</pre><pre>{</pre><pre>  &quot;question&quot;:&quot;Jeff loves sports. His favorite sports in the Olympics are ice skating and skiing for the Winter Olympics, and basketball and volleyball for the Summer Olympics. What are John&#39;s favorite games for the Winter Olympics?&quot;,</pre><pre>  &quot;answer&quot;:[&quot;skating&quot;,&quot;ice skating&quot;,&quot;skiing&quot;]</pre><pre>}</pre><pre>```</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/0*8WTOyY9rh9kfkJme.png" /></figure><p><strong><em>Narrate the story to the customer by using the responseBuilder</em></strong></p><p>Next, we assign the question to the speechOutput variable, and generate a speech response by using the `speak()` method of `responseBuilder`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*j1_2twlfZQzdLRxV.png" /></figure><p><strong><em>Keep the session open</em></strong></p><p>Since we are expecting our customer to respond back, we add the `reprompt()` method to our responseBuilder. This will keep the session open for us, so the customer can respond back with an answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/0*tbBqzYnkhAR2rrJ0.png" /></figure><p><strong><em>Generate the JSON response</em></strong></p><p>Finally, we add the `getResponse()` method to generate the JSON response back with our `speechOutput`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*D4fUAxOSFIkTDmjJ.png" /></figure><h3>Act 2: Capture the Response from the Customer, and Check If the Answer is Correct</h3><p>We have accomplished the first act of our skill, which is to narrate the story to the customer. We are now ready for the second act, which is capturing the answer from the customer, checking if the answer is correct, and responding back accordingly. Then, asking the next question.</p><p><strong>Step 1: Set up a new handler — AnswerHandler</strong></p><p>Create a new handler called `AnswerHandler`. This will be used when the customer provides an answer to our question and will trigger the `AnswerIntent`.</p><p>Like we’ve done before, we start off by capturing the `request`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/0*q_0uxkfemGgN1m5G.png" /></figure><p><strong>Step 2: Set conditions for the requests this handler is capable of handling</strong></p><p>This will be a pretty straight forward canHandle() function. We just need to check if the intent name is `AnswerIntent`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*SiYw-WjW9rYSb7NO.png" /></figure><p><strong>Step 3: Capture User Input and respond back</strong></p><p><strong><em>Get session attributes</em></strong></p><p>We will be using session attributes to keep track of session-level data, like counter, number of correct answers, last question asked, etc. We will use attributes manager provided by the SDK to get and set the session attributes using the attributes manager’s `getSessionAttributes`, and `setSessionAttributes` methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/0*TKLp5w0PeePBNOff.png" /></figure><p><strong><em>Capture the user input through the answer slot</em></strong></p><p>We navigate through the JSON request sent to our skill, and grab the user input provided through the `answer` slot defined in our interaction model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*LnlS6X84wxHIMcYw.png" /></figure><p><strong><em>Check answer</em></strong></p><p>We use our helper function `checkAnswer()` to check if the answer provided by the customer (answerSlot) matches the correct answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/0*glwkiPmzCU_WRWuR.png" /></figure><p><strong><em>Get the next story</em></strong></p><p>We then get the next story using our helper function `getNextStory()`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*GT5NYJWgnf6mkt0a.png" /></figure><p>Let’s take a quick diversion to take a look at the `getNextStory` function. As you can see in the code below, we set up some attributes that will come in handy for us to keep track of number of questions asked (`attributes.counter`), number of correct (`attributes.correctCount`), number of incorrect answers (`attributes.wrongCount`). We increment these counters accordingly in the `<a href="https://github.com/ajot/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/index.js#L105">checkAnswer</a>()` function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*rnsTJpZtBqTG6pF5.png" /></figure><p><strong><em>Generate speechOutput using session attributes</em></strong></p><p>Back in the AnswerHandler, we set up the speechOutput to read the result of the answer (correct/incorrect) as returned by the `checkAnswer()` function. We also pull the counter from the session attributes and include that in our response.</p><pre>```<strong>const</strong> speechOutput = result.message + &quot;Here&#39;s your &quot; + (attributes.counter + 1) + &quot;th question - &quot; + story.question;```</pre><p>Respond back with the status of the answer, and then the question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qjPPvDtHtM0XfNZr.png" /></figure><p><strong><em>Store the result of the last question in session attributes</em></strong></p><p>We store the result of the last question as a session attribute, and call attributes manager’s setSessionAttributes() method to save the attributes, so they’re available in the next interaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gcym3YTX4MXPlQ1k.png" /></figure><p><strong><em>Generate the JSON response</em></strong></p><p>Since we are expecting the customer to respond back, we add the `reprompt()` method to our `responseBuilder`. This will keep the session open for us, so the customer can respond back with an answer. Finally, we add the `getResponse()` method to generate the JSON response back with our `speechOutput`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HA8kWAfuEuIpMpQ2.png" /></figure><h3>Act 3: Get the Final Score</h3><p>We will be using the session attribute counter (`attributes.counter`) to determine if the last question has been asked, which would mean that our skill should now respond with the final score. To deal with that, we will add one more handler — FinalScoreHandler, and add a condition to check if the number of questions asked (`attributes.counter`) equals the total number of questions available. If yes, we respond back with the final score.</p><p><strong><em>Set up the FinalScoreHandler</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/0*-uD6OW5_F147VaG8.png" /></figure><p><strong><em>Add counter condition to AnswerHandler</em></strong></p><p>If the counter is not equal to the number of questions yet, Alexa should hit the `AnswerHandler` again. But, to make sure that happens, we will make a small change to our condition for `AnswerHandler` — check if the number of questions asked (`attributes.counter`) is less than the total number of questions available.</p><p>We will be using session attributes to keep track of session-level data, like counter, number of correct answers, last question asked, etc. We will use attributes manager provided by the SDK to get and set the session attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j9RP729pKhCtxZXO.png" /></figure><h3>Start Building</h3><p>If you would like to build this skill with us throughout the series, follow the steps below to kick-start your skill:</p><ol><li>Create the skill in the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>.</li></ol><ul><li>Create a new skill at developer.amazon.com. Call it “Memory Challenge.”</li><li>Give it an invocation name of “memory game.”</li><li>Click on JSON Editor and paste this <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/interaction-model.json">interaction model</a>.</li><li>Click Save and Build Model.</li></ul><p><a href="https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/instructions/2-lambda-function.md">2. Follow the steps here</a> to create a new AWS Lambda function, and then paste <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/index.js">this final code</a> in the section titled Function Code.</p><p>3. In the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>, test your skill in the Test tab by typing the phrase “<em>open memory challenge</em>”</p><h3>Source Code for This Deep Dive</h3><ul><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/index.js">Final code for the Lambda function</a></li><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-2/interaction-model.json">Interaction model for the skill</a></li></ul><h3>More Resources</h3><ul><li><a href="https://developer.amazon.com/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">Code Deep Dive: Introduction to the ASK Software Development Kit for Node.js</a></li><li><a href="https://developer.amazon.com/blogs/alexa/post/9ec7c7d2-a937-4676-b936-48dd2abd0f66/what-s-new-with-request-handling-in-the-alexa-skills-kit-sdk-for-node-js">What’s New with Request Handling in the Alexa Skills Kit SDK for Node.js</a></li><li><a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs">Alexa Skills Kit SDK for Node.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2b388991c81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Deep Dive: Introduction to the Alexa Skills Kit SDK for Node.js]]></title>
            <link>https://amit.medium.com/code-deep-dive-introduction-to-the-alexa-skills-kit-sdk-for-node-js-16a48d565e6f?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a48d565e6f</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[alexa-skills-kit]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 14:58:56 GMT</pubDate>
            <atom:updated>2018-08-26T15:00:09.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*XOxKP-ROIyMahvV9tCHvzA.png" /><figcaption>This article was originally posted on <a href="https://developer.amazon.com/it/blogs/alexa/post/dff6f892-ee90-4fef-954f-27ad84eb7739/code-deep-dive-introduction-to-the-ask-software-development-kit-for-node-js">Amazon Alexa Blog</a></figcaption></figure><p><em>We recently released </em><a href="https://developer.amazon.com/blogs/alexa/post/decb3931-2c81-497d-85e4-8fbb5ffb1114/now-available-version-2-of-the-ask-software-development-kit-for-node-js"><em>version two of the Alexa Skills Kit (ASK) Software Development Kit (SDK) for Node.js</em></a><em>, which introduced a fresh approach to handling requests and responses (among many other enhancements to the SDK). In our new code deep dive series, we’ll show you the ins and outs of the new SDK by providing a step-by-step code overview of the new features. We will also build a new skill from scratch, bit by bit, as we progress through the series.</em></p><p>Throughout this series, we will create a listening retention memory game skill that will help customers improve their listening skills in a fun way. Alexa will read a short passage and then ask customers one or more questions related to that passage. Alexa will generate the passages at random. If customer gets a question right, they get points! Eventually they could earn badges and other engaging experiences along the way.</p><p>Here’s a sample conversation we want to build:</p><p><strong><em>Customer:</em></strong> <em>Alexa, open Memory Challenge.</em></p><p><strong><em>Alexa:</em></strong> <em>Welcome to Memory Challenge. I will read you a short passage, and then ask you question based on that. Are you ready?</em></p><p><strong><em>Customer:</em></strong> <em>Yes.</em></p><p><strong><em>Alexa:</em></strong> <em>Ok. Here we go. John loves sports. His favorite sports in the Olympics are ice skating and skiing for the Winter Olympics, and basketball and volleyball for the Summer Olympics. What are John’s favorite games for the Winter Olympics?</em></p><p><strong><em>Customer:</em></strong> <em>Ice skating and skiing.</em></p><p><strong><em>Alexa:</em></strong> <em>Bingo! That’s right. Do you want to continue?</em></p><p><strong><em>Customer:</em></strong> <em>Yes.</em></p><p>As we build the skill, we will add features to it gradually, testing each one along the way. For the first code deep dive, we will build the scaffold for our skill using the new request handling features in version two of the ASK SDK for Node.js. You can <a href="https://developer.amazon.com/blogs/alexa/post/9ec7c7d2-a937-4676-b936-48dd2abd0f66/what-s-new-with-request-handling-in-the-alexa-skills-kit-sdk-for-node-js">learn about the request handling features here</a> and then read the rest of this blog post to see those features and concepts implemented as we write the code from scratch for our AWS Lambda function, which will serve as the backend for requests coming to our skill.</p><p>We have one main objective for this code deep dive–when customers start the skill by saying, “Alexa, open memory challenge,” we want the skill to respond with a welcome greeting like the one we included in the conversation above (“Welcome to memory challenge…”).</p><p>This deep dive will teach you how to build request handlers for incoming requests using canHandle() and handle() methods. You’ll also learn how to register the request handlers. Let’s start building.</p><h3>Step 1: Include the ASK SDK</h3><p>Since we’ll be using version two of the ASK SDK for Node.js to write this Lambda function for our skill, the first thing we’ll do is use JavaScript’s require function to include the core ASK SDK module in our Lambda function. The Core Alexa SDK module provides us everything we need to get our skill started. As we expand the functionality of our skill in future deep dives, we will look into <a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/wiki/Setting-Up-The-ASK-SDK">other flavors</a> of the ASK SDK for Node.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/0*7cVb68G_06BRmxPs.png" /></figure><h3>Step 2: Write Your First Handler to Handle the Request of Type LaunchRequest</h3><p>When a customer starts your skill by saying, “open memory challenge,” your skill receives a request of type “LaunchRequest.”</p><p>To handle this request, wecreate a new object called LaunchRequestHandler. You can name it whatever you want but give it a name that’s related to the kind of requests it’s capable of handling for easy recall. For example, in our case, we name it LaunchRequestHandler, since it would be doing just that–handling launch requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*h2s8Rm7jwrX70k3d.png" /></figure><h3>Step 3: Set Conditions for the Requests This Handler Can Handle</h3><p>This is probably the most significant change compared to the previous version of the ASK SDK. In the new SDK, the request routing is based on a “<em>can you handle this</em>?” concept, which means that every handler lays out the specific condition/s that it is capable of handling. This is done within the canHandle() function defined inside the handler. This function is required in every handler. As we will see in later installments of this series, this lets you write a single handler for multiple intents, or handlers that check for other values, like <a href="https://developer.amazon.com/blogs/alexa/post/08edaa00-59e2-46b7-aace-4080f2a87450/using-session-attributes-in-your-alexa-skill-to-enhance-the-voice-experience">session attributes</a>.</p><p>The second piece to this is the handle() function, which includes the execution logic for the handler. If the condition/s set in the canHandle() function return true, the code included in the handle() function is executed. If not, the search for the appropriate handler continues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*KW-x_JWlg9Rza7vF.png" /></figure><h3>Step 4: Grab the Request</h3><p>When a customer interacts with an Alexa skill, your service (Lambda function) receives a POST request containing a JSON body. This request body contains the parameters we would need to figure out what the customer is asking for and is made available by the SDK to all request handlers through a <em>HandlerInput</em> object.</p><p>Here’s an example of what the HandlerInput object may look like for a LaunchRequest:</p><pre>{<br>    &quot;requestEnvelope&quot;: {<br>        &quot;version&quot;: &quot;1.0&quot;,<br>        &quot;session&quot;: {<br>          . . .<br>          . . .<br>        },<br>        &quot;context&quot;: {<br>          . . .<br>          . . .<br>        },<br>        &quot;request&quot;: {<br>            &quot;type&quot;: &quot;LaunchRequest&quot;,<br>            &quot;requestId&quot;: &quot;amzn1.echo-api.request.403abfd8-625c-4717-94e3-76c20e449c7a&quot;,<br>            &quot;timestamp&quot;: &quot;2018-05-24T02:35:25Z&quot;,<br>            &quot;locale&quot;: &quot;en-US&quot;,<br>            &quot;shouldLinkResultBeReturned&quot;: false<br>        }<br>    },<br>    &quot;context&quot;: {<br>      . . .<br>      . . .<br>    },<br>    &quot;attributesManager&quot;: {},<br>    &quot;responseBuilder&quot;: {}<br>}</pre><p>What we are interested in is the request object inside requestEnvelope in HandlerInput object. We grab that and assign it to a variable named <em>request</em>. We will use this variable to set our “can you handle this” conditions for our LaunchRequestHandler in the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*mGUqkz1eX2sBD8fm.png" /></figure><h3>Step 5: Add the Conditions This Handler Can Handle</h3><p>Next, we set the conditions. We want this handler to execute if the request type is a LaunchRequest. Remember for the handler to execute the logic inside the handle() function, the canHandle() function must return true. We return true if the request type is a ‘LaunchRequest’ (you can review the sample request JSON above to see that the request type for that example is in fact LaunchRequest).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/0*9o2YwUGWKIyLeAcC.png" /></figure><h3>Step 6: Add the Logic That Should Execute if canHandle Returns True</h3><p>Let’s add the logic for our request handler inside the handle() function. If the request is a LaunchRequest, that means that the customer has asked the skill to be launched, without a specific request to a functionality within the skill, so we should probably welcome the customer with a welcome message and tell them briefly what the skill can do.</p><p>We generate a speech response by using the speak() method of responseBuilder. The responseBuilder is a helper function provided by the ASK SDK and is used to generate all kinds of responses back to the customer (speech, cards, images, plain text and rich text for devices with display). We will dive deep into ResponseBuilder in the future code walkthroughs, but for now we will use the .speak() method to generate the welcome message speech and then use the .getResponse() method to package that into a JSON response and send it back to the customer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/0*Nzn4y_gn5JfW0Nk8.png" /></figure><p>Let’s refactor that a bit to improve readability:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/0*L9w9Dp5xTXCZIC9G.png" /></figure><h3>Step 7: Create the skillBuilder Object</h3><p>We are almost done with our basic version of the skill. All we need to do now is create an instance of the skill. There are a few different skill builders you can use depending on the features your skill needs. Because our skill is fairly straightforward, we will use CustomSkillBuilder. You can read more about other skill builders available <a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/wiki/Skill-Builders">here.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Ver_IBmR455KA1sz.png" /></figure><h3>Step 8: AWS Lambda Function Handler (exports.handler)</h3><p>Since we are using AWS Lambda to host our skill code, we need to create handler object (exports.handler), which will serve as the entry point that AWS Lambda will use to execute our function code.</p><p>To ensure that this AWS Lambda entry point is aware of the names of all our request handlers, we register them by using skill builder’s built-in addRequestHandlers() method. Since we only have one request handler for now, LaunchRequestHandler, we add that. You will notice in future code deep dives as we add more request handlers that the order in which you type them inside the addRequestHandlers matters. It starts with the first handler and goes down the list asking the question “can you handle this” until it gets to a request handler that returns true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*RLKV1WzyBhgCqauG.png" /></figure><h3>Step 9: Get Your Code Ready for AWS Lambda</h3><p>Finally, we call the .lambda(), and pass it the handler object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/0*U17euaWX1N6Yyyvy.png" /></figure><h3>Start Building</h3><p>Now we’ve created a basic scaffold for our skill. If you would like to build this skill with us throughout the series, follow the steps below to kick-start your skill:</p><ol><li>Create the skill in the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>.</li></ol><ul><li>Create a new skill at developer.amazon.com. Call it “Memory Challenge.”</li><li>Give it an invocation name of “memory game.”</li><li>Click on JSON Editor and paste this <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-1/interaction-model.json">interaction model</a>.</li><li>Click Save and Build Model.</li></ul><p><a href="https://github.com/alexa/skill-sample-nodejs-fact/blob/en-US/instructions/2-lambda-function.md">2. Follow the steps here</a> to create a new AWS Lambda function, and then paste <a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-1/index.js">this final code</a> in the section titled <strong>Function Code</strong>.</p><p>3. In the <a href="https://developer.amazon.com/alexa/console/ask">Alexa Developer Console</a>, test your skill in the Test tab by typing the phrase “<em>open memory challenge</em>”</p><h3>Source Code for This Deep Dive</h3><ol><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-1/index.js">Final code for the Lambda function</a></li><li><a href="https://github.com/alexa/alexa-guided-walkthrough-using-node-sdk/blob/master/part-1/interaction-model.json">Interaction model for the skill</a></li></ol><h3>What’s Next</h3><p>In the next code deep dive, we will add some more request handlers to our skill to handle customer requests like, “Alexa, ask memory challenge to start a nerdy memory challenge.” We will be using slots to accept customer input and cater our responses accordingly.</p><h3>More Resources</h3><ul><li><a href="https://developer.amazon.com/blogs/alexa/post/9ec7c7d2-a937-4676-b936-48dd2abd0f66/what-s-new-with-request-handling-in-the-alexa-skills-kit-sdk-for-node-js">What’s New with Request Handling in the Alexa Skills Kit SDK for Node.js</a></li><li><a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs">Alexa Skills Kit SDK for Node.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a48d565e6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa Skill Recipe: Making HTTP Requests to Get Data from an External API]]></title>
            <link>https://amit.medium.com/alexa-skill-recipe-making-http-requests-to-get-data-from-an-external-api-3daf909f4c30?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3daf909f4c30</guid>
            <category><![CDATA[amazon-alexa]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[alexa]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 20:14:19 GMT</pubDate>
            <atom:updated>2018-04-04T20:14:19.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*XOxKP-ROIyMahvV9tCHvzA.png" /><figcaption>This article was originally posted on <a href="https://developer.amazon.com/blogs/alexa/post/a9ef18b2-ef68-44d4-86eb-dbdb293853bb/alexa-skill-recipe-making-http-requests-to-get-data-from-an-external-api">Amazon Alexa Blog</a></figcaption></figure><p>As a developer, every day you interact with remote APIs and web servers. Almost all services we consume on the internet today are available in the form of an API: weather forecasts, geolocation services, Twitter feeds, and so on. When creating a skill, you are sure to run into situations in which you would want to get meaningful data from one of these remote sources by making HTTP requests to their APIs. HTTP requests allow you to fetch data from a remote source. It could be an API, a website, or something else.</p><p>Making HTTP requests is a core functionality for modern languages, and when it comes to Node.js there are a fair amount of solutions to this problem, both built into the language and by the developer community. In this skill recipe, we look at two of the most popular methods you can use to call an external API through your Alexa skill using Node.js:</p><ul><li><strong>Recipe 1</strong>: Using the built-in <strong>“HTTP”</strong> or <strong>“HTTPS”</strong> modules in the standard library</li><li><strong>Recipe 2:</strong> Using the <strong>“Request”</strong> module</li></ul><p>We’ll look at both of these recipes to cook up some API integration into our skill. We will also look at the pros and cons of each approach.</p><h3>Adding an HTTP Request to a Fact Skill</h3><p>First, we’ll take this <a href="https://github.com/alexa/skill-sample-nodejs-fact">simple fact skill</a> (written in Node.js), and modify the use case slightly to get facts about numbers (instead of space facts). Instead of using the hard-coded data as shown below, we will get the facts in real time by calling the simple (yet awesome) <a href="http://numbersapi.com/">numbersapi.com</a>, which is an API that offers interesting facts about numbers. You can give it a try in the browser by typing: <a href="https://numbersapi.com/21.">https://numbersapi.com/21.</a></p><p>Here’s the kind of conversation we want to serve with this skill:</p><p><strong><em>User:</em></strong><em> Alexa, ask number facts to give me a fact about 7 &lt;Triggers the intent GetNumberFactIntent, and passes the number 7 as an AMAZON.NUMBER slot type&gt;</em></p><p><strong><em>Alexa:</em></strong><em> 7 is the number of main stars in the constellations of the Big Dipper and Orion. &lt;Our skill calls </em><a href="http://numbersapi.com/"><em>numbersapi.com</em></a><em> with </em><a href="https://numbersapi.com/7,"><em>https://numbersapi.com/7,</em></a><em> and responds back with the fact&gt;</em></p><p>This is what our code looks like with facts hard-coded into the skill:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8197b3be4da8a44ce62b4ff30b2b97fc/href">https://medium.com/media/8197b3be4da8a44ce62b4ff30b2b97fc/href</a></iframe><p><em>Your intent handler “GetNumberFactIntent” would then call upon the dataset above when triggered by the user:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44d2d5038d9d5ded9efb892e8f337b7a/href">https://medium.com/media/44d2d5038d9d5ded9efb892e8f337b7a/href</a></iframe><p>Let’s now look at the Alexa recipes we can use to call our API to get facts about numbers dynamically.</p><h3>Recipe 1: Using the Built-In “HTTP” Module in the Standard Library</h3><p>Let’s begin by taking a quick look at our existing code for the <em>GetNumberFactIntent</em> above that gets fired when the user asks for a fact about a number.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44d2d5038d9d5ded9efb892e8f337b7a/href">https://medium.com/media/44d2d5038d9d5ded9efb892e8f337b7a/href</a></iframe><p>As you can see on line 2 and 3 in the code for our <em>GetNumberfactIntent</em> handler above, we are passing the value of the number we received through our slot to the numberFacts object we looked at earlier to get our fact. Let’s now replace this line with our helper function, which will call <a href="http://numbersapi.com/">numbersapi.com</a> and get the fact about the number on the fly.</p><p><strong>Step 1: Include the http module in our skill using the require statement.</strong></p><p>Since <a href="http://numbersapi.com/">numbersapi.com</a> supports only HTTP calls, we are including only the HTTP library. Most APIs, however will support HTTPs, in which case you should include ‘HTTPS’ as well (require(‘https’).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7fd1489526e11113fbe5ede21298c1b/href">https://medium.com/media/d7fd1489526e11113fbe5ede21298c1b/href</a></iframe><p><strong>Step 2: Include this helper function in your skill code to make HTTP calls to REST APIs.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/247860f9dc4b10ca19fdd369ce6815cc/href">https://medium.com/media/247860f9dc4b10ca19fdd369ce6815cc/href</a></iframe><p>Let’s quickly run though what’s happening in this code: First, we prepare the options to send on to the HTTP call — we set up the host URI, the path, which is built using the number we receive from the user (<em>query</em>). So, if the user says “give me a fact about 21,” the number 21 is captured through our number slot (AMAZON.NUMBER slot type), and is passed on to the httpGet function wrapped inside the variable <em>query</em>. This code will make an HTTP GET request to the URI numbersapi.com/21. You can try this URL in your browser to see the result: <a href="http://numbersapi.com/42">http://numbersapi.com/42</a>.</p><p>Then, we need to set up the HTTP request by calling the <em>http.request</em> method, and passing it the options we just set up. Since we are using Node.js, all of the functionality is handled asynchronously, which means we need to set up handlers within our httpGet function to accept incoming data, as well as to deal with the response once it’s complete. In this case, incoming data is simple. We just have to accept the data and concatenate it onto a string (responseString). Once the data return is complete, we call our callback function with this response.</p><p><strong>Step 3: Finally, call the helper function from within your intent.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80f6f90f4bf849fdc69dea4be0f713ee/href">https://medium.com/media/80f6f90f4bf849fdc69dea4be0f713ee/href</a></iframe><p>We call our <em>httpGet</em> helper function from our intent handler (GetNumberFactIntent) by passing it the number we received from the user (<em>query</em>). Once, we receive the result, we use some console.log statements to log the response to CloudWatch, in case we need it to debug our code, and then finally we generate the speech response for the user through <em>this.response.speak.</em></p><p><strong>Pros and Cons of Using “HTTP” Module to Call an API from Your Alexa Skill</strong></p><p>The main advantage of using the HTTP module is that there is no need to install external dependencies. It’s a built-in module part of the standard library, so you can just plug and play. If you are using AWS Lambda to host your skill code, this also means that you can make changes to your code by using the inline editor provided by the AWS Lambda console, without needing to upload the dependencies as a zip file to your Lambda function, which certainly comes pretty handy if you don’t like working with the command line.</p><p>While the HTTP module can do everything, the downside is that it can feel a bit clumsy to use. Much of the HTTP, and the HTTPS, module’s functionality is fairly low-level. You’re required to receive response data in chunks rather than just providing a callback function to be executed as soon as all of the data is received. You also need to parse the response data manually. This is fairly easy if the data returned by the API is in the JSON format, but it is still an extra step.</p><h3>Recipe 2: Using the “Request” Module</h3><p>The Request module is one of the most popular NPM module for making HTTP requests. It supports both HTTP and HTTPS and follows redirects by default. Behind the scenes, it actually uses the http module and adds a bit of magic to make it easier to use. A lot of common cases can be handled with just a tiny bit of code. The downside of using the “Request” module is that it’s not something that’s built-in to the standard library, and needs to be <a href="https://www.npmjs.com/package/request">installed</a> using npm, the default package manager for Node.js.</p><p>Having said that, as you expand the functionality of your skill, you will find yourself the need to use even more external modules, available through npm, like the `<em>aws-sdk</em>` module that makes it easy to work with the AWS services like Lambda, S3, Amazon DynamoDB, and more. This means that eventually you’d graduate to using this approach one way or the other. So, this isn’t really a disadvantage in the long run.</p><p>Let’s see how we can modify the code to use the “Request” module to call our API.</p><p><strong>Step 1: Include the request module in our skill using the require statement.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6cfa7544e98d883d3550711b507cef0/href">https://medium.com/media/b6cfa7544e98d883d3550711b507cef0/href</a></iframe><p><strong>Step 2: Call the request.get() method from within your intent</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5837cd8028c9eaeefb1042fe2109c57/href">https://medium.com/media/a5837cd8028c9eaeefb1042fe2109c57/href</a></iframe><p>As you can see, the “request” module makes it super simple for us to call our API. All we had to do was specify the URL for the API to be called, and the response is made available to us inside the object body, which we can then parse and use as part of our response.</p><p>The next step after this would be to zip up your index.js file along with other modules to create a deployment package and upload it to your Lambda function. To learn more about how to do that, read <a href="https://developer.amazon.com/docs/custom-skills/deploy-a-sample-skill-to-aws-lambda.html#preparing-a-nodejs-sample-to-deploy-in-lambda">Prepare a Node.js Sample to Deploy in Lambda</a>.</p><h3>Choosing Your Recipe</h3><p>You can obviously choose to use either of the recipes depending on your use case. A good rule of thumb to consider is that if your skill is using other external modules already, it may make sense to use the “requests” module and make your code simpler to read and easier to maintain. If, however, your skill is not using any other external modules and you don’t mind the extra bit of complexity in your code, you can stick with the “HTTP” module approach.</p><p>For more such recipes, see <a href="https://developer.amazon.com/blogs/alexa/tag/Skill+Recipe">Alexa Recipes</a> on Amazon Alexa Blog, or visit the <a href="https://github.com/alexa/alexa-cookbook">Alexa Skill-Building Cookbook</a> on GitHub.</p><h3>More Resources</h3><ul><li><a href="https://developer.amazon.com/post/Tx1UE9W1NQ0GYII/Publishing-Your-Skill-Code-to-Lambda-via-the-Command-Line-Interface">Publishing Your Skill Code to Lambda via the Command Line Interface</a></li><li><a href="https://developer.amazon.com/docs/smapi/quick-start-alexa-skills-kit-command-line-interface.html">Quick Start Alexa Skills Kit Command Line Interface (ASK CLI)</a></li><li><a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs">Alexa Skills Kit SDK for Node.js</a></li><li><a href="https://aws.amazon.com/sdk-for-node-js/">AWS SDK for JavaScript in Node.js</a></li><li><a href="https://www.npmjs.com/package/request">Request Simplified HTTP client</a></li><li><a href="https://developer.amazon.com/docs/custom-skills/send-the-user-a-progressive-response.html">Send the User a Progressive Response</a></li></ul><h3>Build Engaging Skills, Earn Money with Alexa Developer Rewards</h3><p>Every month, developers can earn money for eligible skills that drive some of the highest customer engagement. Developers can increase their level of skill engagement and potentially earn more by improving their skill, building more skills, and making their skills available in in the US, UK and Germany.<a href="https://developer.amazon.com/alexa-skills-kit/rewards"> Learn more</a> about our rewards program and start building today.<a href="https://developer.amazon.com/alexa-skills-kit/guide/build-engaging-skills"> Download our guide</a> or watch our<a href="https://attendee.gotowebinar.com/register/4673294238964482305"> on-demand webinar</a> for tips to build engaging skills.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3daf909f4c30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hanging up the Devangelist boots]]></title>
            <link>https://amit.medium.com/hanging-up-the-devangelist-boots-55bf0fbb9c7?source=rss-d538bce230c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/55bf0fbb9c7</guid>
            <dc:creator><![CDATA[Amit Jotwani]]></dc:creator>
            <pubDate>Thu, 11 Jun 2015 18:55:31 GMT</pubDate>
            <atom:updated>2015-06-11T18:57:29.121Z</atom:updated>
            <content:encoded><![CDATA[<h4>This Monday was my last day at Intel <a href="http://mashery.com/">Mashery</a>.</h4><p>It started off with this tweet back in 2011, when I was introduced to <a href="http://twitter.com/delynator">Delyn Simons</a> by my friend — <a href="http://twitter.com/johndbritton">John Britton</a>.</p><h3>John Britton on Twitter</h3><p>Who needs a front-end developer in NYC? I&#39;ve got a friend with some pretty sick design and coding skills looking for a gig.</p><p>Delyn, along with my now friend <a href="http://twitter.com/mansillaDev">Neil Mansilla</a>, were sowing seeds for Mashery’s <a href="http://developer.mashery.com/">Developer Outreach</a> team. They were looking for a Developer Evangelist in New York, who would double up as a front-end developer.</p><h3>Solving the Developer pain</h3><p>I loved the opportunity to serve the developer community, by offering them such a <a href="http://developer.mashery.com/apis">wide variety of APIs</a> to play with, and keep my roots as a developer alive. During the interview process, I remember saying to Neil —</p><blockquote>“I would give my right arm to get this role.”</blockquote><h3>I’ve been spoilt</h3><p>I’ve been lucky enough to have been part of an agile high functioning team. It has been the epitome of what a small but determined team can accomplish with sheer perseverance, and focus. For that, I thank <a href="http://twitter.com/delynator">Delyn Simons</a> for being an inspiring leader &amp; an amazing mentor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*piwwcwvzE6Tp5Fu7ousBFA.jpeg" /><figcaption>Team DevO (2009–2015)</figcaption></figure><h4>Thank you again for all the wonderful moments &amp; memories, MashTeam</h4><p>Being a Developer Evangelist, and then eventually leading product at <a href="http://hackerleague.org/">Hacker League</a> have been the most fun, rewarding, and learning periods of my career. I owe a great deal of that to all the amazing folks I’ve met and become friends with — both inside and outside the company.</p><h3>What’s Next</h3><p>Over <a href="http://masherydev.tumblr.com/tagged/@amit">150</a> Hackathons &amp; Developer Conferences later it’s time for me to move on and look for new challenges. Am not certain what they are just yet, but am excited to embark on this journey of discovering the next cliff.</p><h4>It’s time to jump in the unknown waters again. It’s going to be fun.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55bf0fbb9c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>