New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ask-utils/handlers

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ask-utils/handlers

[![npm version](https://badge.fury.io/js/%40ask-utils%2Fhandlers.svg)](https://badge.fury.io/js/%40ask-utils%2Fhandlers) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Maintainability](https:

latest
Source
npmnpm
Version
3.11.0
Version published
Weekly downloads
30
11.11%
Maintainers
1
Weekly downloads
 
Created
Source

Utility handlers for ASK-SDk (v2)

npm version License: MIT Maintainability Test Coverage Build Status logo

https://ask-utils.dev

You can add general / utility handlers to use this package.

Getting stated

$ npm install -S @ask-utils/handlers

Handlers

RequestHandlers

DeleteUserData

After subscribe AlexaSkillEvent.SkillDisabled event (eventName: 'SKILL_DISABLED'), you can delete a persistent attributes of the user who disabled your skill.

import * as  Alexa from 'ask-sdk'
import { DeleteDisabledUserHandler } from '@ask-utils/handlers'

...
export const handler = Alexa..SkillBuilders.standard()
  .addRequestHandlers(
    ...,
    DeleteDisabledUserHandler
  )
  .lambda()

SessionEndedRequestHandler

Simple handler for SessionEndedRequest.

import * as  Alexa from 'ask-sdk'
import { SessionEndedRequestHandler } from '@ask-utils/handlers'

...
export const handler = Alexa..SkillBuilders.standard()
  .addRequestHandlers(
    ...,
    SessionEndedRequestHandler
  )
  .lambda()

RepeatIntentHandler

Simple handler for AMAZON.RepeatIntent. The handler will return session attributes object as lastResponse. You can easy set the lastResponse attributes into the sessionAttributes by using the RecordTheResponseInterceptor.

import * as  Alexa from 'ask-sdk'
import { RecordTheResponseInterceptor, RepeatIntent } from '@ask-utils/handlers'

...
export const handler = Alexa..SkillBuilders.standard()
  .addRequestHandlers(
    ...,
    RepeatIntent
  )
  .addResponseInterceptors(
    ...,
    RecordTheResponseInterceptor
  )
  .lambda()

RequestHandlerFactort (Beta)

You can easy to create a Alexa request handler

import { RequestHandlerFactory } from '@ask-utils/handlers'

const LaunchRequestHandler = RequestHandlerFactory.create(
    'LaunchRequest',
    {
        handle (handlerInput) {
            return handlerInput.responseBuilder.speak('hello world').getResponse()
        }
    }
)

Interceptors

RequestInterceptors

SetLaunchCountInterceptor

Record the launch count and last launched timestamp. The interceptor will work only new session.

|Name|type||default|description| |:--|:--|:--| |lastLaunch|number?|undefined|Last launch time (UNIX timestamp)| |launchCount|number|0|Launch the skill count.|

import * as  Alexa from 'ask-sdk'
import moment from 'moment'
import { SetLaunchCountInterceptor } from '@ask-utils/handlers'

...
export const handler = Alexa..SkillBuilders.standard()
  .addRequestHandlers(
    {
      canHandle: () => true,
      handle: (handlerInput) => {
        const {
          launchCount,
          lastLaunch
        } = handlerInput.attributesManager.getSessionAttributes()
        const lastLaunchDate = moment.unix(lastLaunch).toISOString()
        ...
      }
    }
  )
  .addRequestInterceptors(
    ...,
    SetLaunchCountInterceptor
  )
  .lambda()

ConstantsInjectionIntereptor

You can inject your skill constants to use requestAttributes.

import * as  Alexa from 'ask-sdk'
import { ConstantsInterceptorFactory } from '@ask-utils/handlers'

const ConstantsInterceptor = ConstantsInterceptorFactory.init({
  SKILL_NAME: 'awesome skill',
  STATE: {
    START: 'START',
    HELP: 'HELP'
  }
})
...
export const handler = Alexa..SkillBuilders.standard()
  .addRequestHandlers(
    {
      canHandle: () => true,
      handle: (handlerInput) => {
        const {
          CONSTANTS
        } = handlerInput.attributesManager.getRequestAttributes()
        const speech = `Welcome to the ${CONSTANTS.SKILL_NAME} skill!`
        ...
      }
    }
  )
  .addRequestInterceptors(
    ...,
    ConstantsInterceptor
  )
  .lambda()

ResponseInterceptors

RecordTheResponseInterceptor

Record the response JSON into the session attributes. If you use handler to handle AMAZON.RepeatIntent, you must use it.

import * as  Alexa from 'ask-sdk'
import { RecordTheResponseInterceptor } from '@ask-utils/handlers'

...
export const handler = Alexa..SkillBuilders.standard()
  .addResponseInterceptors(
    ...,
    RecordTheResponseInterceptor
  )
  .lambda()

Keywords

Alexa

FAQs

Package last updated on 27 Jun 2020

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