Neutralize Pesky Miscreants
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

ask-sdk-addon

1.2.1 • Public • Published

Addon package for the Alexa Skills Kit SDK

Build Status npm version

Installation

npm install ask-sdk-addon

Features

Handlers

NamedIntentRequestHandler

When creation RequestHandler you can extend the NamedIntentRequestHandler and specify the intent name instead of implementing the canHandle method.

The following RequestHandler will handle requests for the intents SomeIntent and FoobarIntent.

import {NamedIntentRequestHandler} from 'ask-sdk-addon';
 
class SomeIntentRequestHandler extends NamedIntentRequestHandler {
    constructor() {
        super('SomeIntent', 'FoobarIntent');
    }
 
    public handle(handlerInput : HandlerInput) : Promise<Response> | Response {
        return null;
    }
}

The following RequestHandler will handle LaunchRequests.

import {NamedIntentRequestHandler} from 'ask-sdk-addon';
 
class LaunchRequestHandler extends NamedIntentRequestHandler {
    constructor() {
        super('LaunchRequest');
    }
 
    public handle(handlerInput : HandlerInput) : Promise<Response> | Response {
        return null;
    }
}

AudioPlayerRequestHandler

You can extend the AudioPlayerRequestHandler and implement the methods to facilitate the processing of AudioPlayer events.

import {AudioPlayerRequestHandler} from 'ask-sdk-addon';
 
class TestHandler extends AudioPlayerRequestHandler {
 
    public handlePlaybackFailed(handlerInput : HandlerInput) : Promise<Response> | Response {
         // Handle event
    }
 
    public handlePlaybackFinished(handlerInput : HandlerInput) : Promise<Response> | Response {
         // Handle event
    }
    
    public handlePlaybackNearlyFinished(handlerInput : HandlerInput) : Promise<Response> | Response {
         // Handle event
    }
 
    public handlePlaybackStarted(handlerInput : HandlerInput) : Promise<Response> | Response {
         // Handle event
    }
 
    public handlePlaybackStopped(handlerInput : HandlerInput) : Promise<Response> | Response {
         // Handle event
    }
 
}

Helper

SlotHelper

Use the SlotHelper to get slot values or entity resolutions from slots.

Create an instance of the SlotHelper with new SlotHelper(requestEnvelope).

You can now call getValue or resolveFirstValue to get appropriate slot values.

import {SlotHelper} from 'ask-sdk-addon';
 
    async handle({requestEnvelope}) {
        const slotHelper = new SlotHelper(requestEnvelope);
        
        let attr = slotHelper.resolveFirstValue('attribute');
        console.log(`Resolution Id: ${attr.id}`);
        
        let value = slotHelper.getValue('attribute');
        console.log(`Slot Value: ${value}`);
        
        // ... more code
    }

Using the isConfirmed method you can get the confirmation status of the intent and slots.

ResponseHelper

Use the ResponseHelper to add additional features to skill responses.

Create an instance of the ResponseHelper with new ResponseHelper(responseBuilder).

You can now call the additional methods for enhanced features.

import {ResponseHelper} from 'ask-sdk-addon';
 
    async handle({requestEnvelope, responseBuilder}) {
        const responseHelper = new ResponseHelper(responseBuilder);
        
        responseHelper.speakOneOf(['OutputSpeech 1', 'OutputSpeech 2']);
        
        // ... more code
    }

DisplayTemplateBuilder

Use the DisplayTemplateBuilder to ease the creation of RenderTemplates for display devices like Echo Show and Echo Spot.

Create an instance of the Builder with new DisplayTemplateBuilder({type: 'BodyTemplate2'}).

import {DisplayTemplateBuilder} from 'ask-sdk-addon';
 
if (DisplayTemplateBuilder.isDisplaySupported(handlerInput.requestEnvelope)) {
    const builder : DisplayTemplateBuilder = new DisplayTemplateBuilder({type: 'BodyTemplate2'});
    builder.withToken('superToken').withBackButton().withImage(myImageUrl).withTitle('Template Title');
    builder.withPrimaryRichText('<i>Some Text:</i> Lorem ipsum');
    handlerInput.responseBuilder.addRenderTemplateDirective(builder.getTemplate());
}
 

InterfaceHelper

The InterfaceHelper helps you determine which interfaces are supported by the calling device.

import {InterfaceHelper} from 'ask-sdk-addon';
 
InterfaceHelper.isAudioPlayerSupported(requestEnvelope);
InterfaceHelper.isVideoPlayerSupported(requestEnvelope);
InterfaceHelper.isDisplaySupported(requestEnvelope);

Interceptor

LogRequestInterceptor

This interceptor logs all incoming requests to the console

import {SkillBuilders} from 'ask-sdk';
import {LogRequestInterceptor} from 'ask-sdk-addon';
 
SkillBuilders.custom().addRequestInterceptors(new LogRequestInterceptor());

PersistAttributesInterceptor

This interceptor saves the persistent attributes to the data store

import {SkillBuilders} from 'ask-sdk';
import {PersistAttributesInterceptor} from 'ask-sdk-addon';
 
SkillBuilders.custom().addResponseInterceptors(new PersistAttributesInterceptor());

install

npm i ask-sdk-addon

Downloadsweekly downloads

17

version

1.2.1

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability