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

@boxoffice/alexa-chatbase-interceptors

v1.0.2

Published

Provides interceptors to track interactions on Alexa custom skill with Chatbase

Downloads

2

Readme

Chatbase integration for Alexa custom skill

Installation

npm install @boxoffice/alexa-chatbase-interceptors

Usage

Simply initialize the interceptors with your Chatbase API key and add them to your skill's lambda.

const Alexa = require('ask-sdk-core')
const chatbase = require('@boxoffice/alexa-chatbase-interceptors')

const {
  ChatbaseRequestInterceptor,
  ChatbaseResponseInterceptor,
  ChatbaseInterceptingErrorHandler
} = chatbase(process.env.CHATBASE_API_KEY)

// ... declare your handlers and interceptors

module.exports.handler = Alexa.SkillBuilders.custom()

  // ChatbaseRequestInterceptor aggregates data from the request to track
  // the user's request. The order of the interceptors does not matter.
  .addRequestInterceptors(
    ...requestInterceptors,
    ChatbaseRequestInterceptor
  )

  // ChatbaseInterceptingErrorHandler does not actually handle errors.
  // It uses the canHandle method to set the not_handled flag on the user
  // request. For this reason, you should set it as the first error
  // handler to intercept all errors.
  .addErrorHandlers(
    ChatbaseInterceptingErrorHandler,
    ...errorHandlers
  )

  // ChatbaseResponseInterceptor aggregates data from the response and
  // sends all tracking information to your Chatbase app. To be as accurate
  // as possible in terms of response time, it should be put last.
  .addResponseInterceptors(
    ...responseInterceptors,
    ChatbaseResponseInterceptor
  )

  // After that, nothing changes
  .addRequestHandlers(...requestHandlers)
  .lambda()

Optionally, if you want to set a response intent or mark a request as not handled (see the Chatbase not_handled concept), a request attributes is available. By default, the only request marked as not handled are:

  • SessionEndedRequest with ERROR as reason
  • IntentRequest with AMAZON.FallbackIntent as intent name
const SendTomatoHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
      && Alexa.getIntentName(handlerInput.requestEnvelope) === 'SingASongIntent',
  },
  handle(handlerInput) {
    // Set your skill's intent
    handlerInput
      .attributesManager.getRequestAttributes()
      .chatbase.setResponseIntent('SendTomato')

    // Proceed with sending a tomato
  }
}

const UnhandledRequestHandler = {
  canHandle() {
    return true
  },
  handle(handlerInput) {
    // Mark this user request as not handled
    handlerInput
      .attributesManager.getRequestAttributes()
      .chatbase.setRequestAsNotHandled()

    // Proceed with fixing the situation
  },
}

Options

You can provide custom options to the interceptors builder by passing on option oject after the API key. Here are the default options :

const chatbase = require('@boxoffice/alexa-chatbase-interceptors')

const options = {
  // The platform to use when pushing to events to chatbase
  // Platform can be used as a filter in Chatbase dashboard and should be use to differenciate
  // your live environment from your dev/staging one.
  platform: `alexa-${process.env.NODE_ENV || 'default'}`,
}

const interceptors = chatbase(process.env.CHATBASE_API_KEY, options)