Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. JSON Editor
  2.  
  3. {
  4. "interactionModel": {
  5. "languageModel": {
  6. "invocationName": "dado de once caras",
  7. "intents": [
  8. {
  9. "name": "AMAZON.CancelIntent",
  10. "samples": []
  11. },
  12. {
  13. "name": "AMAZON.HelpIntent",
  14. "samples": []
  15. },
  16. {
  17. "name": "AMAZON.StopIntent",
  18. "samples": []
  19. },
  20. {
  21. "name": "LanzaDado",
  22. "slots": [],
  23. "samples": [
  24. "lanzar dado",
  25. "tirar dado",
  26. "otra vez",
  27. "otra tirada",
  28. "otra"
  29. ]
  30. },
  31. {
  32. "name": "AMAZON.NavigateHomeIntent",
  33. "samples": []
  34. },
  35. {
  36. "name": "AMAZON.YesIntent",
  37. "samples": []
  38. },
  39. {
  40. "name": "AMAZON.NoIntent",
  41. "samples": []
  42. },
  43. {
  44. "name": "AMAZON.NextIntent",
  45. "samples": []
  46. }
  47. ],
  48. "types": []
  49. }
  50. }
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Index.js
  64.  
  65. const Alexa = require('ask-sdk-core');
  66.  
  67. const LaunchRequestHandler = {
  68. canHandle(handlerInput) {
  69. return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  70. },
  71. handle(handlerInput) {
  72. const speechText = "Bienvenido a dado de 11 caras. ¿Quieres que lance el dado?";
  73. return handlerInput.responseBuilder
  74. .speak(speechText)
  75. .reprompt(speechText)
  76. .getResponse();
  77. }
  78. };
  79. const DimeFraseIntentHandler = {
  80. canHandle(handlerInput) {
  81. return handlerInput.requestEnvelope.request.type === 'IntentRequest'
  82. && (handlerInput.requestEnvelope.request.intent.name === 'DimeFrase'
  83. || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.YesIntent'
  84. || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NextIntent');
  85. },
  86. handle(handlerInput) {
  87. const speechText = getRandomItem(FRASES);
  88. if (handlerInput.requestEnvelope.context.System.device.supportedInterfaces['Alexa.Presentation.APL']) {
  89. let myDocument = require('./documentAPL.json');
  90. let myDatasource = require('./datasourceAPL.json');
  91. myDatasource.bodyTemplate1Data.title= "El resultado de la tirada es: ";
  92. myDatasource.bodyTemplate1Data.textContent.primaryText.text= speechText;
  93.  
  94. return handlerInput.responseBuilder
  95. .speak(speechText + getRandomItem(PREGUNTAS))
  96. .reprompt(getRandomItem(PREGUNTAS))
  97. .addDirective({
  98. type: 'Alexa.Presentation.APL.RenderDocument',
  99. version: '1.0',
  100. document: myDocument,
  101. datasources: myDatasource
  102. })
  103. .getResponse();
  104.  
  105. }
  106. else{
  107.  
  108. return handlerInput.responseBuilder
  109. .speak(speechText + getRandomItem(PREGUNTAS))
  110. .reprompt(getRandomItem(PREGUNTAS))
  111. .getResponse();
  112. }
  113. }
  114. };
  115. const HelpIntentHandler = {
  116. canHandle(handlerInput) {
  117. return handlerInput.requestEnvelope.request.type === 'IntentRequest'
  118. && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
  119. },
  120. handle(handlerInput) {
  121. const speechText = 'Puedes pedirme que lance el dado respondiendo sí o no. ¿Quieres que lance el dado?';
  122.  
  123. return handlerInput.responseBuilder
  124. .speak(speechText)
  125. .reprompt(speechText)
  126. .getResponse();
  127. }
  128. };
  129. const CancelAndStopIntentHandler = {
  130. canHandle(handlerInput) {
  131. return handlerInput.requestEnvelope.request.type === 'IntentRequest'
  132. && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
  133. || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent'
  134. || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NoIntent');
  135. },
  136. handle(handlerInput) {
  137. const speechText = 'Hasta la vista!';
  138. return handlerInput.responseBuilder
  139. .speak(speechText)
  140. .getResponse();
  141. }
  142. };
  143. const SessionEndedRequestHandler = {
  144. canHandle(handlerInput) {
  145. return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
  146. },
  147. handle(handlerInput) {
  148. // Any cleanup logic goes here.
  149. return handlerInput.responseBuilder.getResponse();
  150. }
  151. };
  152.  
  153. const ErrorHandler = {
  154. canHandle() {
  155. return true;
  156. },
  157. handle(handlerInput, error) {
  158. console.log(`~~~~ Error handled: ${error.message}`);
  159. const speechText = 'Perdona, hubo un error. Vuelve a intentarlo respondiendo sí o no. ¿Quieres que lance el dado?';
  160.  
  161. return handlerInput.responseBuilder
  162. .speak(speechText)
  163. .reprompt(speechText)
  164. .getResponse();
  165. }
  166. };
  167.  
  168. function getRandomItem(array) {
  169. return array[Math.floor(Math.random()*array.length)]
  170. }
  171.  
  172. const FRASES = [
  173. '1 ',
  174. '2 ',
  175. '3 ',
  176. '4 ',
  177. '5 ',
  178. '6 ',
  179. '7 ',
  180. '8 ',
  181. '9 ',
  182. '10 ',
  183. '11 '
  184. ];
  185.  
  186. const PREGUNTAS = [
  187. '¿Quieres otra tirada?',
  188. '¿Lanzo el dado de nuevo?',
  189. '¿Vamos con otra tirada?',
  190. '¿Lanzamos el dado otra vez?',
  191. '¿Te gustaría que lanzara de nuevo el dado?'
  192. ];
  193.  
  194. exports.handler = Alexa.SkillBuilders.custom()
  195. .addRequestHandlers(
  196. LaunchRequestHandler,
  197. DimeFraseIntentHandler,
  198. HelpIntentHandler,
  199. CancelAndStopIntentHandler,
  200. SessionEndedRequestHandler)
  201. .addErrorHandlers(
  202. ErrorHandler)
  203. .lambda();
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214. datasourceAPL.json
  215.  
  216.  
  217. {
  218. "bodyTemplate1Data": {
  219. "type": "object",
  220. "objectId": "bt1Sample",
  221. "backgroundImage": {
  222. "contentDescription": null,
  223. "smallSourceUrl": null,
  224. "largeSourceUrl": null,
  225. "sources": [
  226. {
  227. "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
  228. "size": "small",
  229. "widthPixels": 0,
  230. "heightPixels": 0
  231. },
  232. {
  233. "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
  234. "size": "large",
  235. "widthPixels": 0,
  236. "heightPixels": 0
  237. }
  238. ]
  239. },
  240. "title": "Sabías que?",
  241. "textContent": {
  242. "primaryText": {
  243. "type": "PlainText",
  244. "text": "Los dados de 11 a 15 caras se usan en rol para tareas de dificultad moderada. "
  245. }
  246. },
  247. "logoUrl": ""
  248. }
  249. }
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. documentAPL.json
  275.  
  276. {
  277. "bodyTemplate1Data": {
  278. "type": "object",
  279. "objectId": "bt1Sample",
  280. "backgroundImage": {
  281. "contentDescription": null,
  282. "smallSourceUrl": null,
  283. "largeSourceUrl": null,
  284. "sources": [
  285. {
  286. "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
  287. "size": "small",
  288. "widthPixels": 0,
  289. "heightPixels": 0
  290. },
  291. {
  292. "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
  293. "size": "large",
  294. "widthPixels": 0,
  295. "heightPixels": 0
  296. }
  297. ]
  298. },
  299. "title": "Sabías que?",
  300. "textContent": {
  301. "primaryText": {
  302. "type": "PlainText",
  303. "text": "Los dados de 11 a 15 caras se usan en rol para tareas de dificultad moderada. "
  304. }
  305. },
  306. "logoUrl": ""
  307. }
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement