Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 24, 2020 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/376d8902bc456e8f816462a8d83bb72b to your computer and use it in GitHub Desktop.
Save velotiotech/376d8902bc456e8f816462a8d83bb72b to your computer and use it in GitHub Desktop.
'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