Diving Deeper Into Laziness With Nodlex
So If you have read my last blog and created Lazybot, Then you too are a victim of Lazybot’s laziness. So why not work a little bit more and make our bot more intelligently lazy?

In this blog, we will:
- Add few more intents to Lazybot,
- We will work on the feature where Lazybot can ask you few questions (prompts) and,
- Also, it can track context with the help of session.
And all of this we will be doing with the help of Nodlex and alexa-nodejs-boilerplates, so it’s gonna be real quick.
As I was thinking what could be the sample feature that I can choose for the Lazybot. Then I got this idea what about Lazybot is a Weather Bot that hardly tells you weather (because it’s too lazy of-course).
So let’s begin,
For our Lazybot to understand that, the user is asking about the weather, we need to add weather intent and few utterances (for the skill Lazybot on Amazon Developer Portal). I have added following intent and utterances for weather

Do you remember that we added a greeting intent and hi utterance just to run the skill? So we don’t need that now, we can remove that intent and utterance.
Now we need to add an intent match and a response for the intent that we have created. In the normal case, we have to add a check for weather intent, a method that will get called and finally a response. I am pretty sure that this would have taken a significant amount of time. But don’t worry, you are rescued by Nodlex. So let’s do it in Nodlex way.
Come to the root of your project directory, open console window and type-
This will run Nodlex and will ask you a confirmation to add an intent named weather, press enter to add intent.

And that’s all, now Nodlex will automatically add an intent to intent-matcher file and create a function that will be called once the request for weather will come. You can see both things in the intent-matcher.js file.

This new function should return a Promise resolving into datastore object containing our response.
Let’s say, Our Lazybot did not reply the weather instead it asks another question, then we can build the response with the help of ResponseBuilder (containing a simple speech followed by prompt) in following way —

Little Explanation: This function is returning a Promise. This promise is resolving a datastore object. This datastore object should contain response object of type ResponseBuilder(). Here we building a response that contains a simple speech and a prompt.
With the help of ResponseBuilder() from alexa-nodejs-boilerplate, adding speech and prompts is just a matter of calling two functions.
Now Lazybot is waiting for user’s response in Yes or No. But here is a problem, Lazybot can ask different questions at different point of time in a conversation flow, Our Lazybot needs something to remember like what it has asked and for what user is replying Yes/No. To solve that we use a technique called as in-session context. And let’s see how easily we can use this awesome technique for our Lazybot with the help of alexa-nodejs-boilerplate’s dataStore.
To do that we just need to add an identifier (for asked the question) whenever we send our response back. When the next request will come, we will look for the identifier and then we can create an appropriate response. Just add the following line before resolving
dataStore.sessionData.context = ‘WeatherLookUpConfirmation’;
So our final function looks something like this —

As you can see here I have used WeatherLookUpConfirmation as an identifier to identify the context and stored it in dataStore.sessionData.context. we can use dataStore.sessionData for many different tasks and the data that we store, can be retrieved in the next request if the session is continued. But do remember that dataStore.sessionData should be an object. So just add key and values to sessionData.
Now we will add two more intents (AMAZON.YesIntent and AMAZON.NoIntent) to the developer portal and to our code. To add these two intents to the code we can use Nodlex’s addintent feature. It will automatically add check and method body for both these intents.
Once user will say Yes/No to our skill, we need to fetch the information like — For what user is saying Yes/No? As you remember while asking the question we have saved an identifier in our context memory. Now we can use the same object to fetch the context from. To fetch the context use —
let sessionContext = dataStore.sessionData.context;
Once we have this context information, we can write a simple check to see in which context user has said Yes/No.

And that’s all. Just deploy the above code and enjoy your first ever Nodlex Alexa Skill.
…, Over and Out.










