| 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