Guest User

Untitled

a guest
Jul 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. const AzureFactsIntent = {
  2. canHandle(handlerInput) {
  3. return handlerInput.requestEnvelope.request.type === "IntentRequest"
  4. && handlerInput.requestEnvelope.request.intent.name === "AzureFactsIntent";
  5. },
  6. async handle(handlerInput) {
  7. let currentIntent;
  8.  
  9. let myName = slotValue(handlerInput.requestEnvelope.request.intent.slots.myName);
  10. let myQuestion = slotValue(handlerInput.requestEnvelope.request.intent.slots.myQuestion);
  11.  
  12. if (!myName) {
  13. currentIntent = myName;
  14. return handlerInput.responseBuilder
  15. .addDelegateDirective(currentIntent)
  16. .getResponse();
  17. }
  18.  
  19. if (myQuestion === "random") {
  20. myQuestion = FACTS_ARRAY[Math.floor(Math.random() * FACTS_ARRAY.length)];
  21. }
  22.  
  23. if (!myQuestion) {
  24. currentIntent = myQuestion;
  25. return handlerInput.responseBuilder
  26. .addDelegateDirective(currentIntent)
  27. .getResponse();
  28. }
  29.  
  30. let fact = await buildFactResponse(myName, myQuestion);
  31. let factToSpeak = `${myName}, ${fact.Attributes.Response}`
  32. return handlerInput
  33. .responseBuilder
  34. .speak(factToSpeak)
  35. .withStandardCard(CARD_TITLE, factToSpeak,
  36. IMAGES.smallImageUrl, `${BUCKET_URL}\/${fact.Attributes.Image}`)
  37. .getResponse();
  38. },
  39. };
Add Comment
Please, Sign In to add comment