Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. // This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).
  2. // Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
  3. // session persistence, api calls, and more.
  4. const Alexa = require('ask-sdk-core');
  5.  
  6. const LaunchRequestHandler = {
  7. canHandle(handlerInput) {
  8. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
  9. },
  10. handle(handlerInput) {
  11. const speakOutput = 'Benvenuto, chidimi una barzelltta dicendomi: dimmi una barzelletta';
  12. return handlerInput.responseBuilder
  13. .speak(speakOutput)
  14. .reprompt(speakOutput)
  15. .getResponse();
  16. }
  17. };
  18. const StorielleIntentHandler = {
  19. canHandle(handlerInput) {
  20. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
  21. && Alexa.getIntentName(handlerInput.requestEnvelope) === 'StorielleIntent';
  22. },
  23. handle(handlerInput) {
  24. var storielle=new Array();
  25. storielle.push("Bambini, come vorreste che fosse la vostra scuola? Rispondono in coro gli scolari: ");
  26.  
  27.  
  28. var x=Math.floor(Math.random() * storielle.length);
  29. const speakOutput = storielle[x];
  30. return handlerInput.responseBuilder
  31. .speak(speakOutput)
  32. //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
  33. .getResponse();
  34. }
  35. };
  36. const HelpIntentHandler = {
  37. canHandle(handlerInput) {
  38. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
  39. && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
  40. },
  41. handle(handlerInput) {
  42. const speakOutput = 'per chiedermi una barzelletta basta che mi dici la frase dimmi una barzelletta';
  43.  
  44. return handlerInput.responseBuilder
  45. .speak(speakOutput)
  46. .reprompt(speakOutput)
  47. .getResponse();
  48. }
  49. };
  50. const CancelAndStopIntentHandler = {
  51. canHandle(handlerInput) {
  52. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
  53. && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
  54. || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
  55. },
  56. handle(handlerInput) {
  57. const speakOutput = 'Ci vediamo';
  58. return handlerInput.responseBuilder
  59. .speak(speakOutput)
  60. .withShouldEndSession(true)
  61. .getResponse();
  62. }
  63. };
  64. const SessionEndedRequestHandler = {
  65. canHandle(handlerInput) {
  66. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
  67. },
  68. handle(handlerInput) {
  69. // Any cleanup logic goes here.
  70. return handlerInput.responseBuilder.getResponse();
  71. }
  72. };
  73.  
  74. // The intent reflector is used for interaction model testing and debugging.
  75. // It will simply repeat the intent the user said. You can create custom handlers
  76. // for your intents by defining them above, then also adding them to the request
  77. // handler chain below.
  78. const IntentReflectorHandler = {
  79. canHandle(handlerInput) {
  80. return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
  81. },
  82. handle(handlerInput) {
  83. const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
  84. const speakOutput = `Stai usando ${intentName}`;
  85.  
  86. return handlerInput.responseBuilder
  87. .speak(speakOutput)
  88. //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
  89. .getResponse();
  90. }
  91. };
  92.  
  93. // Generic error handling to capture any syntax or routing errors. If you receive an error
  94. // stating the request handler chain is not found, you have not implemented a handler for
  95. // the intent being invoked or included it in the skill builder below.
  96. const ErrorHandler = {
  97. canHandle() {
  98. return true;
  99. },
  100. handle(handlerInput, error) {
  101. console.log(`~~~~ Errore 101: ${error.stack}`);
  102. const speakOutput = `Scusami c'è stato un erorre`;
  103.  
  104. return handlerInput.responseBuilder
  105. .speak(speakOutput)
  106. .reprompt(speakOutput)
  107. .getResponse();
  108. }
  109. };
  110.  
  111. // The SkillBuilder acts as the entry point for your skill, routing all request and response
  112. // payloads to the handlers above. Make sure any new handlers or interceptors you've
  113. // defined are included below. The order matters - they're processed top to bottom.
  114. exports.handler = Alexa.SkillBuilders.custom()
  115. .addRequestHandlers(
  116. LaunchRequestHandler,
  117. StorielleIntentHandler,
  118. HelpIntentHandler,
  119. CancelAndStopIntentHandler,
  120. SessionEndedRequestHandler,
  121. IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
  122. )
  123. .addErrorHandlers(
  124. ErrorHandler,
  125. )
  126. .lambda();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement