alexa-ability
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -28,4 +28,2 @@ 'use strict'; | ||
var _resolve = require('./resolve'); | ||
var _verifyApplication = require('./middleware/verifyApplication'); | ||
@@ -35,2 +33,4 @@ | ||
var _handleRequest = require('./handleRequest'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -45,3 +45,2 @@ | ||
var oLog = (0, _debug2.default)('alexa-ability:ability:on'); | ||
var hLog = (0, _debug2.default)('alexa-ability:ability:handle'); | ||
@@ -122,5 +121,2 @@ var warnAppId = function warnAppId() { | ||
var stack = [].concat(_toConsumableArray(this._stack)); | ||
var index = 0; | ||
// build request object and attach listeners | ||
@@ -152,35 +148,3 @@ var req = new _Request.Request(event); | ||
// this function gives up execution to the next handler | ||
function next(err) { | ||
// halt execution early if response has been sent | ||
if (req.sent) { | ||
warnSent(); | ||
return; | ||
} | ||
// no more handlers? fail | ||
if (index >= stack.length) { | ||
done(err); | ||
return; | ||
} | ||
var fn = stack[index++]; | ||
var fnName = fn.name || fn.displayName || 'anonymous'; | ||
if (fn.length >= 3 && err) { | ||
hLog('executing error handler: <' + fnName + '>'); | ||
(0, _resolve.resolve)(fn, next, err, req); | ||
} else if (fn.length < 3 && !err) { | ||
// all's well! try the handler | ||
hLog('executing handler: <' + fnName + '>'); | ||
(0, _resolve.resolve)(fn, next, req); | ||
} else { | ||
// not correct type of handler | ||
hLog('skipping handler: <' + fnName + '>'); | ||
next(err); | ||
} | ||
} | ||
// start execution | ||
next(); | ||
(0, _handleRequest.handleRequest)(req, this._stack, done); | ||
return req; | ||
@@ -187,0 +151,0 @@ } |
{ | ||
"name": "alexa-ability", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "An Alexa skills framework for node", | ||
@@ -10,4 +10,4 @@ "main": "lib/index.js", | ||
"pretest": "npm run lint", | ||
"test": "mocha test --opts mocha.opts", | ||
"prepublish": "npm run test && npm run build", | ||
"test": "mocha test", | ||
"prepublish": "in-publish && npm run test && npm run build || not-in-publish", | ||
"publish:major": "npm version major && npm publish", | ||
@@ -57,2 +57,3 @@ "publish:minor": "npm version minor && npm publish", | ||
"eslint-plugin-react": "^3.16.1", | ||
"in-publish": "^2.0.0", | ||
"mocha": "^2.3.4", | ||
@@ -59,0 +60,0 @@ "sinon": "^1.17.2", |
@@ -5,2 +5,3 @@ # alexa-ability [![Build Status](https://travis-ci.org/nickclaw/alexa-ability.svg?branch=master)](https://travis-ci.org/nickclaw/alexa-ability) | ||
- [Read the docs](docs/) | ||
- [Try the interactive demo](https://tonicdev.com/nickclaw/alexa-ability-demo) | ||
- [View the examples](examples/) | ||
@@ -19,4 +20,6 @@ - [Contribute!](CONTRIBUTING.md) | ||
* [alexa-ability-express-handler](https://npmjs.org/package/alexa-ability-express-handler) - Expose abilities as Express endpoints | ||
* [alexa-ability-async-handler](https://npmjs.org/package/alexa-ability-async-handler) - Promise creating handler for abilities | ||
* [alexa-ability-timeout](https://npmjs.org/alexa-ability-timeout) - Middleware to prevent your skills from stalling. | ||
* [alexa-ability-context](https://npmjs.org/alexa-ability-context) - Middleware to simplify building multistep conversations. | ||
* [alexa-ability-stash](https://npmjs.org/alexa-ability-stash) - Middleware to easily persist user data (a lot like [express-session](https://npmjs.org/express-session)). | ||
* [alexa-utterances](https://npmjs.org/package/alexa-utterances) - Easily generate an exhaustive list of utterances from a few template strings. | ||
@@ -40,3 +43,3 @@ * [alexa-ssml](https://npmjs.org/package/alexa-ssml) - Manipulate and validate SSML using the [jsx](https://facebook.github.io/react/docs/jsx-in-depth.html) syntax | ||
app.use(function(req, next) { | ||
logRequest(req); | ||
console.log('Handling:', req); | ||
next(); | ||
@@ -47,3 +50,3 @@ }); | ||
// handle LaunchRequest - "Alexa, launch MyApp" | ||
ability.on(events.launch, function(req, next) { | ||
app.on(events.launch, function(req, next) { | ||
const cardTitle = 'Greetings'; | ||
@@ -62,3 +65,3 @@ const cardContent = 'Hello world!'; | ||
// handle SessionEndedRequest - "Alexa stop" | ||
ability.on(events.end, function(req, next) { | ||
app.on(events.end, function(req, next) { | ||
console.log(`Session ended because: ${req.reason}`); | ||
@@ -70,3 +73,3 @@ req.say('Goodbye!').end(); | ||
// handle custom intents | ||
ability.on('MeaningOfLifeIntent', function(req, next) { | ||
app.on('MeaningOfLifeIntent', function(req, next) { | ||
asyncRequest(function(err) { | ||
@@ -80,3 +83,3 @@ if (err) return next(err); | ||
// catches any unhandled requests | ||
ability.use(function(req, next) { | ||
app.use(function(req, next) { | ||
req.say('I don\'t know what to say').end(); | ||
@@ -87,3 +90,3 @@ }); | ||
// gracefully handles any uncaught errors | ||
ability.use(function(err, req, next) { | ||
app.use(function(err, req, next) { | ||
req.say('Uhoh, something went wrong').end(); | ||
@@ -94,3 +97,3 @@ }); | ||
// export as a lambda handler | ||
export const handler = handleAbility(ability); | ||
export const handler = handleAbility(app); | ||
``` |
38292
509
91
13