O'Reilly logo

Hands-On Chatbot Development with Alexa Skills and Amazon Lex by Sam Williams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling the whichCar Intent

We can start dealing with our whichCar intent. We start by creating the WhichCarHandler and adding it to the list in addRequestHandlers():

const WhichCarHandler = {    canHandle(handlerInput) {        return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&            handlerInput.requestEnvelope.request.intent.name === 'whichCar';    },    async handle(handlerInput) {}}

Inside this handler function, the first thing that we need to do is to get the slots from the event. We can use es6 destructuring to simplify our code:

const slots = handlerInput.requestEnvelope.request.intent.slots;const {size, cost, gears, doors} = slots;

We now have access to all four of our slot variables. Even though we created our slot types, we need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required