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

@matthewp/ask-sdk-helpers

v1.4.0

Published

Helper functions for use with the ask-sdk

Downloads

8

Readme

@matthewp/ask-sdk-helpers

Helper functions for use with the ASK SDK

Usage

Helpers

canHandle functions

The following functions are to be used with the ask-sdk handlers, acting as the canHandle function.

isLaunchRequest()

A canHandle function for launch requests.

const {
  isLaunchRequest
} = require('@matthewp/ask-sdk-helpers');

const LaunchRequestHandler = {
  canHandle: isLaunchRequest(),
  async handle(h) {
    // do whatever
  }
};

isIntentRequest(intentName)

A canHandle function for intent request handlers.

const {
  isIntentRequest
} = require('@matthewp/ask-sdk-helpers');

const ShoppingIntentHandler = {
  canHandle: isIntentRequest('ShoppingIntent'),
  async handle(h) {
    // Do some shopping stuff.
  }
};

isResponseRequest(responseName)

A canHandle function for Connections.Response requests, as used in In-Skill purchases.

Note that you probably want to use IsBuyResponseRequest() and IsCancelResponseRequest() directly instead. This is a lower-level function.

const {
  isResponseRequest
} = require('@matthewp/ask-sdk-helpers');

const ShoppingIntentHandler = {
  canHandle: isResponseRequest('Buy'),
  async handle(h) {
    // Proceed with a purchased item.
  }
};

IsBuyResponseRequest()

Indicates a Connections.Response request with the name Buy. This occurs when the user has gone through the In-Skill purchase buy flow. Use purchaseResult to determine if the user choose to purchase the item or not.

const {
  IsBuyResponseRequest
} = require('@matthewp/ask-sdk-helpers');

const ShoppingIntentHandler = {
  canHandle: IsBuyResponseRequest(),
  async handle(h) {
    // Proceed with a purchased item.
  }
};

IsCancelResponseRequest()

Indicates a Connections.Response request with the name Cancel. This is used in In-Skill purchases when the user goes through a cancellation flow.

const {
  IsCancelResponseRequest
} = require('@matthewp/ask-sdk-helpers');

const ShoppingIntentHandler = {
  canHandle: IsCancelResponseRequest(),
  async handle(h) {
    // Proceed with cancellation
  }
};

isSessionEndedRequest()

Indicates that the session has ended. Use this to do any cleanup necessary at the end of a session.

const {
  isSessionEndedRequest
} = require('@matthewp/ask-sdk-helpers');

const SessionEndedHandler = {
  canHandle: isSessionEndedRequest(),
  async handle(h) {
    // cleanup
  }
};

Request helpers

These helpers are for things related to a request, such as slots and local values.

slot(h, name)

Get a value from a slot.

const {
  isIntentRequest,
  slot
} = require('@matthewp/ask-sdk-helpers');

const AddTodoIntentHandler = {
  canHandle: isIntentRequest('AddTodoIntent'),
  async handle(h) {
    let label = slot(h, 'label');

    // do something with this slot value.
  }
};

SSML

Helpers for building advanced SSML speech patterns.

const {
  isIntentRequest,
  speak,
  pipeResponse,

  ssml,
  pause
} = require('@matthewp/ask-sdk-helpers');

const AnnounceIntentHandler = {
  canHandle: isIntentRequest('AnnounceIntent'),
  async handle(h) {
    return pipeResponse(h)(
      speak(
        ssml(
          'Today was a fantastic win for the home team.',
          pause('3s'),
          'They won with a score of 4 to 2.'
        )
      )
    )
  }
}

ssml(...children)

The ssml helper is a wrapper that is used at the top-level of the SSML speech. It can take any child, such as other ssml elements or just plain text strings.

Although primarily used at the top-level, the ssml helper can be used at any nesting level. When used this way it simply wraps children and concats them.

pause(timeOrOptions)

The pause helper is used for SSML breaks. It is called pause because break is a reserved word in JavaScript.

It can take a time argument like so:

ssml(
  pause('3s')
)

It can also take an object of options:

  • time: The time (as a string) for the break.
  • strength: The relationship between the pause and surrounding speech.
ssml(
  pause({
    time: '3s',
    strength: 'medium'
  })
)

License

BSD 2-Clause