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 ...

Get Hands-On Chatbot Development with Alexa Skills and Amazon Lex now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.