Skip to content

Instantly share code, notes, and snippets.

Created June 24, 2020 05:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.`
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