Creating the Lambda

To start this Lambda, create another folder in the Lambda directory called addToCart with an index.js file inside. In your folder, we need to run npm install --save aws-sdk to make sure that we have access to AWS. We start, as normal, with our default node 8.10 function, and there are two things we need to do at the start of this function: check whether there is a Denied confirmation status, and call a handleAddToCart function.

If the confirmation status is denied, we can ask the user whether they want to find another product, using Lex.confirmIntent. We have already programmed our productFind Lambda to deal with confirmIntent triggers so that should already be working:

exports.handler = async (event) => { if (event.currentIntent ...

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.