0.2.1 • Published 10 years ago
alexa-ability-stash v0.2.1
alexa-ability-stash 
An alexa-ability middleware for persistent user storage.
Warning: Still in development. Not suitable for use in production yet.
Example
import { Ability } from 'alexa-ability';
import { handleAbility } from 'alexa-ability-lambda-handler';
import createStash from 'alexa-ability-stash';
import createRedisStore from 'connect-redis'; // or any compatible express-session store
const RedisStore = createRedisStore(createStash);
const store = new RedisStore(options);
const app = new Ability();
app.use(createStash({ store }));
app.on('LuckyNumberIntent', function(req, next) {
if (!req.stash.luckyNumber) {
// persisted "forever"
req.stash.luckyNumber = Math.floor(Math.random() * 100 + 1);
}
req.say(`Your lucky number is ${req.stash.luckyNumber}!`).end();
});
export const handler = handleAbility(app);API
createStash(options) -> middleware
Creates a middleware function to handle the stash.
Takes the following options:
store- one of the stores defined belowgenid- a function that takes a request object and returns a string. Returns<appId>:<userId>by default.unset- Behavior whenreq.stashis deleted.destroyorkeep. Defaults tokeep.keepThe stash will be kept, but modifications made during the request are ignored and not saved.destroy: The stash will be destroyed (deleted) when the response ends.
resaveForces the stash to be saved, even if the stash was never modified. Defaults totrue.
Attaches two properties to the request object:
stashan object you can read and modify. Changes will be saved across requests.stashIdthe id generated bygenid.
Stores
Theoretically all the store supported by express-session should work. In practice, only connect-redis has been tested.
If a store doesn't work for you raise an issue!