Skip to content

Instantly share code, notes, and snippets.

@armonge
Last active March 27, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armonge/c7c82bce5002b90f039559aa1d4fee35 to your computer and use it in GitHub Desktop.
Save armonge/c7c82bce5002b90f039559aa1d4fee35 to your computer and use it in GitHub Desktop.
Add skill
'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);
{
"intents": [
{
"intent": "LaunchIntent"
},
{
"intent": "AMAZON.NoIntent"
},
{
"intent": "SumIntent",
"slots": [
{
"name": "number",
"type": "AMAZON.NUMBER"
}
]
}
]
}
{
"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 <andresm@rain.agency>",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.4",
"voxa": "^2.1.0"
}
}
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