Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. /* eslint-disable func-names */
  2. /* eslint-disable no-console */
  3.  
  4. const Alexa = require('ask-sdk');
  5.  
  6. const GetNewFactHandler = {
  7. canHandle(handlerInput) {
  8. const request = handlerInput.requestEnvelope.request;
  9. return request.type === 'LaunchRequest';
  10. },
  11. handle(handlerInput) {
  12. const speechOutput = "Meow! Welcome to Cat Match! What kind of cat do you want?";
  13.  
  14. return handlerInput.responseBuilder
  15. .speak(speechOutput)
  16. .withSimpleCard(SKILL_NAME, speechOutput)
  17. .reprompt("Tell me a cat you want!")
  18. .getResponse();
  19. },
  20. };
  21.  
  22. const InProgressChoosePetIntentHandler = {
  23. canHandle(handlerInput) {
  24. const request = handlerInput.requestEnvelope.request;
  25. return request.type === 'IntentRequest' &&
  26. request.intent.name === 'CatIntent' &&
  27. request.dialogState !== 'COMPLETED';
  28. },
  29. handle(handlerInput) {
  30. const currentIntent = handlerInput.requestEnvelope.request.intent;
  31. console.log("hello, we are here!");
  32. return handlerInput.responseBuilder
  33. .addDelegateDirective(currentIntent)
  34. .getResponse();
  35. },
  36. };
  37.  
  38. const CatIntentHandler = {
  39. canHandle(handlerInput) {
  40. return handlerInput.requestEnvelope.request.type === 'IntentRequest'
  41. && handlerInput.requestEnvelope.request.intent.name === 'CatIntent';
  42. },
  43. async handle(handlerInput) {
  44. const responseBuilder = handlerInput.responseBuilder;
  45. const fur = handlerInput.requestEnvelope.request.intent.slots.fur.value;
  46. const size = handlerInput.requestEnvelope.request.intent.slots.size.value;
  47. let speechText = `Meow! You just got ${fur} haired ${size} cat as you asked for!`;
  48.  
  49. return responseBuilder
  50. .speak(speechText)
  51. .getResponse();
  52. },
  53. };
  54.  
  55. const HelpHandler = {
  56. canHandle(handlerInput) {
  57. const request = handlerInput.requestEnvelope.request;
  58. return request.type === 'IntentRequest'
  59. && request.intent.name === 'AMAZON.HelpIntent';
  60. },
  61. handle(handlerInput) {
  62. return handlerInput.responseBuilder
  63. .speak(HELP_MESSAGE)
  64. .reprompt(HELP_REPROMPT)
  65. .getResponse();
  66. },
  67. };
  68.  
  69.  
  70.  
  71.  
  72.  
  73. const ExitHandler = {
  74. canHandle(handlerInput) {
  75. const request = handlerInput.requestEnvelope.request;
  76. return request.type === 'IntentRequest'
  77. && (request.intent.name === 'AMAZON.CancelIntent'
  78. || request.intent.name === 'AMAZON.StopIntent');
  79. },
  80. handle(handlerInput) {
  81. return handlerInput.responseBuilder
  82. .speak(STOP_MESSAGE)
  83. .getResponse();
  84. },
  85. };
  86.  
  87. const SessionEndedRequestHandler = {
  88. canHandle(handlerInput) {
  89. const request = handlerInput.requestEnvelope.request;
  90. return request.type === 'SessionEndedRequest';
  91. },
  92. handle(handlerInput) {
  93. console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
  94.  
  95. return handlerInput.responseBuilder.getResponse();
  96. },
  97. };
  98.  
  99. const ErrorHandler = {
  100. canHandle() {
  101. return true;
  102. },
  103. handle(handlerInput, error) {
  104. console.log(`Error handled: ${error.message}`);
  105.  
  106. return handlerInput.responseBuilder
  107. .speak('Sorry, an error occurred.')
  108. .reprompt('Sorry, an error occurred.')
  109. .getResponse();
  110. },
  111. };
  112.  
  113. const SKILL_NAME = 'Space Facts';
  114. const GET_FACT_MESSAGE = 'Here\'s your fact: ';
  115. const HELP_MESSAGE = 'You can say tell me a space fact, or, you can say exit... What can I help you with?';
  116. const HELP_REPROMPT = 'What can I help you with?';
  117. const STOP_MESSAGE = 'Goodbye!';
  118.  
  119. const data = [
  120. 'A year on Mercury is just 88 days long.',
  121. 'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
  122. 'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.',
  123. 'On Mars, the Sun appears about half the size as it does on Earth.',
  124. 'Earth is the only planet not named after a god.',
  125. 'Jupiter has the shortest day of all the planets.',
  126. 'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
  127. 'The Sun contains 99.86% of the mass in the Solar System.',
  128. 'The Sun is an almost perfect sphere.',
  129. 'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
  130. 'Saturn radiates two and a half times more energy into space than it receives from the sun.',
  131. 'The temperature inside the Sun can reach 15 million degrees Celsius.',
  132. 'The Moon is moving approximately 3.8 cm away from our planet every year.',
  133. ];
  134.  
  135. const skillBuilder = Alexa.SkillBuilders.standard();
  136.  
  137. exports.handler = skillBuilder
  138. .addRequestHandlers(
  139. GetNewFactHandler,
  140. InProgressChoosePetIntentHandler,
  141. CatIntentHandler,
  142. HelpHandler,
  143. ExitHandler,
  144. SessionEndedRequestHandler
  145. )
  146. .addErrorHandlers(ErrorHandler)
  147. .lambda();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement