Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alexa-ability-context

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alexa-ability-context

Simplify building multistep conversations with context-aware intent handling

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

alexa-ability-context Build Status

Simplify building multistep conversations with context-aware intent handling.

Example

import { Ability, events } from 'alexa-ability';
import { handleAbility } from 'alexa-ability-lambda-handler';
import { trackContext, context } from 'alexa-ability-context';

// create ability
const app = new Ability({
    applicationId: 'your-app-id'
});


// add middleware to track context
app.use(trackContext());


app.on('OrderPizzaIntent', function(req) {
    req.say('Are you sure you want to order pizza?').send();
});


// check against previous event
app.on(events.yes, context.after('OrderPizzaIntent', function(req) {
    req.say('Are you really really sure?').send();
}));


// do more complex checks with a regex
app.on(events.yes, context.matches(/.*OrderPizzaIntent:AMAZON.YesIntent$/, function(req) {
    orderPizza(function() {
        req.say('Your pizza is on its way!').end();
    });
}));

app.on(events.no, function() {
    req.say('Ok, goodbye.').end();
});

export const handler = handleAbility(app);

API

trackContext(options) -> middleware

A middleware factory that takes an optional options object. The currently supported options are:

  • key: defaults to __context__, the session key to store the context between requests.

The returned middleware will add an additional property to the request object called context. Which will be an array of strings representing every request handled during the session.

context.after(event, handler) -> handler

Creates a new handler function that only executes when the previous intent matches.

The two arguments are:

  • event: an event name
  • handler: a standard alexa-ability handler that accepts req and next as arguments.

The string the regex will be tested against will look like this:

FirstIntent:SecondIntent:ThirdIntent

context.matches(regex, handler) -> handler

Creates a new handler function that only executes when the conversation context matches the given regular expression.

The two arguments are:

  • regex: a regular expression.
  • handler: a standard alexa-ability handler that accepts req and next as arguments.
context.custom(fn, handler) -> handler

Creates a new handler function that only executes when the custom fn returns a true.

The two arguments are:

  • fn: a function that takes in the request object and returns true or false.
  • handler: a standard alexa-ability handler that accepts req and next as arguments.

Keywords

FAQs

Package last updated on 13 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc