Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
exports.handler = (event, context, callback) => {
const sessionAttributes = event.sessionAttributes;
const slots = event.currentIntent.slots;
const bookName = slots.bookName;
// predefined list of available books
const validBooks = ['harry potter', 'twilight', 'wings of fire'];
// negative check: if valid slot value is not obtained, inform lex that user is expected
// respond with a slot value
if (bookName && !(bookName === "") && validBooks.indexOf(bookName.toLowerCase()) === -1) {
let response = { sessionAttributes: event.sessionAttributes,
dialogAction: {
type: "ElicitSlot",
message: {
contentType: "PlainText",
content: `We do not have book: ${bookName}, Provide any other book name. For. e.g twilight.`
},
intentName: event.currentIntent.name,
slots: slots,
slotToElicit : "bookName"
}
}
callback(null, response);
}
// if valid book name is obtained, send command to choose next course of action
let response = {sessionAttributes: sessionAttributes,
dialogAction: {
type: "Delegate",
slots: event.currentIntent.slots
}
}
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.