Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JSON Editor
- {
- "interactionModel": {
- "languageModel": {
- "invocationName": "dado de once caras",
- "intents": [
- {
- "name": "AMAZON.CancelIntent",
- "samples": []
- },
- {
- "name": "AMAZON.HelpIntent",
- "samples": []
- },
- {
- "name": "AMAZON.StopIntent",
- "samples": []
- },
- {
- "name": "LanzaDado",
- "slots": [],
- "samples": [
- "lanzar dado",
- "tirar dado",
- "otra vez",
- "otra tirada",
- "otra"
- ]
- },
- {
- "name": "AMAZON.NavigateHomeIntent",
- "samples": []
- },
- {
- "name": "AMAZON.YesIntent",
- "samples": []
- },
- {
- "name": "AMAZON.NoIntent",
- "samples": []
- },
- {
- "name": "AMAZON.NextIntent",
- "samples": []
- }
- ],
- "types": []
- }
- }
- }
- Index.js
- const Alexa = require('ask-sdk-core');
- const LaunchRequestHandler = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
- },
- handle(handlerInput) {
- const speechText = "Bienvenido a dado de 11 caras. ¿Quieres que lance el dado?";
- return handlerInput.responseBuilder
- .speak(speechText)
- .reprompt(speechText)
- .getResponse();
- }
- };
- const DimeFraseIntentHandler = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === 'IntentRequest'
- && (handlerInput.requestEnvelope.request.intent.name === 'DimeFrase'
- || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.YesIntent'
- || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NextIntent');
- },
- handle(handlerInput) {
- const speechText = getRandomItem(FRASES);
- if (handlerInput.requestEnvelope.context.System.device.supportedInterfaces['Alexa.Presentation.APL']) {
- let myDocument = require('./documentAPL.json');
- let myDatasource = require('./datasourceAPL.json');
- myDatasource.bodyTemplate1Data.title= "El resultado de la tirada es: ";
- myDatasource.bodyTemplate1Data.textContent.primaryText.text= speechText;
- return handlerInput.responseBuilder
- .speak(speechText + getRandomItem(PREGUNTAS))
- .reprompt(getRandomItem(PREGUNTAS))
- .addDirective({
- type: 'Alexa.Presentation.APL.RenderDocument',
- version: '1.0',
- document: myDocument,
- datasources: myDatasource
- })
- .getResponse();
- }
- else{
- return handlerInput.responseBuilder
- .speak(speechText + getRandomItem(PREGUNTAS))
- .reprompt(getRandomItem(PREGUNTAS))
- .getResponse();
- }
- }
- };
- const HelpIntentHandler = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === 'IntentRequest'
- && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
- },
- handle(handlerInput) {
- const speechText = 'Puedes pedirme que lance el dado respondiendo sí o no. ¿Quieres que lance el dado?';
- return handlerInput.responseBuilder
- .speak(speechText)
- .reprompt(speechText)
- .getResponse();
- }
- };
- const CancelAndStopIntentHandler = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === 'IntentRequest'
- && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
- || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent'
- || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NoIntent');
- },
- handle(handlerInput) {
- const speechText = 'Hasta la vista!';
- return handlerInput.responseBuilder
- .speak(speechText)
- .getResponse();
- }
- };
- const SessionEndedRequestHandler = {
- canHandle(handlerInput) {
- return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
- },
- handle(handlerInput) {
- // Any cleanup logic goes here.
- return handlerInput.responseBuilder.getResponse();
- }
- };
- const ErrorHandler = {
- canHandle() {
- return true;
- },
- handle(handlerInput, error) {
- console.log(`~~~~ Error handled: ${error.message}`);
- const speechText = 'Perdona, hubo un error. Vuelve a intentarlo respondiendo sí o no. ¿Quieres que lance el dado?';
- return handlerInput.responseBuilder
- .speak(speechText)
- .reprompt(speechText)
- .getResponse();
- }
- };
- function getRandomItem(array) {
- return array[Math.floor(Math.random()*array.length)]
- }
- const FRASES = [
- '1 ',
- '2 ',
- '3 ',
- '4 ',
- '5 ',
- '6 ',
- '7 ',
- '8 ',
- '9 ',
- '10 ',
- '11 '
- ];
- const PREGUNTAS = [
- '¿Quieres otra tirada?',
- '¿Lanzo el dado de nuevo?',
- '¿Vamos con otra tirada?',
- '¿Lanzamos el dado otra vez?',
- '¿Te gustaría que lanzara de nuevo el dado?'
- ];
- exports.handler = Alexa.SkillBuilders.custom()
- .addRequestHandlers(
- LaunchRequestHandler,
- DimeFraseIntentHandler,
- HelpIntentHandler,
- CancelAndStopIntentHandler,
- SessionEndedRequestHandler)
- .addErrorHandlers(
- ErrorHandler)
- .lambda();
- datasourceAPL.json
- {
- "bodyTemplate1Data": {
- "type": "object",
- "objectId": "bt1Sample",
- "backgroundImage": {
- "contentDescription": null,
- "smallSourceUrl": null,
- "largeSourceUrl": null,
- "sources": [
- {
- "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
- "size": "small",
- "widthPixels": 0,
- "heightPixels": 0
- },
- {
- "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
- "size": "large",
- "widthPixels": 0,
- "heightPixels": 0
- }
- ]
- },
- "title": "Sabías que?",
- "textContent": {
- "primaryText": {
- "type": "PlainText",
- "text": "Los dados de 11 a 15 caras se usan en rol para tareas de dificultad moderada. "
- }
- },
- "logoUrl": ""
- }
- }
- documentAPL.json
- {
- "bodyTemplate1Data": {
- "type": "object",
- "objectId": "bt1Sample",
- "backgroundImage": {
- "contentDescription": null,
- "smallSourceUrl": null,
- "largeSourceUrl": null,
- "sources": [
- {
- "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
- "size": "small",
- "widthPixels": 0,
- "heightPixels": 0
- },
- {
- "url": "https://ilovetelas.com/341-tm_large_default/tela-fieltro.jpg",
- "size": "large",
- "widthPixels": 0,
- "heightPixels": 0
- }
- ]
- },
- "title": "Sabías que?",
- "textContent": {
- "primaryText": {
- "type": "PlainText",
- "text": "Los dados de 11 a 15 caras se usan en rol para tareas de dificultad moderada. "
- }
- },
- "logoUrl": ""
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement