<?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 Akshay Milmile on Medium]]></title>
        <description><![CDATA[Stories by Akshay Milmile on Medium]]></description>
        <link>https://medium.com/@akshay-milmile?source=rss-474401a14bd5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*XWWn9VqSckUPWVLiwymF5A.jpeg</url>
            <title>Stories by Akshay Milmile on Medium</title>
            <link>https://medium.com/@akshay-milmile?source=rss-474401a14bd5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:20:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshay-milmile/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[A Pinch of AI, a Dash of Code: Building a Recipe Chatbot with GPT-3 (yup, the same model that…]]></title>
            <link>https://akshay-milmile.medium.com/a-pinch-of-ai-a-dash-of-code-building-a-recipe-chatbot-with-gpt-3-yup-the-same-model-that-72c156c0e4c3?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/72c156c0e4c3</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[gpt-3]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Sat, 18 Mar 2023 13:20:47 GMT</pubDate>
            <atom:updated>2023-03-18T13:33:38.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmz6mUJNPmdiIOHYSIPQjQ.png" /></figure><h3>A Pinch of AI, a Dash of Code: Building a Recipe Chatbot with GPT-3 (yup, the same model that powers ChatGPT)</h3><p>GPT-3, or Generative Pre-trained Transformer 3, is an insanely powerful AI language model developed by OpenAI. Its ability to understand the context and generate human-like text based on prompts has taken the world by storm. GPT-3’s versatility and ease of use make it the perfect tool for creating chatbots tailored to your needs.</p><h3>GPT-3: A Beast of a Language Model</h3><p>GPT-3 is one of the most powerful language models on the planet. With a mind-boggling 175 billion parameters, it can understand and generate text with jaw-dropping coherence and versatility. From translation and summarization to question-answering and chatbots, GPT-3 is truly a force to be reckoned with.</p><h3>Creating a Chatbot that Cooks Up a Storm with GPT-3</h3><p>We’ll create a quirky chatbot called <em>RecipeRemixBot</em> using the GPT-3 model. RecipeRemixBot will whip up unique recipes based on the ingredients you throw at it. The code below will show you how to build this sizzling chatbot using Node.js:</p><pre>const { Configuration, OpenAIApi } = require(&quot;openai&quot;);<br>const readline = require(&quot;readline&quot;);<br><br>const rl = readline.createInterface({<br>  input: process.stdin,<br>  output: process.stdout,<br>});<br><br>const configuration = new Configuration({<br>  apiKey: process.env.OPENAPI_KEY,<br>});<br>const openai = new OpenAIApi(configuration);<br><br>async function askGPT3(prompt = &quot;coffee&quot;) {<br>  try {<br>    const response = await openai.createChatCompletion({<br>      model: &quot;gpt-3.5-turbo&quot;,<br>      messages: [<br>        {<br>          role: &quot;user&quot;,<br>          content: `Create a unique recipe using the following ingredients: ${prompt}`,<br>        },<br>      ],<br>    });<br>    return response.data.choices[0].message.content;<br>  } catch (error) {<br>    console.error(error);<br>  }<br>}<br><br>console.log(<br>  &quot;Welcome to the RecipeRemixBot! Enter your favorite ingredients, separated by commas, and press Enter to get a unique recipe.&quot;<br>);<br><br>rl.on(&quot;line&quot;, async (input) =&gt; {<br>  console.log(&quot;Fetching recipe&quot;);<br>  const response = await askGPT3(input);<br>  console.log(response);<br>  process.exit(0);<br>});</pre><p>This code sets up a command-line interface, initializes the OpenAI API with your API key, defines the function to send user inputs to the GPT-3 API, and unleashes the chatbot to handle user input.</p><p>I asked it to remix a recipe with the following ingredients:<br><em>gram flour, green chilies, coriander, cummin seed, oil, onion and whole lot of love<br></em>And it gave me a recipe for <em>Onion Bhaji, </em>😋 perfect for a rainy evening.</p><h3>GPT-3 vs. Other Chatbot Platforms: Clash of the Titans</h3><p>GPT-3 has several aces up its sleeve when compared to other chatbot platforms like Google Dialogflow. Its vast understanding of language and context allows it to generate more accurate and coherent responses. Moreover, GPT-3 can be quickly adapted to a wide range of use cases without extensive training or fine-tuning, making it a powerful and versatile tool for chatbot development.</p><h3>The Saga Continues: More Articles on the Horizon</h3><p>Hold on to your hats, because we’ll be diving deeper into the world of GPT-3 and other AI technologies in upcoming articles. We’ll explore customizing chatbots, optimizing performance, and integrating GPT-3 with other tools and platforms.</p><p>I would love feedback and what you expect from my next piece around GPT.</p><p>You can also check the code out here: <a href="https://replit.com/@AkshayMilmile/RecipeRemixBotWithGPT3">https://replit.com/@AkshayMilmile/RecipeRemixBotWithGPT3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72c156c0e4c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Downloading MLFlow model from Databricks and Serving with Docker]]></title>
            <link>https://akshay-milmile.medium.com/downloading-mlflow-model-from-databricks-and-serving-with-docker-710c1c275333?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/710c1c275333</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[mlflow]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Mon, 28 Dec 2020 19:53:22 GMT</pubDate>
            <atom:updated>2020-12-28T20:02:59.737Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are using Managed MLFlow in Databricks Workspace to train and save your models and can’t figure out how to download and serve the model outside the Databricks environment using Docker, you are in luck!</p><p>In this article, I will touch upon the following points:<br>- Downloading MLFlow model from Databricks workspace model registry<br>- Packaging downloaded model and serve it in a container using Docker</p><h3>Downloading MLFlow model from Databricks workspace</h3><p>Databricks provides the managed version of MLFlow to write our experiments in a notebook and register the model in the provided MLFlow registry.</p><p>We’ll use MLFlow’s Python API to download a model.</p><p>To download a model from Databricks workspace you need to do two things:<br>1. Set MLFlow tracking URI to databricks using <a href="https://www.mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_tracking_uri">python API</a><br>2. Setup databricks authentication. I prefer authenticating by setting the following environment variables, you can also use <a href="https://docs.databricks.com/dev-tools/cli/index.html#set-up-authentication">databricks CLI</a> to authenticate:</p><pre>DATABRICKS_HOST<br>DATABRICKS_TOKEN</pre><p>Here’s a basic code snippet to download a model from Databricks workspace model registry:</p><pre>import os<br>import mlflow<br>from mlflow.store.artifact.models_artifact_repo import ModelsArtifactRepository</pre><pre>model_name = “example-model-name”<br>model_stage = “Staging” # Should be either ‘Staging’ or ‘Production’</pre><pre>mlflow.set_tracking_uri(“databricks”)</pre><pre>os.makedirs(“model”, exist_ok=True)<br>local_path = ModelsArtifactRepository(<br> f’models:/{model_name}/{model_stage}’).download_artifacts(“”, dst_path=”model”)</pre><pre>print(f’{model_stage} Model {model_name} is downloaded at {local_path}’)</pre><p>Running the above python script will download an ML model in the model directory.</p><h3>Containerizing MLFlow model serving with Docker</h3><p>The next step is to package this downloaded model in a docker image and serve as a model when you run the image.</p><p>Here’s a basic Dockerfile to do the same:</p><pre>docker<br>FROM continuumio/miniconda3</pre><pre>ENV MLFLOW_HOME /opt/mlflow<br>ENV MLFLOW_VERSION 1.12.1<br>ENV PORT 5000</pre><pre>RUN conda install -c conda-forge mlflow=${MLFLOW_VERSION}</pre><pre>COPY model/ ${MLFLOW_HOME}/model</pre><pre>WORKDIR ${MLFLOW_HOME}</pre><pre>RUN mlflow models prepare-env -m ${MLFLOW_HOME}/model</pre><pre>RUN useradd -d ${MLFLOW_HOME} mlflow<br>RUN chown mlflow: ${MLFLOW_HOME}<br>USER mlflow</pre><pre>CMD mlflow models serve -m ${MLFLOW_HOME}/model — host 0.0.0.0 — port ${PORT}</pre><p>Few things to note from Dockerfile:<br>- We are using base image continuumio/miniconda3 because mlflow by default uses conda to install it’s dependencies while preparing environment for the model serving<br>- We are using non-root mlflow user with limited permissions to run mlflow models serve process in a secure way<br>- We are specifying host as 0.0.0.0 to listen on as default uses 127.0.0.1 which will not let us access the serving endpoint /invocations from outside container</p><h3>Wrapping up</h3><p>This is a very simple and minimal example of how you can use docker to serve the MLFlow model trained in Databricks workspace.<br>I hope this article will help you save time in connecting the dots in different documentations.<br>So that is it, fellas. Thank you for reading the article. Wish you a great day. Peace out ✌.</p><h3>Reference</h3><p><a href="https://www.mlflow.org/docs/latest/cli.html#mlflow-models-serve">https://www.mlflow.org/docs/latest/cli.html#mlflow-models-serve</a><br><a href="https://databricks.com/blog/2019/10/17/managed-mlflow-now-available-on-databricks-community-edition.html">https://databricks.com/blog/2019/10/17/managed-mlflow-now-available-on-databricks-community-edition.html</a><br><a href="https://docs.databricks.com/dev-tools/cli/index.html#set-up-authentication">https://docs.databricks.com/dev-tools/cli/index.html#set-up-authentication</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=710c1c275333" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a serverless service for “Contact Me” form in Golang and deploy on GCP]]></title>
            <link>https://medium.com/bit-shift/build-a-serverless-service-for-contact-me-form-in-golang-and-deploy-on-gcp-475e53aa6364?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/475e53aa6364</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Wed, 08 Jan 2020 11:28:28 GMT</pubDate>
            <atom:updated>2020-01-08T14:59:58.653Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3vJZpWteDBkxRVwBXVfKw.png" /></figure><p>“Contact me” forms are pretty common. You can use it for your portfolio website, contact section of your online business and so on.</p><p>This tutorial assumes our “Contact me” form has three fields: Name, Email, and Message. On hitting submit it will call a REST API which will trigger our GCP (Google Cloud Platform) function which in turn will forward above mentioned details to our email.</p><p>This tutorial will cover the following things:</p><ol><li>Setting up the code with <a href="https://serverless.com/">“Serverless Framework”</a> in Golang.</li><li>Configuring Twilio SendGrid API.</li><li>Prepare GCP resources.</li><li>Deploying the Golang code on Google Cloud Functions.</li></ol><h3>Setting up the code</h3><p>We are using the <a href="https://serverless.com/">“Serverless Framework”</a> to manage our function. In this tutorial, we will configure it to support GCP. But it’s very easy to change the provider to other platforms like AWS, Azure, etc.</p><p>If you don’t have “Serverless Framework” installed on your machine, let’s get it first by following below link (just install it, no need to login):</p><p><a href="https://serverless.com/framework/docs/getting-started/">Serverless Getting Started Guide</a></p><p>Create the codebase:</p><pre>$ cd to/desired/location/in/GOPATH</pre><pre>$ serverless create --template google-go --name contactmebackend --path contactmebackend</pre><p>Next, install the plugin required for GCP (I’m using yarn, feel free to use NPM):</p><pre>yarn add serverless-google-cloudfunctions</pre><p>You will get the following files under contactmebackend the directory:</p><pre>Makefile<br>fn.go<br>fn_test.go<br>node_modules<br>package.json<br>serverless.yml<br>yarn.lock</pre><p>We will use Twilio’s SendGrid API to send the information coming from REST API to our email address. SendGrid has a Golang package to interact with its API. Since we will be deploying this code to GCP functions later, we will need to setup <a href="https://github.com/golang/go/wiki/Modules">Golang module</a> so that GCP can figure out the external dependencies. Follow these steps to do just that:</p><pre>$ export GO111MODULE=on<br>$ go mod init<br>$ go get -u github.com/sendgrid/sendgrid-go</pre><p>Edit fn.go with the following code. I have provided comments to better understand the code (don’t forget to replace it with your name and email id):</p><pre>package contactmebackend</pre><pre>import (<br>&quot;encoding/json&quot;<br>&quot;log&quot;<br>&quot;net/http&quot;<br>&quot;os&quot;</pre><pre>&quot;github.com/sendgrid/sendgrid-go&quot;<br>&quot;github.com/sendgrid/sendgrid-go/helpers/mail&quot;<br>)</pre><pre>// Email struct defines the data coming via REST API<br>type <em>email</em> struct {<br>EmailAddress <em>string</em> `json:&quot;emailAddress&quot;`<br>Name         <em>string</em> `json:&quot;name&quot;`<br>Message      <em>string</em> `json:&quot;message&quot;`<br>}</pre><pre>// SendEmail function sents email with the data coming from REST API<br>func SendEmail(w http.ResponseWriter, r *http.Request) {<br>var e email<br>decoder := json.NewDecoder(r.Body)<br>err := decoder.Decode(&amp;e)</pre><pre>if err != nil {<br>panic(err)<br>}</pre><pre>// Prepare the email content<br>from := mail.NewEmail(e.Name, e.EmailAddress)<br>subject := &quot;Contacted via portfolio website&quot;<br>to := mail.NewEmail(&quot;Your name&quot;, &quot;Your email id&quot;)<br>plainTextContent := e.Message</pre><pre>message := mail.NewSingleEmail(from, subject, to, plainTextContent, plainTextContent)</pre><pre>// Get the SendGrid API key from environment variable<br>sendGridAPIKey := os.Getenv(&quot;SENDGRID_API_KEY&quot;)</pre><pre>// Generate a SendGrid Send Client<br>client := sendgrid.NewSendClient(sendGridAPIKey)</pre><pre>// Send the message<br>response, err := client.Send(message)</pre><pre>if response.StatusCode != http.StatusAccepted {<br>if response.StatusCode != http.StatusOK {<br>// Request failed</pre><pre>log.Println(err)</pre><pre>w.WriteHeader(http.StatusInternalServerError)<br>w.Write([]byte(&quot;Something bad happened!&quot;))<br>}<br>} else {<br>// Request successful</pre><pre>// Setting header to allow cors</pre><pre>w.Header().Set(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;)<br>w.Write([]byte(&quot;Success&quot;))<br>}<br>}</pre><h3>Configuring Twilio SendGrid API</h3><p>The only thing remaining for the above code to work as expected is the <a href="https://www.twilio.com/sendgrid">SendGrid</a> API key. To get the key, log in<a href="https://app.sendgrid.com/login"> to SendGrid Console</a> first. Then go to <a href="https://app.sendgrid.com/settings/api_keys">create API key page</a>. Click on Create API Key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3GIOi27UMUYcJJyGhPj6g.png" /></figure><p>Enter the name for the key. You can keep the Full Access for API Key permissions and hit “Create &amp; View”. Copy the API key displayed on the next page and keep it with you in some secure place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pOXuDcKMa_B_BZgBrPMeQ.png" /></figure><h3>Testing the code</h3><p>To make sure the above code works, we will edit fn_test.go and run tests. Edit fn_test.go with the following code:</p><pre>package contactmebackend</pre><pre>import (<br>&quot;net/http&quot;<br>&quot;net/http/httptest&quot;<br>&quot;strings&quot;<br>&quot;testing&quot;<br>)</pre><pre>func TestSendEmail(t *testing.T) {<br>// Mock data with the &#39;body&#39; which will go over the REST, and &#39;wantStatus&#39; which is the expected status for the data sent in &#39;body&#39; field</pre><pre>tests := []struct {<br>body       <em>string<br></em>wantStatus <em>int<br></em>}{<br>// This one has all the necessary fields for successful request</pre><pre>{body: `{&quot;name&quot;: &quot;Itachi Redhair&quot;, &quot;emailAddress&quot;: &quot;itachi.redhair@gmail.com&quot;, &quot;message&quot;: &quot;Would love to meet over a beer!&quot;}`, wantStatus: http.StatusOK},</pre><pre>// This one will fail the request because emailAddress is missing.</pre><pre>{body: `{&quot;name&quot;: &quot;Itachi Redhair&quot;, &quot;message&quot;: &quot;Would love to meet over a beer!&quot;}`, wantStatus: http.StatusInternalServerError},<br>}</pre><pre>for _, test := range tests {<br>// httptest.NewRequest package will form the mock request object which we can pass on to our function directly<br>req := httptest.NewRequest(http.MethodPost, &quot;/&quot;, strings.NewReader(test.body))<br>req.Header.Add(&quot;Content-Type&quot;, &quot;application/json&quot;)</pre><pre>// mock response object<br>rr := httptest.NewRecorder()</pre><pre>SendEmail(rr, req)</pre><pre>if got := rr.Result().StatusCode; got != test.wantStatus {<br>t.Errorf(&quot;SendEmail(%q) = %q, want %q&quot;, test.body, got, test.wantStatus)<br>}<br>}<br>}</pre><p>Now before you run the tests, you need to set the environment variables. Run the following command with the SendGrid API key:</p><pre>export SENDGRID_API_KEY={Paste the api key which you copied earlier}</pre><p>Run the test with the following command:</p><pre>go test</pre><p>You should see output which should be somewhat like this:</p><pre>2020/01/08 11:18:29 &lt;nil&gt;<br>PASS<br>ok      medium-code-dump/contactmebackend       1.003s</pre><h3>Preparing GCP resources</h3><p>Now that our code is ready, we need to deploy it. To deploy it on Cloud Functions we need to enable few GCP APIs. You can do so by following this <a href="https://serverless.com/framework/docs/providers/google/guide/credentials/">link</a>.</p><p>Once you’ve enabled the required APIs, got credentials JSON file, stored it on your local machine and updated the serverless.yml file, edit functions field in serverless.yml field like below</p><pre>functions:<br>  first:<br>    handler: SendEmail<br>    events:<br>      - http: dummy-text</pre><p>SendEmail is the name of the handler function from our code in fn.go . Name of the function first doesn’t really mean anything and is ignored, same goes for value of the field http . You can see this <a href="https://serverless.com/framework/docs/providers/google/events/http#http-endpoint">link</a> for details.</p><h3>Deploying</h3><p>We are just there. To deploy the code just hit the following command:</p><pre>serverless deploy</pre><p>Wait till the deployment is done. You will get the link to trigger the function at the end. Something like this:</p><pre>Deployed functions<br>first<br>  https://us-central1-{project-id}.cloudfunctions.net/SendEmail</pre><p>Before you try the above link, you need to specify the environment variable SENDGRID_API_KEY in your cloud functions.</p><p>Go to <a href="https://console.cloud.google.com/functions/list">Cloud Functions List</a> in GCP console. Open our newly deployed function SendEmail. Click on edit. Scroll down and you will see an option to edit the environment variables. Add SENDGRID_API_KEY and it’s value and hit deploy.</p><p>After your function is deployed, try the following command with the above link:</p><pre>curl -X POST \<br>https://us-central1-{project-id}.cloudfunctions.net/SendEmail \<br>-H &#39;Content-Type: application/json&#39; \<br>-d &#39;{<br>&quot;emailAddress&quot;:&quot;dummy-email@dummy.com&quot;,&quot;name&quot;:&quot;dummy name&quot;, &quot;message&quot;:&quot;Hi there would like to meet you!&quot;<br>}&#39;</pre><p>Check your email and if everything goes fine you won’t be disappointed.</p><h3>Wrapping up</h3><p>This is a very simple and minimal example of how you can leverage Google Cloud Functions to deploy serverless service written in Golang.</p><p>I am using this for the contact me form I have on my portfolio and wanted to share with you the approach I’ve followed. If you need a live demo, then check out my portfolio website <a href="https://findakshay.dev/">https://findakshay.dev</a> and scroll down.</p><p>If there is something you didn’t understand or not working for you or can be improved, please let me know. You can reach out to me via <a href="https://twitter.com/_akshay_milmile">Twitter</a> or <a href="https://www.linkedin.com/in/akshaymilmile/">Linkedin</a>. You can also email me at akshay.milmile@gmail.com. You can check out some other projects that I’ve worked on past on my <a href="https://github.com/itachiredhair">Github</a>.</p><p>So that is it guys. Thank you for reading the article. Wish you a happy new year. Peace out ✌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=475e53aa6364" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bit-shift/build-a-serverless-service-for-contact-me-form-in-golang-and-deploy-on-gcp-475e53aa6364">Build a serverless service for “Contact Me” form in Golang and deploy on GCP</a> was originally published in <a href="https://medium.com/bit-shift">Bit Shift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa Skill with NodeJs, Part III : Rapid Development tools]]></title>
            <link>https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-iii-rapid-development-tools-f98294040431?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f98294040431</guid>
            <category><![CDATA[alexa]]></category>
            <category><![CDATA[alexa-skill-local]]></category>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 09:46:22 GMT</pubDate>
            <atom:updated>2018-07-10T06:49:57.723Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtKWlXTV4P9wvpKW2OyFbQ.png" /></figure><blockquote>I asked, Alexa, how can I develop your skills locally? She kept mum.</blockquote><p>Amazon has provided us with everything we need from very helpful Alexa Skill Console to cloud service like lambda. The only thing it failed to do is providing tools for developing Alexa skills locally.</p><p>When I first started out, I was very much frustrated than excited. I had to make changes to my interaction model in Alexa Skill Console. Zip my code and upload that big chunk of a file to lambda. Then use test simulator to send a request to lambda. After that, if code breaks, go to <a href="https://aws.amazon.com/cloudwatch/?sc_channel=PS&amp;sc_campaign=acquisition_IN&amp;sc_publisher=google&amp;sc_medium=cloudwatch_b&amp;sc_content=cloudwatch_e&amp;sc_detail=cloudwatch&amp;sc_category=cloudwatch&amp;sc_segment=159810556025&amp;sc_matchtype=e&amp;sc_country=IN&amp;s_kwcid=AL!4422!3!159810556025!e!!g!!cloudwatch&amp;ef_id=Wq1W4wAABXjQz9iY:20180422093250:s">CloudWatch </a>logs and check for all the console logs I’ve put in my code. Any If anything is failing, repeat all these steps again.What’s in this article?</p><p>In this article, I will discuss some tools which I’ve found and created during my frustration phase.</p><p>I’ll explain how to write test cases for your Alexa Skill using popular Javascript testing frameworks like chai and mocha. Test cases are very helpful if you have a very complex skill and want to test full flow of your code at once.<br>Then I will talk about <a href="https://www.npmjs.com/package/alexa-skill-local"><strong>alexa-skill-local</strong></a>, a tool to make a local server on your system which Alexa can directly talk with. This way you can use the debugger in your favorite editor for rapid development.</p><p>This is the part in series <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c">“Alexa Skill with NodeJs”</a>. I already discussed the flow of a basic Alexa Skill in my <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">previous article</a> with <a href="https://github.com/itachiRedhair/FlashCards">FlashCards</a>. If you want to follow along with, clone this project from my <a href="https://github.com/itachiRedhair/FlashCards">GitHub repo</a>.</p><h3>Writing test cases</h3><p>I am assuming that you have basic knowledge of how <a href="http://www.chaijs.com/">chai</a> and <a href="https://mochajs.org/">mocha</a> works.</p><h4>Directory Structure</h4><p>Mocha require test folder in root directory of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*z1qfRt1fyvEd5l6qVWw1TQ.png" /></figure><p>Test cases are written in invocation.js and practiceIntent.js. Request event JSON are in events folder and are classified according to intent it belongs.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>You can grab these JSON files from Alexa Skill Console’s test simulator. Say “open flash cards”. Then Copied JSON input and pasted it in invocationEvent.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i2nkH_n977mCvru9B59LyA.png" /></figure><p>Similarly I’ve have done this for PracticeIntent. Pasted JSON input in practiceEvent.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SYMQFUyA4msMQX5DIWojvA.png" /></figure><h4>Setting up dependencies</h4><p>Now before we move on to write test cases, we need to setup few things:</p><ul><li>DynamoDB Local</li><li><a href="https://www.npmjs.com/package/aws-lambda-mock-context">aws-lambda-mock-context</a></li><li>chai and mocha</li></ul><p><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html">DynamoDB Local</a> lets you develop your application locally without the need of accessing <a href="http://aws.amazon.com/dynamodb%E2%80%8E">DynamoDB’s web service</a>. Download any of the archives from <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html">here</a>. Unzip. Now enter root directory, where you have extracted the archive. Open terminal and type following command (Make sure you have latest JDK or JRE):</p><pre>java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 3333</pre><p>If you see something like this in your terminal, your DynamoDB service is now running on port 3333.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*hPj5B6cvWHX7WnBcX5nLXQ.png" /></figure><p>You need to adjust your code like this to tell your code to talk to local DynamoDB in the development environment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fed5b99397b7b5fcd451cc6a00e5e79/href">https://medium.com/media/5fed5b99397b7b5fcd451cc6a00e5e79/href</a></iframe><p>You will also need to set value of NODE_ENV as production in lambda console to make sure it won’t break while attempting to connect DynamoDB’s web service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wcUatlJ7QsrdiOgRIB7ydQ.png" /></figure><p>Now install aws-lambda-mock-context.</p><pre>npm install aws-lambda-mock-context --save-dev</pre><p>This package provides you with the mock context of lambda wrapped in a promise. We will need it to pass context object to our lambda handler function.</p><p>Install chai and mocha.</p><pre>npm install chai mocha --save-dev</pre><h4>Understanding the code</h4><p>We have imported context from aws-lambda-mock-context. In before hook, handler function is called. Handler function is the exported in index.js file. It is the first thing lamda calls and provides event request object and context. In our case, we have given the content of invocationEvent.json as a first parameter and ctx object as a second parameter. Then we are completing the before hook by calling done function after getting response or error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a99937abe54093991b89ff98243982e9/href">https://medium.com/media/a99937abe54093991b89ff98243982e9/href</a></iframe><p>speechResponse contains a response object after successful execution of handler function or else if the execution fails, speechError is populated with the error produced.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da0f63cb8c694aa8729f29875ad7c992/href">https://medium.com/media/da0f63cb8c694aa8729f29875ad7c992/href</a></iframe><p>Similar steps are followed for practiceIntent.js.</p><p>You can find full code <a href="https://github.com/itachiRedhair/FlashCards">here</a>.</p><p>Make sure you have added test script in package.json as follows.</p><pre>“scripts”: {<br>    “test”: “mocha”<br>},</pre><p>Run following command in root directory.</p><pre>npm run test</pre><p>If everything goes well you will have following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*Tz_iQxJbSOMjMYnDJds0IQ.png" /></figure><p>And there, you have written your test cases successfully and everything works on local just fine. Be sure to mock other things in development just like we did with DynamoDB Local.</p><h3>Necessity is the mother of invention.</h3><p>Test cases come real handy when dealing with the big project. But what about debugging. You can’t just run all your test cases to debug a small issue.</p><p>Wouldn’t it be amazing, if Alexa can talk to your code on the local system? Well, it’s possible with <a href="https://www.npmjs.com/package/alexa-skill-local"><strong>alexa-skill-local</strong></a>. I developed alexa-skill-local to get rid of all the problems associated with not being able to test and debug rapidly on AWS Lambda.</p><h4>Here’s how alexa-skill-local works.</h4><p>Install globally (recommended) or use it as a dev-dependency in you project (in this case you might want to use it in a npm script).</p><p>Update: In case of mac and ubuntu, if you are facing EAccess error, install it locally and use it in npm script.</p><pre>npm install -g alexa-skill-local</pre><p>Also add<em> asl-config.json</em> file in your root directory with following contents (in most cases stage is development):</p><pre>{<br>  “skillId”: “your_skill_id_here”,<br>  “stage”: “stage_of_your_skill”<br>}</pre><p>Make sure you have main field in a <em>package.json</em> indicating your lambda entry file or at least <em>index.js</em> file in root directory. If you don’t have both, specify entry file with --file argument.</p><p>Then go to the root directory of our lambda code and run following command.</p><pre>alexa-skill-local</pre><p>You will be prompted to open http://localhost:3001 in your browser. Go there and login with Amazon. This gives alexa-skill-local a permission to update Alexa Skill Endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*Bpozevnx1c-TxmWcdguKRA.png" /></figure><p>After your authentication, alexa-skill-local will start ngrok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*RLHQLexdZPnYEbfwHt58YQ.png" /></figure><p>Your Alexa Skill Endpoint will be automatically updated with ngrok URL. After that, a mock lambda service will run on local host on the same port ngrok is listening to. All the traffic to and fro on local host will be tunneled through ngrok.</p><p>Whenever you make any changes in your project files, mock lambda service will restart in response to those changes in respective files. This enables you to develop your skills rapidly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zRwoqkOngZ-u7SOdL06bqw.png" /></figure><p>You can also inspect these files with your favorite editor. Just add--inspect-brk while running alexa-skill-local. Debugger will listen on default port 9229.</p><pre>alexa-skill-local --inspect-brk</pre><p>I prefer VSCode to attach debugger. You can use something of your choice. For VSCode, add this configuration to your launch.json file under .vscode folder.</p><pre>{<br> “version”: “0.2.0”,<br> “configurations”: [<br>  {<br>    “type”: “node”,<br>    “request”: “attach”,<br>    “name”: “alexa-skill-local”,<br>    “processId”: “${command:PickProcess}”,<br>    “restart”: true,<br>    “protocol”: “inspector”,<br>    “port”: 9229<br>  }<br> ]<br>}</pre><p>Press ctrl+shift+D. It will open a debugger window. Make sure debugger configuration is selected as alexa-skill-local in top left corner. Click on green arrow and select process which starts with something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*vae-48uz6m5ez8K7gQ_RjQ.png" /></figure><p>Now set your breakpoints. Whenever request comes on your mock lambda service these breakpoints will be hit.</p><p>That’s all! Hope this articles will help you speed up your development. Check out alexa-skill-local’s <a href="https://www.npmjs.com/package/alexa-skill-local">documentation</a> for more options.</p><h3>Finale</h3><p>This is the final article in the series “Alexa Skill with NodeJs”. <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c">First part</a> was about setting up Alexa Skill and AWS Lambda. In the <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">second part</a>, I discussed ASK CLI functionalities and the basic flow of how Alexa Skill works. Check them out if you haven’t already.</p><p>Questions? Feedback? Comments? Leave a note here or contact me on twitter @Akshay_Milmile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f98294040431" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-iii-rapid-development-tools-f98294040431">Alexa Skill with NodeJs, Part III : Rapid Development tools</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa Skill with NodeJs, Part II: Understanding the flow]]></title>
            <link>https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc8de7913353</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Tue, 10 Apr 2018 03:34:40 GMT</pubDate>
            <atom:updated>2018-05-08T03:38:16.761Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtKWlXTV4P9wvpKW2OyFbQ.png" /></figure><h4>This is the second part in “Alexa Skill with NodeJs” series. In the <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c">first part</a>, we discussed how to setup AWS configuration to use AWS Lambda. We also created a local development environment and deployed it using ASK CLI. If you are new to AWS configuration and ASK CLI, you should first go through “<a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c"><strong>Alexa Skill with NodeJs, Part I: Setup</strong></a>”</h4><h4>What’s in this article?</h4><p>In this article, I will explain the project structure in detail. I will then introduce you to some ASK CLI commands to sync up Alexa Skill console and AWS Lambda function with local development. We will then understand basic fundamentals of Custom Alexa Skill. We will also have a look at using sessions, states and persisting our data in dynamoDB. For this article, I have already set up a <a href="https://github.com/itachiRedhair/FlashCards"><strong>project</strong></a> on GitHub based on this <a href="https://github.com/alexa/alexa-cookbook/tree/master/games/FlashCards"><strong>example</strong></a>.</p><p>Take a note that this is not the complete tutorial. Purpose of this article is to get you started with some basic fundamentals which you may not know as a beginner. Go through <a href="https://developer.amazon.com/docs/custom-skills/understanding-custom-skills.html"><strong>Custom Skill Guide</strong></a> and <a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs"><strong>alexa-skills-kit-sdk-for-nodejs</strong></a><strong> </strong>from time to time to build up your concepts.</p><h3>Set up a new project</h3><p>To follow up with this article, go through these steps:</p><ol><li>Set up a new project with the skill name “<em>FlashCards</em>”.</li></ol><pre>ask new --skill-name FlashCards --profile alexa-user</pre><p>2. Copy files under lambda and models folder from <a href="https://github.com/itachiRedhair/FlashCards">here</a> and paste it into your project.</p><p>3. Then deploy it.</p><pre>ask deploy --profile alexa-user</pre><p>After successful deployment you can see your deployed skill on <a href="https://developer.amazon.com/alexa/console/ask"><strong>Alexa Skill Console</strong></a> and lambda function uploaded on <a href="https://aws.amazon.com/lambda/"><strong>AWS Lambda</strong></a>.</p><h4>Project Structure</h4><p>Now we will take a look at our project structure from top to bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*S0Z4CNOCq2lGsOOwJON1WQ.png" /><figcaption>Project Structure</figcaption></figure><p>“<em>config</em>” file under “<em>.ask</em>” folder includes deployment settings. It has skill id and endpoint our skill will send requests to. In our case this endpoint points to our newly created lambda function. All our code which will be deployed on AWS Lambda is inside “<em>lambda </em>”folder. Interaction models for our skill is in json file under “<em>models</em>” folder. Files are named with the name of locale your are developing that interaction model for. In this case, it is “<em>en-US</em>”. In the end we have “<em>skill.json</em>” which has publishing information. It also has an api endpoint which points to source directory of lambda function.</p><h3>Some basics to begin with…</h3><p>I hope you have some knowledge about how things work in when it comes to creating custom skill. If you don’t, you should consider reading <a href="https://developer.amazon.com/docs/custom-skills/understanding-custom-skills.html"><strong>official documentation</strong></a>. Anyways, to begin with, I will explain some basic fundamentals. Click on edit which should be on the left side of FlashCard skill on <a href="https://developer.amazon.com/alexa/console/ask"><strong>Alexa Skill Console</strong></a> page. You will be greeted by the following page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBxRNQyuHqm4P3EkkhhG_g.png" /><figcaption>Aelxa Skill Dashboard</figcaption></figure><h4>Invocation</h4><p>First thing on the left-hand side panel is Invocation. You can edit invocation name of your skill here. There are <a href="https://developer.amazon.com/docs/custom-skills/understanding-how-users-invoke-custom-skills.html"><strong>several ways</strong></a> to invoke a skill, For ex.- “<em>Alexa, Open {invocation_name}</em>”, “<em>Alexa ask {invocation_name} to {do_something}</em>”. Make sure it is “<em>flash cards</em>” in our case.</p><h4>Intents</h4><p>Then comes intents. Whatever we say or ask to do something to Alexa, it maps it to a particular intent. There are two types of intents, <em>Custom </em>and <em>Built-In</em>. Built-In intents are some standard intents for basic utterances like “<em>yes</em>”, “<em>no</em>”, “<em>stop</em>” or “<em>help</em>”. We have three custom intents here:</p><ul><li>AnswerIntent</li><li>PracticeIntent</li><li>QuizIntent</li></ul><h4>Utterances</h4><p>Alexa leverage NLU (Natural Language Understanding) to create utterances based on what user is saying. These utterances are then used to map intents. For ex.- “<em>AnswerIntent</em>” has utterances like “<em>it is in {usstate}</em>” and “<em>{usstate}</em>”</p><h4>Slots</h4><p>Slots are basically a variable used in utterances. Slots have types and these particular types can have sample slot values. Slot values can have synonyms. Slots could be <em>Custom </em>or <em>Built-In</em>. It is always recommended to look for “<em>Built-In”</em> type if it serves your purpose. In above example “<em>it is in {usstate}</em>”, “<em>usstate</em>” is a slot of Built-In type <em>AMAZON.US_STATE</em>. Whenever user says something like “<em>it is in virginia</em>”, Alexa knows that slot “<em>usstate</em>” has value “<em>virginia</em>”.</p><p>Play around more to understand and get used to things.</p><h4>Handy ASK CLI commands</h4><p>Here are some commands to keep your local development in sync with Alexa Skill Console and AWS Lambda:</p><ul><li>Update local “<em>skill.json</em>” file</li></ul><pre>ask api get-skill --skill-id --stage development &gt; skill.json</pre><ul><li>Update local models</li></ul><pre>ask api get-model --skill-id &lt;skill_id&gt; --locale en-US --stage development &gt; models/en-US.json</pre><ul><li>Update deployed skill info</li></ul><pre>ask api update-skill --skill-id &lt;skill_id&gt; --file skill.json --stage development --profile alexa-user</pre><ul><li>Update deployed interaction model</li></ul><pre>ask api update-model --skill-id &lt;skill_id&gt; --file models/en-US.json --locale en-Us --profile alexa-user --stage development</pre><ul><li>Deploy Lambda function</li></ul><pre>ask deploy -t lambda --profile alexa-user</pre><p>All of these commands are to be run from the root directory. These commands will come in handy if you want to update only specific changes.</p><h3>Heart of our Alexa Skill, Lambda function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*0PkTgJg2ZPYD06DR0r3-iw.png" /><figcaption>Lambda folder</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54e571b3429f92e79461b93c2c331f13/href">https://medium.com/media/54e571b3429f92e79461b93c2c331f13/href</a></iframe><p>Let’s have a look at “index.js” file. It is exporting a handler function which represents the name of your lambda function. It is an entry point for AWS Lambda which it uses to execute your function’s code. An event is something which is passed from the application or service invoking the function. Context is for the purpose of interacting with lambda function to collect logs or other run-time parameters. Everything else is basic Alexa configuration and at the end, we call alexa.execute() to create a response.</p><p>Alexa creates requests based on invocation and utterances. It then sends these requests to lambda function in the event object. Now comes the role of handlers to handle the particular request based on intent. We have defined handlers in different files in handlers folder. According to intent present in our request’s event object, particular handler function specified for that intent is fired. Read <a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs#response-vs-responsebuilder"><strong>documentation </strong></a>to know how to create a response and emit it in the handler function. All the handler functions needs to be registered using registerHandlers function of alexa object.</p><p>When you invoke a skill, Alexa creates a request containing “LaunchRequest” event. If you are using stateless handlers, you can specify “LaunchRequest” handler which will handle the invocation request. But in our project, we are using state manager to handle the request. In this case, “NewSession” handler in “newSessionHandlers.js” will be fired in case of any incoming intent or launch requests with no state. Read <a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs#skill-state-management"><strong>this </strong></a>to know more about state management.</p><h4>Maintaining session</h4><p>Note that Alexa cannot maintain a persistent connection to lambda as it is a serverless service. So to maintain a session, lambda function sends session key-value pairs in a sessionAttributes field of the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cfjf-0Mpp5ENm945MESPw.png" /><figcaption>Launch Request</figcaption></figure><p>Alexa then puts these values in <em>attributes </em>field of the subsequent requests as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1b83p_7e_GdQhclOlEaYYg.png" /><figcaption>Intent Request</figcaption></figure><p>Creating session attributes is very easy. You have to take use of this.attributes object. Whatever you store in it is saved in the session.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/674f34dcf30786ac675ac0906c97dab5/href">https://medium.com/media/674f34dcf30786ac675ac0906c97dab5/href</a></iframe><p>This session lasts only for the period your skill is active. To persist your session attributes in the database, you can take advantage of Amazon DynamoDB. So next time you launch your skill your session attributes will be right there in this.attributes object. And to do that, you have to add this line.</p><pre>alexa.dynamoDBTableName=&quot;your_table_name&quot;</pre><p>Pretty neat, isn’t it?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52ab700fc25db94399491fab6619a68e/href">https://medium.com/media/52ab700fc25db94399491fab6619a68e/href</a></iframe><p>Note that your states you define with <em>this.hander.state</em> also gets persist in DynamoDB. This happens because, <em>this.handler.state</em> references to <em>this.attribute[‘state’]</em>. So if you want to clear state in particular case, add following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a759b5df011803af18c2de0e2ac4703c/href">https://medium.com/media/a759b5df011803af18c2de0e2ac4703c/href</a></iframe><p>You can only use up to 24kb of data while creating request. So take care while persisting everything into session. You can use DynamoDB to store large values by leveraging <a href="https://aws.amazon.com/documentation/sdk-for-javascript/"><strong>aws-sdk</strong></a>. You can use DynamoDB’s <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html"><strong>Node.js API</strong></a> to create a table, update documents etc. Just be sure to use different table than the one you are using for persisting session attributes.</p><h3>Conclusion</h3><p>Use this article to get started with your first skill. To understand rest of the code you have to refer to following documentations from time to time.</p><ul><li><a href="https://developer.amazon.com/docs/custom-skills/understanding-custom-skills.html"><strong>Building custom skill with alexa</strong></a></li><li><a href="https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs"><strong>alexa-skills-kit-sdk-for-nodejs</strong></a></li></ul><h3>Wait, there is more to it…</h3><p>Well, this was a very basic example of how the skill works. To make a complex skill, you may have to make more use of sdk’s functionalities like interfaces and services. You can refer to above-mentioned documentations to learn more.<br>If you want to get acquainted with every functionality Alexa Skill Kit offers and know how to leverage it, then <a href="https://github.com/alexa/alexa-cookbook"><strong>alexa-cookbook</strong></a> has the perfect set of examples for you to start.</p><h3>What’s next?</h3><p>While developing, you can’t always deploy to test just one change of line. It’s not efficient for collaborations too. While Amazon has not provided anything to work with our skill development locally, javascript testing frameworks like chai, mocha comes to rescue. In the <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-iii-rapid-development-tools-f98294040431">next article</a>, I will discuss how to setup lambda context and DynamoDB locally and write test for our use case using <strong><em>chai </em></strong>and <strong><em>mocha</em></strong>. See you there.</p><p>Questions? Feedback? Comments? Leave a note here or contact me on twitter @Akshay_Milmile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc8de7913353" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">Alexa Skill with NodeJs, Part II: Understanding the flow</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alexa Skill with NodeJs, Part I : Setup]]></title>
            <link>https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c?source=rss-474401a14bd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b2207482a7c</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[alexa-skills]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[alexa]]></category>
            <dc:creator><![CDATA[Akshay Milmile]]></dc:creator>
            <pubDate>Sat, 07 Apr 2018 20:21:57 GMT</pubDate>
            <atom:updated>2018-04-30T17:34:33.757Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtKWlXTV4P9wvpKW2OyFbQ.png" /></figure><p>It’s been more than 3 years since the launch of Amazon Alexa and almost 3 years for Amazon Echo which made this voice assistant more popular. There are very few voice assistants in the market. And when it comes to flexibility in developing custom skills, Amazon made it sure it stands out in the community. This new but quite promising field of digital voice assistants is still in its infancy and at times quite limiting despite it’s being around for quite a time. But it’s evident that with time it will bloom and render smartphones useless. So better late than never.</p><p>For those who are new to AWS services, official documentation can be a pain to follow when you don’t know where to start. In this article, I will discuss how to set up front-end and back-end for Alexa skill. Note that this will be a series of articles where I will discuss how to kickstart skill development and various pointers that I found useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0V1dblkEIs1XhP-HvO4WQ.png" /><figcaption>Under the hood</figcaption></figure><p>Unlike traditional apps, it’s a no-brainer that Alexa interacts with you with it’s Voice User Interface. Whatever you speak, Alexa figures out your intent and constructs a request. It then sends this request to back-end services which in almost all cases run on cloud-based services with the most popular one being <a href="https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"><strong>AWS Lambda</strong></a>. AWS Lambda is this serverless compute service for which you don’t need to setup and manage servers. You deploy your code and bingo, that’s it. I will be using AWS Lambda in this article but feel free to look into <a href="https://iwritecrappycode.wordpress.com/2016/04/01/create-an-alexa-skill-in-node-js-and-hosting-it-on-heroku/">heroku</a>, <a href="https://hackernoon.com/build-an-alexa-skill-in-7-minutes-flat-with-node-js-and-stdlib-70611f58c37f">StdLib</a> etc.</p><h3><strong>Enough talk! Let’s setup AWS and configure some things to get started.</strong></h3><p>Go to <a href="https://aws.amazon.com/"><strong>AWS</strong></a><strong> </strong>and sign in to console. I am assuming that you’ve already setup all the billing details and sign up formalities. If you haven’t then do it asap when it prompts. AWS will not charge you a penny as you won’t exceed the quota for the minimal usage of development.</p><p>AWS has this concept of Users and Groups for authenticating its services. Users in particular group are given certain permissions by the policies attached to that group.</p><h4>Create a Group</h4><p>First, we will create an administrator group and add an user to it. We will use this user for our project initialization and deployment. Find “<em>IAM </em>” under “<em>Security, Identity &amp; Compliance</em>” or search for “<em>IAM</em>” and enter. Click on Groups on the left-hand side panel and create a new group and give it a name ‘<em>alexa-administrator</em>’. Then search for following policies, tick them and go ahead.</p><ul><li>AWSLambdaFullAccess</li><li>IAMFullAccess</li></ul><p>Review your attached policies and then create a group. You should see something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVj7NeOg-7Mpo1bGcdzYYg.png" /><figcaption>Group with attached policies</figcaption></figure><h4>Create a User</h4><p>Let’s create a user and it to our group. Set user’s name as “<em>alexa-user</em>”. Check “<em>Programmatic access</em>” and go ahead to permissions. Select our newly created group “<em>alexa-administrator</em>” and hit review button and then create a user. Copy those keys. You will need them later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWrWxnlasr9Iy8aBLL2-Ow.png" /></figure><h4>Roles</h4><p>Our Lambda function needs a role which will define what it can do. In this article, we will initialize our Alexa skill using ASK CLI and then deploy it. This will automatically create a Lambda function and give it a role. We will have a look at that role in <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">next part</a> of this series.</p><h3>Phew! Let’s head on to ASK CLI.</h3><p>Install <a href="https://developer.amazon.com/docs/smapi/ask-cli-command-reference.html"><strong>ASK CLI</strong></a> with npm.</p><pre>npm i -g ask-cli</pre><p>Before we start, we need to tell ask-cli how to authenticate AWS services. This can be done in two ways. If you are familiar with awscli, you can configure using aws configure command which will ask you for “<em>Access key ID</em>” and “<em>Secret access key</em>” (remaining things you can leave blank). Or else, the easy way is to create local “<em>credentials</em>” file with the following content in “<em>.aws</em>” folder in your HOME directory (which could be different based on operating system). For more on credentials file, <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html"><strong>check this out</strong></a>.</p><pre>[alexa-user] </pre><pre>aws_access_key_id=&lt;your access key id here&gt;</pre><pre>aws_secret_access_key=&lt;your secret key here&gt;</pre><h4>Initialize ASK CLI</h4><p>Open your terminal and run following command.</p><pre>ask init --profile alexa-user</pre><p>Choose “<em>alexa-user</em>” profile when it’s prompted. Your browser should open after this. If not, then enter URL “<a href="http://localhost:9090/"><em>http://localhost:9090</em></a>” in your browser and log in to Alexa console. Your ASK CLI is now initialized and ready to do some action.</p><h4>Create a new skill with ASK CLI</h4><p>Run following command in the terminal.</p><pre>ask new --skill-name HelloWorld --profile alexa-user</pre><p>Wait till it’s finished. You will see a structure like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*3snB_vZ9MTasdnGBw2LsUw.png" /><figcaption>Project Structure</figcaption></figure><p>Under lambda folder whatever you have will be deployed to AWS Lambda. Inside models, you’ll have “<em>en-US.json”</em> which contains interaction model of our skill. “<em>skill.json”</em> has meta info about our skill which comes in picture when it is being published. There is config file in .ask folder which includes skill id and endpoint URI pointing to our Lambda function. All these files will be discussed in detail in <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">next part</a> of the series.</p><h4>Deploy with ASK CLI</h4><p>Let’s check how our skill does by deploying it. Run the following command inside the root directory of our project.</p><pre>ask deploy --profile alexa-user</pre><h4>Alexa Skill Console</h4><p>Go to Alexa Skill Console. Log in and head over to skills section, you can see your skill named HelloWorld like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEdY8emvzRzSL8xwVTrdeA.png" /><figcaption>Alexa Skill Console Home Page</figcaption></figure><h4>AWS Console</h4><p>Also, check your Lambda function by signing into AWS console. You can see your function name automatically created for you based on the user who deployed it and skill name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfpzVmgxcGL0Q2uPc4DfxQ.png" /><figcaption>Lambda Home Page</figcaption></figure><p>Let’s come back to Alexa skill console. Click on “<em>Edit</em>” link of our HelloWorld skill. On the left side, you can choose between intents and slots to edit. You can configure interfaces and endpoints on this page. Let’s quickly test our skill. Open Test tab and enter “<em>Tell hello world my name is Meeseek</em>”. It should reply with “<em>Hello Meeseek</em>”. There you go, you made your first skill. Take a breath and have yourself a drink :P.</p><h3>This is not the end.</h3><p>I started this article series to help all those people who are new to Alexa and AWS as was I when I started. It took me a shitload of time to figure out what goes where. Everything is there on the internet but in bits and pieces. While learning you have to switch between different pieces provided by Amazon which could confuse you at first. This article series is supposed to provide you with the direction to start on this promising world of Voice Interaction Applications. See ya in <a href="https://medium.com/@akshay.milmile/alexa-skill-with-nodejs-part-ii-understanding-the-flow-bc8de7913353">next part</a> where I will discuss writing Skill interaction model and Lambda function.</p><p>Feedback? Suggestion? Questions? Leave a note here or contact me on twitter @<a href="https://twitter.com/Akshay_Milmile">A</a>kshay_Milmile<em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b2207482a7c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/alexa-skill-with-nodejs-part-i-setup-8b2207482a7c">Alexa Skill with NodeJs, Part I : Setup</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>