Created
June 24, 2020 05:27
-
-
Save velotiotech/376d8902bc456e8f816462a8d83bb72b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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