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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.