In the previous post I described the
SessionEndedRequest which I think of as system level session requests. They are events that happen at startup and shutdown but don’t have a lot to do with the actual interaction.
In this post I’ll cover the
IntentRequest request type. This request type plus the name of the intent is how interactions unique to your skill are handled.
In part one of the tutorial you defined the
HelloIntent in the interaction model definition which should handle phrases like “hello” and “say hello”. Here’s the definition in case you forgot:
In part two we added the a request handler for the
index.js. Here’s a reminder of that.
This simply configures the skill to use the
HelloIntentHandler code to process intents.
Here is the code which I will discuss below.
You saw the
canHandle function in part two. There you saw it handle the standard system request type
HelloIntentHandler handles the
IntentRequest type. The problem is that non-system requests are all of the
IntentRequest type. We need to distinguish between them by adding the intent name to the check. This is done with this section of code:
Finally the good part! You handle the request in the
handle(handlerInput) function. What you do want to do is return the text you want spoken to the user saying “hello” or “say hello” to your skill. In this case you set this up with the constant string (which you should change of course):
Then you build and return the response:
You start building the response with
handlerInput.responseBuilder. Then you pass the text you want to speak to the
speak() function. The
withSimpleCard function adds a visual for Alexa devices that have a screen (I don’t know much about this yet, but I’ll be digging into in the future.). Then you send the response by calling the
We’ve walked through the code and while there is a bunch of configuration stuff that’s not intuitive, I think programmatically there isn’t anything tricky. Now that you understand the code and configuration behind the skill the next part of the tutorial you will deploy and test it.
See you then and please let me know if you have any questions.