Created
January 11, 2019 12:51
-
-
Save softwarechido/55945a638fc80465ce3ce466318807cc to your computer and use it in GitHub Desktop.
Poesia Urbana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//lambda | |
const Alexa = require('ask-sdk'); | |
const LaunchRequestHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'LaunchRequest' | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak('¡Hola!... '+HELP_MESSAGE) | |
.withSimpleCard(SKILL_NAME) | |
.addDirective({ | |
type: 'Alexa.Presentation.APL.RenderDocument', | |
version: '1.0', | |
document: require('./main.json'), | |
datasources: {} | |
}) | |
.reprompt(HELP_REPROMPT) | |
.getResponse(); | |
}, | |
}; | |
const PoesiaHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'PoesiaIntent'; | |
}, | |
handle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
var nombre = request.intent.slots.nombre.value; | |
console.log('nombre -'+nombre); | |
if (typeof nombre === 'undefined') nombre = 'amor'; | |
const data = [ | |
'Y me preguntas '+nombre+' que es poesía... ¡Poesía eres tu!', | |
nombre+' ...eres una persona tan bonita que a todos robas... robas un suspiro. Una mirada... mas que eso. Eres de aquellas personas que... con una sonrisa roban el alma', | |
'Tú sonrisa elegante y tu espíritu andante me hacen perder la razón y tu nombre '+nombre+' ahora habita en mi corazón', | |
'Eres tu '+nombre+'... eres tu mi tesoro, la persona que adoro... y me hace perder la razón', | |
'Debo confesar '+nombre+' que ya te conocía antes de conocerte.... Al soñarte ya te amaba', | |
nombre+' ...eres mi estrella... puedo verlo en tu mirada', | |
]; | |
const factArr = data; | |
const factIndex = Math.floor(Math.random() * factArr.length); | |
const randomFact = factArr[factIndex]; | |
const speechOutput = GET_FACT_MESSAGE + randomFact + ' <break time="1s"/> <say-as interpret-as="interjection">wuórales</say-as> ¡cuanta inspiración!. Ahora ' + HELP_MESSAGE ; | |
return handlerInput.responseBuilder | |
.speak(speechOutput) | |
.withSimpleCard(SKILL_NAME, speechOutput) | |
.reprompt(HELP_REPROMPT) | |
.addDirective({ | |
type: 'Alexa.Presentation.APL.RenderDocument', | |
version: '1.0', | |
document: require('./poesia.json'), | |
datasources: { | |
"bodyTemplate7Data": { | |
"title": "Poesía Urbana", | |
"backgroundImage": { | |
"sources":[ | |
{ | |
"url":"https://s3.amazonaws.com/poesia-urbana/PoesiaBackground.jpg" | |
} | |
] | |
} | |
} | |
} | |
}) | |
.getResponse(); | |
}, | |
}; | |
const HelpHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'AMAZON.HelpIntent'; | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(HELP_MESSAGE) | |
.reprompt(HELP_REPROMPT) | |
.getResponse(); | |
}, | |
}; | |
const ExitHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& (request.intent.name === 'AMAZON.CancelIntent' | |
|| request.intent.name === 'AMAZON.StopIntent'); | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(STOP_MESSAGE) | |
.withShouldEndSession(true) | |
.getResponse(); | |
}, | |
}; | |
const SessionEndedRequestHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'SessionEndedRequest'; | |
}, | |
handle(handlerInput) { | |
console.log(`Se ha terminado la sesión por las siguientes causas: ${handlerInput.requestEnvelope.request.reason}`); | |
return handlerInput.responseBuilder.getResponse(); | |
}, | |
}; | |
const ErrorHandler = { | |
canHandle() { | |
return true; | |
}, | |
handle(handlerInput, error) { | |
console.log(`Error handled: ${error.message}`); | |
return handlerInput.responseBuilder | |
.speak('<say-as interpret-as="interjection">épale ocurrió un error</say-as>') | |
.reprompt('Lo siento, ocurrió un error') | |
.getResponse(); | |
}, | |
}; | |
const SKILL_NAME = 'Poesia Urbana'; | |
const GET_FACT_MESSAGE = ''; | |
const HELP_MESSAGE = ' Puedes decir: Escribe poesía para alguien... o simplemente para detenerme puedes decir: ¡Cancela!... ¿Cómo te puedo ayudar?'; | |
const HELP_REPROMPT = '¿Cómo te puedo ayudar?'; | |
const STOP_MESSAGE = 'Adios y <say-as interpret-as="interjection">buena suerte</say-as>'; | |
const skillBuilder = Alexa.SkillBuilders.standard(); | |
exports.handler = skillBuilder | |
.addRequestHandlers( | |
LaunchRequestHandler, | |
PoesiaHandler, | |
HelpHandler, | |
ExitHandler, | |
SessionEndedRequestHandler | |
) | |
.addErrorHandlers(ErrorHandler) | |
.lambda(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"interactionModel": { | |
"languageModel": { | |
"invocationName": "poesía urbana", | |
"intents": [ | |
{ | |
"name": "AMAZON.CancelIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.HelpIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.StopIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.NavigateHomeIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "PoesiaIntent", | |
"slots": [ | |
{ | |
"name": "nombre", | |
"type": "AMAZON.FirstName" | |
} | |
], | |
"samples": [ | |
"escribe poesía", | |
"dame un poema", | |
"escribe un poema", | |
"un poema", | |
"unas líneas para {nombre}", | |
"un poema para {nombre}", | |
"poema para {nombre}", | |
"escribe poesia para {nombre}" | |
] | |
}, | |
{ | |
"name": "AMAZON.PauseIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.ResumeIntent", | |
"samples": [] | |
} | |
], | |
"types": [] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "APL", | |
"version": "1.0", | |
"theme": "dark", | |
"import": [], | |
"resources": [], | |
"styles": {}, | |
"layouts": {}, | |
"mainTemplate": { | |
"items": [ | |
{ | |
"type": "Frame", | |
"height": "100vh", | |
"width": "100vw", | |
"backgroundColor": "purple", | |
"items": [ | |
{ | |
"type": "Container", | |
"height": "100vh", | |
"width": "100vw", | |
"direction": "column", | |
"alignItems": "center", | |
"justifyContent": "center", | |
"items": [ | |
{ | |
"type": "Text", | |
"text": "Poesía Urbana" | |
}, | |
{ | |
"type": "Text", | |
"text": "¡Bienvenidos!" | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "APL", | |
"version": "1.0", | |
"theme": "dark", | |
"import": [ | |
{ | |
"name": "alexa-layouts", | |
"version": "1.0.0" | |
} | |
], | |
"resources": [ | |
{ | |
"description": "Stock color for the light theme", | |
"colors": { | |
"colorTextPrimary": "#151920" | |
} | |
}, | |
{ | |
"description": "Stock color for the dark theme", | |
"when": "${viewport.theme == 'dark'}", | |
"colors": { | |
"colorTextPrimary": "#f0f1ef" | |
} | |
}, | |
{ | |
"description": "Standard font sizes", | |
"dimensions": { | |
"textSizeBody": 48, | |
"textSizePrimary": 27, | |
"textSizeSecondary": 23, | |
"textSizeSecondaryHint": 25 | |
} | |
}, | |
{ | |
"description": "Common spacing values", | |
"dimensions": { | |
"spacingThin": 6, | |
"spacingSmall": 12, | |
"spacingMedium": 24, | |
"spacingLarge": 48, | |
"spacingExtraLarge": 72 | |
} | |
}, | |
{ | |
"description": "Common margins and padding", | |
"dimensions": { | |
"marginTop": 40, | |
"marginLeft": 60, | |
"marginRight": 60, | |
"marginBottom": 40 | |
} | |
} | |
], | |
"styles": { | |
"textStyleBase": { | |
"description": "Base font description; set color and core font family", | |
"values": [ | |
{ | |
"color": "@colorTextPrimary", | |
"fontFamily": "Amazon Ember" | |
} | |
] | |
}, | |
"textStyleBase0": { | |
"description": "Thin version of basic font", | |
"extend": "textStyleBase", | |
"values": { | |
"fontWeight": "100" | |
} | |
}, | |
"textStyleBase1": { | |
"description": "Light version of basic font", | |
"extend": "textStyleBase", | |
"values": { | |
"fontWeight": "300" | |
} | |
}, | |
"mixinBody": { | |
"values": { | |
"fontSize": "@textSizeBody" | |
} | |
}, | |
"mixinPrimary": { | |
"values": { | |
"fontSize": "@textSizePrimary" | |
} | |
}, | |
"mixinSecondary": { | |
"values": { | |
"fontSize": "@textSizeSecondary" | |
} | |
}, | |
"textStylePrimary": { | |
"extend": [ | |
"textStyleBase1", | |
"mixinPrimary" | |
] | |
}, | |
"textStyleSecondary": { | |
"extend": [ | |
"textStyleBase0", | |
"mixinSecondary" | |
] | |
}, | |
"textStyleBody": { | |
"extend": [ | |
"textStyleBase1", | |
"mixinBody" | |
] | |
}, | |
"textStyleSecondaryHint": { | |
"values": { | |
"fontFamily": "Bookerly", | |
"fontStyle": "italic", | |
"fontSize": "@textSizeSecondaryHint", | |
"color": "@colorTextPrimary" | |
} | |
} | |
}, | |
"layouts": {}, | |
"mainTemplate": { | |
"parameters": [ | |
"payload" | |
], | |
"items": [ | |
{ | |
"when": "${viewport.shape == 'round'}", | |
"type": "Container", | |
"direction": "column", | |
"items": [ | |
{ | |
"type": "Image", | |
"source": "${payload.bodyTemplate7Data.backgroundImage.sources[0].url}", | |
"scale": "best-fill", | |
"position": "absolute", | |
"width": "100vw", | |
"height": "100vh" | |
}, | |
{ | |
"type": "AlexaHeader", | |
"headerTitle": "${payload.bodyTemplate7Data.title}", | |
"headerAttributionImage": "${payload.bodyTemplate7Data.logoUrl}" | |
}, | |
{ | |
"type": "Container", | |
"grow": 1, | |
"alignItems": "center", | |
"justifyContent": "center", | |
"items": [ | |
{ | |
"type": "Image", | |
"source": "${payload.bodyTemplate7Data.image.sources[0].url}", | |
"scale": "best-fill", | |
"width": "100vh", | |
"height": "70vw", | |
"align": "center" | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"type": "Container", | |
"items": [ | |
{ | |
"type": "Image", | |
"source": "${payload.bodyTemplate7Data.backgroundImage.sources[0].url}", | |
"scale": "best-fill", | |
"position": "absolute", | |
"width": "100vw", | |
"height": "100vh" | |
}, | |
{ | |
"type": "AlexaHeader", | |
"headerTitle": "${payload.bodyTemplate7Data.title}", | |
"headerAttributionImage": "${payload.bodyTemplate7Data.logoUrl}" | |
}, | |
{ | |
"type": "Container", | |
"direction": "row", | |
"paddingLeft": "5vw", | |
"paddingRight": "5vw", | |
"paddingBottom": "5vh", | |
"alignItems": "center", | |
"justifyContent": "center", | |
"items": [ | |
{ | |
"type": "Image", | |
"height": "75vh", | |
"width": "90vw", | |
"source": "${payload.bodyTemplate7Data.image.sources[0].url}", | |
"scale": "best-fill", | |
"align": "center" | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment