npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

intent-handler

v1.0.0

Published

A utility for the Node ASK SDK that provides readable intent flow.

Downloads

2

Readme

intent-handler

A wrapper for the Node ASK SDK that provides readable intent flow.

Installation

  1. Install dependency npm install intent-handler --save
  2. Import the intent handler const Handler = require('intent-handler')

Usage

Out of the box, the Node ASK SDK lets us choose which handler is executed for a given request. This is done with the following:

canHandle(handlerInput) {
  return handlerInput.requestEnvelope.request.type === 'IntentRequest'
    && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},

With the intent-handler module you can now make canHandle() methods much more readable in your Alexa skills.

const Handler = require('intent-handler')

canHandle(handlerInput) {
  const handler = Handler(handlerInput);

  return handler.isIntent('HelloWorldIntent').canHandle();
},

Create an instance of the class, chain the necessary checks, then call canHandle() to perform validation.

Display Templates

Display Templates can be used to present information on an echo devices screen. Using these in an intent handler will causes devices that do not support Display interfaces to fail.

This can be solved by using the doesSupport() method to create two separate handlers for display devices, and non display devices.

Scope on Display for an intent:

canHandle(handlerInput) {
  return Handler(handlerInput)
    .isIntent('MyIntent')
    .doesSupport('Display') // User has a Echo Show or Echo Spot.
    .canHandle();
},
handler {
  // Use features only supported on Display devices.
}

And create a handler for non Display devices:

canHandle(handlerInput) {
  return Handler(handlerInput)
    .isIntent('MyIntent')
    .doesNotSupport('Display') // User has a standard audio only Echo device.
    .canHandle();
},
handler {
  // Use features supported on every device.
}

Handling Multiple Intents

Sometimes you want the same handler to handle multiple intents, with optional requirements. This can be done by chaining the or() method onto the handler.

Handler(handlerInput)
  .isIntent("MyIntent")
  .hasAttributes(["name"])
  .or()
  .isIntent("MyOtherIntent")
  .canHandle();

API

isType(type)

Check if a request is a certain type.

Handler(handlerInput)
  .isType("IntentRequest")
  .canHandle();

isIntent(intentName)

Check if a request is any of the given intents.

Handler(handlerInput)
  .isIntent("TestIntent")
  .canHandle();

hasSlots(slots)

Check if a request has all of the given slots filled.

Returns true if request has every slot value filled.

Handler(handlerInput)
  .hasSlots(["name"]) // User has given name so we can store it as an attribute.
  .canHandle();

hasAttributes(attributes)

Check if a request contains one or many attributes.

Returns true if request has every attribute.

Handler(handlerInput)
  .hasAttributes(["name"]) // User has given name so we can reply using their name.
  .canHandle();

doesSupport(displayInterfaces)

Check if the device that sent the request supports the given interface.

Lets us show information on an Echo device that has a screen for example.

Handler(handlerInput)
  .doesSupport("Display") // User has a Echo Show or Echo Spot.
  .canHandle();

doesNotSupport(displayInterfaces)

Check if the device that sent the request does not support the given interface.

Lets us prevent a Display specific handler from handling an intent on an audio only device.

Handler(handlerInput)
  .doesNotSupport("Display") // User isn't using a Echo Show or Echo Spot.
  .canHandle();