Last active
August 14, 2018 01:31
-
-
Save garystafford/3999b9e8b907ce36399e45303cb48956 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
const AzureFactsIntent = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === "IntentRequest" | |
&& request.intent.name === "AzureFactsIntent"; | |
}, | |
async handle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
let currentIntent = request.intent; | |
if (myNameValue === undefined) { | |
myNameValue = slotValue(request.intent.slots.myName); | |
} | |
if (!myNameValue) { | |
return handlerInput.responseBuilder | |
.addDelegateDirective(currentIntent) | |
.getResponse(); | |
} | |
let myQuestionValue = slotValue(request.intent.slots.myQuestion); | |
if (!myQuestionValue) { | |
return handlerInput.responseBuilder | |
.addDelegateDirective(currentIntent) | |
.getResponse(); | |
} | |
if (myQuestionValue.toString().trim() === 'random') { | |
myQuestionValue = selectRandomFact(); | |
} | |
let fact = await buildFactResponse(myNameValue, myQuestionValue); | |
myNameValue = Object.is(myNameValue, undefined) ? undefined : capitalizeFirstLetter(myNameValue); | |
let factToSpeak = `${myNameValue}, ${fact.Attributes.Response}`; | |
cardContent = factToSpeak; | |
// optional: logged to CloudWatch Logs | |
console.log(`myName: ${myNameValue}`); | |
console.log(`myQuestion: ${myQuestionValue}`); | |
console.log(`factToSpeak: ${factToSpeak}`); | |
return handlerInput | |
.responseBuilder | |
.speak(factToSpeak) | |
.reprompt("You can request another fact") | |
.withStandardCard(CARD_TITLE, cardContent, | |
IMAGES.smallImageUrl, `${BUCKET_URL}\/${fact.Attributes.Image}`) | |
.getResponse(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment