Last active
March 27, 2017 22:02
-
-
Save armonge/c7c82bce5002b90f039559aa1d4fee35 to your computer and use it in GitHub Desktop.
Add skill
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
'use strict'; | |
const Voxa = require('voxa'); | |
const _ = require('lodash'); | |
const views = { | |
Hello: { | |
ask: 'Hello! Welcome to the Add skill, what is the first number?', | |
}, | |
waitingForInput: { | |
ask: 'Do you have other number to add?' | |
}, | |
SumIntent: { | |
tell: 'Your result is {result}' | |
} | |
}; | |
const variables = { | |
result: function(model) { | |
return model.result; | |
}, | |
} | |
const skill = new Voxa({ views, variables }); | |
skill.onIntent('LaunchIntent', function(event) { | |
return { reply: 'Hello', to: 'waitingForInput' }; | |
}); | |
skill.onState('waitingForInput', function(event) { | |
if (!event.model.values) { event.model.values = [] } | |
if (event.intent.name === 'SumIntent') { | |
event.model.values.push(parseInt(event.intent.params.number)); | |
return { reply: 'waitingForInput', to: 'waitingForInput' }; | |
} | |
if (event.intent.name === 'AMAZON.NoIntent') { | |
event.model.result = _.sum(event.model.values); | |
return { reply: 'SumIntent' }; | |
} | |
}) | |
exports.handler = skill.startServer(3000); |
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
{ | |
"intents": [ | |
{ | |
"intent": "LaunchIntent" | |
}, | |
{ | |
"intent": "AMAZON.NoIntent" | |
}, | |
{ | |
"intent": "SumIntent", | |
"slots": [ | |
{ | |
"name": "number", | |
"type": "AMAZON.NUMBER" | |
} | |
] | |
} | |
] | |
} |
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
{ | |
"name": "alexa-sample", | |
"version": "1.0.0", | |
"description": "Un ejemplo de Alexa", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Andres Reyes Monge <[email protected]>", | |
"license": "ISC", | |
"dependencies": { | |
"lodash": "^4.17.4", | |
"voxa": "^2.1.0" | |
} | |
} |
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
SumIntent my number is {number} | |
SumIntent {number} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment