Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const AzureFactsIntent = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === "IntentRequest"
- && handlerInput.requestEnvelope.request.intent.name === "AzureFactsIntent";
- },
- async handle(handlerInput) {
- let currentIntent;
- let myName = slotValue(handlerInput.requestEnvelope.request.intent.slots.myName);
- let myQuestion = slotValue(handlerInput.requestEnvelope.request.intent.slots.myQuestion);
- if (!myName) {
- currentIntent = myName;
- return handlerInput.responseBuilder
- .addDelegateDirective(currentIntent)
- .getResponse();
- }
- if (myQuestion === "random") {
- myQuestion = FACTS_ARRAY[Math.floor(Math.random() * FACTS_ARRAY.length)];
- }
- if (!myQuestion) {
- currentIntent = myQuestion;
- return handlerInput.responseBuilder
- .addDelegateDirective(currentIntent)
- .getResponse();
- }
- let fact = await buildFactResponse(myName, myQuestion);
- let factToSpeak = `${myName}, ${fact.Attributes.Response}`
- return handlerInput
- .responseBuilder
- .speak(factToSpeak)
- .withStandardCard(CARD_TITLE, factToSpeak,
- IMAGES.smallImageUrl, `${BUCKET_URL}\/${fact.Attributes.Image}`)
- .getResponse();
- },
- };
Add Comment
Please, Sign In to add comment