UNPKG

@jargon/alexa-skill-sdk

Version:

The Jargon Alexa Skill SDK makes it easy to manage the content of your custom Alexa skill

196 lines (195 loc) 9.42 kB
import { canfulfill, Directive, Intent, interfaces, Response, ui } from 'ask-sdk-model'; import AudioItemMetadata = interfaces.audioplayer.AudioItemMetadata; import { RenderItem } from '@jargon/sdk-core'; /** * Options that modify the default response builder behavior for a specific call. * These flags may be Jargon-specific (such as merge) or come from the ASK response * builder (playBehavior). */ export interface ResponseGenerationOptions { /** * If provided, overrides the mergeSpeakAndReprompt setting in the response builder's options. * True merges the rendered content with previously rendered content; false replaces any previous content */ merge?: boolean; /** Optional playBehavior parameter for speak and reprompt (for ASK v2.4.0 and greater) */ playBehavior?: ui.PlayBehavior; } /** * Type alias for response builder parameters that were previously optional * booleans (for merge), but that can now also take a ResponseGenerationOptions instance */ export declare type RGOParam = ResponseGenerationOptions | boolean; /** * JargonResponseBuilder mirrors the ASK response builder, but takes RenderItems instead * of raw strings for parameters that end up being spoken or displayed to the end user. */ export interface JargonResponseBuilder { /** * Has Alexa say the provided speech to the user * @param {RenderItem} speechOutput The item to render for the speech content * @param {RGOParam} optionsOrMerge Options to control response generation behavior. A boolean value * is treated as ResponseGenerationOptions.merge (for backwards compatibility) * @returns {ResponseBuilder} */ speak(speechOutput: RenderItem, optionsOrMerge?: RGOParam): this; /** * Has alexa listen for speech from the user. If the user doesn't respond within 8 seconds * then has alexa reprompt with the provided reprompt speech * @param {RenderItem} repromptSpeechOutput The item to render for the reprompt content * @param {RGOParam} optionsOrMerge Options to control response generation behavior. A boolean value * is treated as ResponseGenerationOptions.merge (for backwards compatibility) * @returns {ResponseBuilder} */ reprompt(repromptSpeechOutput: RenderItem, optionsOrMerge?: RGOParam): this; /** * Renders a simple card with the following title and content * @param {RenderItem} cardTitle * @param {RenderItem} cardContent * @returns {JargonResponseBuilder} */ withSimpleCard(cardTitle: RenderItem, cardContent: RenderItem): this; /** * Renders a standard card with the following title, content and image * @param {RenderItem} cardTitle * @param {RenderItem} cardContent * @param {string} smallImageUrl * @param {string} largeImageUrl * @returns {JargonResponseBuilder} */ withStandardCard(cardTitle: RenderItem, cardContent: RenderItem, smallImageUrl?: string, largeImageUrl?: string): this; /** * Renders a link account card * @returns {JargonResponseBuilder} */ withLinkAccountCard(): this; /** * Renders an askForPermissionsConsent card * @param {string[]} permissionArray * @returns {JargonResponseBuilder} */ withAskForPermissionsConsentCard(permissionArray: string[]): this; /** * Adds a Dialog delegate directive to response * @param {Intent} updatedIntent * @returns {JargonResponseBuilder} */ addDelegateDirective(updatedIntent?: Intent): this; /** * Adds a Dialog elicitSlot directive to response * @param {string} slotToElicit * @param {Intent} updatedIntent * @returns {JargonResponseBuilder} */ addElicitSlotDirective(slotToElicit: string, updatedIntent?: Intent): this; /** * Adds a Dialog confirmSlot directive to response * @param {string} slotToConfirm * @param {Intent} updatedIntent * @returns {JargonResponseBuilder} */ addConfirmSlotDirective(slotToConfirm: string, updatedIntent?: Intent): this; /** * Adds a Dialog confirmIntent directive to response * @param {Intent} updatedIntent * @returns {JargonResponseBuilder} */ addConfirmIntentDirective(updatedIntent?: Intent): this; /** * Adds an AudioPlayer play directive * @param {interfaces.audioplayer.PlayBehavior} playBehavior Describes playback behavior. Accepted values: * REPLACE_ALL: Immediately begin playback of the specified stream, and replace current and enqueued streams. * ENQUEUE: Add the specified stream to the end of the current queue. * This does not impact the currently playing stream. * REPLACE_ENQUEUED: Replace all streams in the queue. This does not impact the currently playing stream. * @param {string} url Identifies the location of audio content at a remote HTTPS location. * The audio file must be hosted at an Internet-accessible HTTPS endpoint. * HTTPS is required, and the domain hosting the files must present a valid, trusted SSL certificate. * Self-signed certificates cannot be used. * The supported formats for the audio file include AAC/MP4, MP3, HLS, PLS and M3U. Bitrates: 16kbps to 384 kbps. * @param {string} token A token that represents the audio stream. This token cannot exceed 1024 characters * @param {number} offsetInMilliseconds The timestamp in the stream from which Alexa should begin playback. * Set to 0 to start playing the stream from the beginning. * Set to any other value to start playback from that associated point in the stream * @param {string} expectedPreviousToken A token that represents the expected previous stream. * This property is required and allowed only when the playBehavior is ENQUEUE. * This is used to prevent potential race conditions if requests to progress * through a playlist and change tracks occur at the same time. * @param {interfaces.audioplayer.AudioItemMetadata} audioItemMetadata Metadata that can be displayed on screen enabled devices * @returns {JargonResponseBuilder} */ addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string, audioItemMetadata?: AudioItemMetadata): this; /** * Adds an AudioPlayer Stop directive - Stops the current audio Playback * @returns {JargonResponseBuilder} */ addAudioPlayerStopDirective(): this; /** * Adds an AudioPlayer ClearQueue directive - clear the queue without stopping the currently playing stream, * or clear the queue and stop any currently playing stream. * * @param {interfaces.audioplayer.ClearBehavior} clearBehavior Describes the clear queue behavior. * Accepted values: * CLEAR_ENQUEUED: clears the queue and continues to play the currently playing stream * CLEAR_ALL: clears the entire playback queue and stops the currently playing stream (if applicable). * @returns {JargonResponseBuilder} */ addAudioPlayerClearQueueDirective(clearBehavior: interfaces.audioplayer.ClearBehavior): this; /** * Adds a Display RenderTemplate Directive * @param {interfaces.display.Template} template * @returns {JargonResponseBuilder} */ addRenderTemplateDirective(template: interfaces.display.Template): this; /** * Adds a hint directive - show a hint on the screen of the echo show * @param {RenderItem} text plain text to show on the hint * @returns {JargonResponseBuilder} */ addHintDirective(text: RenderItem): this; /** * Adds a VideoApp play directive to play a video * * @param {string} source Identifies the location of video content at a remote HTTPS location. * The video file must be hosted at an Internet-accessible HTTPS endpoint. * @param {RenderItem} title (optional) title that can be displayed on VideoApp. * @param {RenderItem} subtitle (optional) subtitle that can be displayed on VideoApp. * @returns {JargonResponseBuilder} */ addVideoAppLaunchDirective(source: string, title?: RenderItem, subtitle?: RenderItem): this; /** * Adds canFulfillIntent to response. * @param {canfulfill.CanFulfillIntent} canFulfillIntent * @return {ResponseBuilder} */ withCanFulfillIntent(canFulfillIntent: canfulfill.CanFulfillIntent): this; /** * Sets shouldEndSession value to null/false/true * @param {boolean} val * @returns {JargonResponseBuilder} */ withShouldEndSession(val: boolean): this; /** * Helper method for adding directives to responses * @param {Directive} directive the directive send back to Alexa device * @returns {JargonResponseBuilder} */ addDirective(directive: Directive): this; /** * Returns a promise to the response object * @returns {Promise<Response>} */ getResponse(): Promise<Response>; } /** * Options that alter the response builder's default behavior */ export interface JargonResponseBuilderOptions { /** * If true, repeated calls to speak or reprompt will merge their * inputs into a single string (separated by spaces). If false (default), * a call to speak or reprompt replaces any previous content */ mergeSpeakAndReprompt?: boolean; } export * from './jrb';