Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ControlHandler

RequestHandler for a skill built using Controls.

This is the common runtime that drives the processing flow for a skill that uses Controls. Please see the user guide for a thorough discussion of the phases of processing and how the common ControlHandler interfaces with an instance of ControlManager and the control tree.

Hierarchy

  • ControlHandler

Implements

  • CustomSkillRequestHandler

Constructors

constructor

Properties

Protected Optional canHandleFailureResponse

canHandleFailureResponse: Response

canHandleThrowBehavior

canHandleThrowBehavior: CanHandleExceptionBehavior = "ProduceResponse"

Behavior if an exception occurs during ControlHandler.canHandle.

In all cases, ControlManager.handleInternalError will be called. The options differ in how the response is produced.

ProduceResponse (default) - treat the input as handled, and return the custom response ReturnFalse - treat the input as 'cannot handle'. Rethrow - let the exception bubble up to be processed by CustomSkill.errorHandlers

Usage:

  • The default, 'ProduceResponse', allows ControlManager

controlManager

controlManager: IControlManager

Optional rootControl

rootControl: IControl

validateStateRoundtrip

validateStateRoundtrip: boolean = true

Determines if the controls state will be correctly reestablished on the next turn

Usage:

  • If a skill uses more than one ControlHandler the state validation procedure gets confused due to unexpected control states in session attributes. In this situation, set validateStateRoundtrip = false.

Static attributeNameContext

attributeNameContext: string = "__controlContext"

Methods

canHandle

  • canHandle(handlerInput: HandlerInput): Promise<boolean>
  • Determines if this RequestHandler handle the input.

    Parameters

    • handlerInput: HandlerInput

      HandlerInput

    Returns Promise<boolean>

getSerializableControlStates

  • getSerializableControlStates(): object
  • Returns object

    • [key: string]: any

handle

  • handle(handlerInput: HandlerInput, processInput?: boolean): Promise<Response>
  • Handle the input.

    Parameters

    • handlerInput: HandlerInput

      HandlerInput

    • Default value processInput: boolean = true

    Returns Promise<Response>

takeInitiative

  • takeInitiative(handlerInput: HandlerInput, promptPrefix: string, repromptPrefix?: undefined | string): Promise<Response>
  • Take the initiative in the dialog.

    Any existing content in the Response's prompt & reprompt is overwritten. To avoid losing this content, pass it in using parameters promptPrefix & repromptPrefix.

    Usage:

    • This method is used to transition from a regular RequestHandler into Controls For example, when a regular RequestHandler consumes the input but doesn't want to keep the initiative, it can ask a ControlHandler to take the initiative to complete the turn. A prompt/reprompt fragment can be specified by the RequestHandler which will be included as the start of the overall prompt/reprompt.

    Parameters

    • handlerInput: HandlerInput

      Handler input

    • promptPrefix: string

      Prompt fragment to prefix the prompt generated via Controls.

    • Optional repromptPrefix: undefined | string

      Reprompt fragment to prefix to the prompt generated via Controls

    Returns Promise<Response>

userAgentInfo

  • userAgentInfo(): string
  • Creates a string 'C:' for inclusion in UserAgent to indicate usage.

    The information gathered is only the number of Controls being used. This will help the dev team to understand usage - thank you!

    Returns string

Static getPromptAndRepromptFromResponse

  • getPromptAndRepromptFromResponse(response: Response): [string, string]
  • Parameters

    • response: Response

    Returns [string, string]

Static handleCore

  • Implements the core of the processing loop

    Public for testing

    Parameters

    Returns Promise<void>