import { Intent } from 'ask-sdk-model'; import { ModelData } from '../..'; import { Control, ControlInputHandler, ControlInputHandlingProps, ControlProps, ControlState } from '../../controls/Control'; import { ControlInput } from '../../controls/ControlInput'; import { ControlResultBuilder } from '../../controls/ControlResult'; import { ControlServicesProps } from '../../controls/ControlServices'; import { InteractionModelContributor } from '../../controls/mixins/InteractionModelContributor'; import { StateValidationFunction } from '../../controls/Validation'; import { ControlInteractionModelGenerator } from '../../interactionModelGeneration/ControlInteractionModelGenerator'; import { ResponseStyleEvaluator } from '../../modality/ModalityEvaluation'; import { ControlResponseBuilder } from '../../responseGeneration/ControlResponseBuilder'; import { InvalidValueAct, UnusableInputValueAct, ValueChangedAct, ValueConfirmedAct, ValueDisconfirmedAct, ValueSetAct } from '../../systemActs/ContentActs'; import { ConfirmValueAct, InitiativeAct, RequestChangedValueByListAct, RequestValueByListAct } from '../../systemActs/InitiativeActs'; import { SystemAct } from '../../systemActs/SystemAct'; import { StringOrList } from '../../utils/BasicTypes'; import { DeepRequired } from '../../utils/DeepRequired'; /** * Props for a ListControl. */ export interface ListControlProps extends ControlProps { /** * Unique identifier for control instance */ id: string; /** * Slot type for the value that this control collects. * * Usage: * - The slot type defines the set of expected value items. * - NLU will, on occasion, accept novel slot value and mark them as * ER_NO_MATCH. If you only want to accept values that are explicitly * defined add a validation function to test `this.state.erMatch` */ slotType: string; /** * Function(s) that determine if the value is valid. * * Default: `true`, i.e. any value is valid. * * Usage: * - Validation functions return either `true` or a `ValidationResult` to * describe what validation failed. */ validation?: StateValidationFunction | Array>; /** * List of slot-value IDs that will be presented to the user as a list. */ listItemIDs: string[] | ((input: ControlInput) => string[]); /** * The maximum number of items spoken per turn. */ pageSize?: number; /** * Determines if the Control must obtain a value. * * - If `true` the Control will take initiative to elicit a value. * - If `false` the Control will not take initiative to elicit a value, but the user * can provide one if they wish, e.g. "U: My favorite color is blue". */ required?: boolean | ((input: ControlInput) => boolean); /** * Whether the Control has to obtain explicit confirmation of the value. * * Default: false * * If `true`: * - the Control will take initiative to explicitly confirm the value with a yes/no * question. */ confirmationRequired?: boolean | ((input: ControlInput) => boolean); /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ prompts?: ListControlPromptProps; /** * Props to customize the reprompt fragments that will be added by * `this.renderAct()`. */ reprompts?: ListControlPromptProps; /** * Props to customize the relationship between the control and the * interaction model. */ interactionModel?: ListControlInteractionModelProps; /** * Props to configure input handling. */ inputHandling?: ControlInputHandlingProps; /** * Function that maps the ListControlState.value to rendered value that * will be presented to the user as a list. * * Default: prompt & primaryText set to the value other props default to undefined. */ valueRenderer?: (value: string, input: ControlInput) => ListControlRenderedItem; /** * Props to customize the APL generated by this control. */ apl?: ListControlAPLProps; /** * Props to customize services used by the control. */ services?: ControlServicesProps; /** * Function that determines the preferred response style based on input * and input modality history. * * Default: Function always returns indeterminate response style, which * causes the decision to be deferred to the function configured in ControlManager. */ responseStyleEvaluator?: ResponseStyleEvaluator; } /** * Props to customize the value which will be returned by `this.valueRenderer()`. */ export interface ListControlRenderedItem { /** * Defines the primary Text used to render list Items on APL. * * Default: ListControlState.value */ primaryText?: string; /** * Defines the secondary text used to render list Items on APL. * * Default: '' */ secondaryText?: string; /** * Defines the Image source reference to render listItem images on APL. * */ imageSource?: string; /** * Rendered value which maps to ListControlState.value * that will be presented to the user as a list * * Default: ListControlState.value */ prompt: string; } /** * Mapping of action slot values to the capability that this control supports. * * Behavior: * - This control will not handle an input if the action-slot is filled with an * value whose ID is not associated with a capability. */ export interface ListControlActionProps { /** * Action slot value IDs that are associated with the "set value" capability. * * Default: ['builtin_set', 'builtin_select'] */ set?: string[]; /** * Action slot value IDs that are associated with the "change value" capability. * * Default ['builtin_change'] */ change?: string[]; } /** * Props associated with the interaction model. */ export declare class ListControlInteractionModelProps { /** * Target-slot values associated with this Control. * * Targets associate utterances to a control. For example, if the user says * "change the time", it is parsed as a `GeneralControlIntent` with slot * values `action = change` and `target = time`. Only controls that are * registered with the `time` target should offer to handle this intent. * * Default: `['builtin_it']` * * Usage: * - If this prop is defined, it replaces the default; it is not additive to * the defaults. To add an additional target to the defaults, copy the * defaults and amend. * - A control can be associated with many target-slot-values, eg ['date', * 'startDate', 'eventStartDate', 'vacationStart'] * - It is a good idea to associate with general targets (e.g. date) and * also with specific targets (e.g. vacationStart) so that the user can * say either general or specific things. e.g. 'change the date to * Tuesday', or 'I want my vacation to start on Tuesday'. * - The association does not have to be exclusive, and general target slot * values will often be associated with many controls. In situations where * there is ambiguity about what the user is referring to, the parent * controls must resolve the confusion. * - The 'builtin_*' IDs are associated with default interaction model data * (which can be extended as desired). Any other IDs will require a full * definition of the allowed synonyms in the interaction model. * * Control behavior: * - A control will not handle an input that mentions a target that is not * registered by this prop. * */ targets?: string[]; /** * Action slot-values associated to the control's capabilities. * * Default: * ``` * { * set: ['builtin_set', 'builtin_select'], * change: ['builtin_set'] * } * ``` * * Action slot-values associate utterances to a control. For example, if the * user says "change the time", it is parsed as a `GeneralControlIntent` * with slot values `action = change` and `target = time`. Only controls * that are registered with the `change` action should offer to handle this * intent. * * Usage: * - This allows users to refer to an action using more domain-appropriate * words. For example, a user might like to say 'show two items' rather * that 'set item count to two'. To achieve this, include the * slot-value-id 'show' in the list associated with the 'set' capability * and ensure the interaction-model includes an action slot value with * id=show and appropriate synonyms. * - The 'builtin_*' IDs are associated with default interaction model data * (which can be extended as desired). Any other IDs will require a full * definition of the allowed synonyms in the interaction model. */ actions?: ListControlActionProps; /*** * Additional properties to resolve utterance conflicts caused by the * configured slot type. * * Purpose: * - use these props in situations where the configured slotType has * values/synonyms that cause utterance conflicts. Most commonly, this * arises when the list control is managing a slotType with values such * as 'yes' and 'no' that conflict with Amazon.YesIntent & Amazon.NoIntent. */ slotValueConflictExtensions?: { /** * Slot type that is a copy of the main slot type, with problematic values * removed. * * Purpose: * - During interaction-model-generation, the `filteredSlotType` is used * in sample-utterances that would cause conflicts if the regular * slotType was used. * * Example: * - if the list is managing a SlotType `ExtendedBoolean` with values * `yes | no | maybe`, create and register a filtered SlotType * `ExtendedBooleanFiltered` that has only the `maybe` value. */ filteredSlotType: string; /** * Function that maps an intent to a valueId for props.slotValue. * * Default: IntentUtils.defaultIntentToValueMapper * * Purpose: * * Some simple utterances intended for this control will be * interpreted as intents that are unknown to this control. This * function allows mapping of them. * * Example: * * if the list is managing a SlotType `ExtendedBoolean` with values * `yes | no | maybe` and filteredSlotType has been configured * correctly then a user-utterance of 'U: yes' will be interpreted as * an `AMAZON.YesIntent`. To ensure that intent is correctly * processed, declare an intentToValueMapper that maps * `AMAZON.YesIntent -> 'yes'`. The built-in logic of the ListControl * will thus treat AMAZON.YesIntent as the value 'yes', assuming that the * control is not actively asking a yes/no question. */ intentToValueMapper: (intent: Intent) => string | undefined; }; } /** * Props to customize the prompt fragments that will be added by * `this.renderAct()`. */ export declare class ListControlPromptProps { valueSet?: StringOrList | ((act: ValueSetAct, input: ControlInput) => StringOrList); valueChanged?: StringOrList | ((act: ValueChangedAct, input: ControlInput) => StringOrList); invalidValue?: StringOrList | ((act: InvalidValueAct, input: ControlInput) => StringOrList); unusableInputValue?: StringOrList | ((act: UnusableInputValueAct, input: ControlInput) => StringOrList); requestValue?: StringOrList | ((act: RequestValueByListAct, input: ControlInput) => StringOrList); requestChangedValue?: StringOrList | ((act: RequestChangedValueByListAct, input: ControlInput) => StringOrList); confirmValue?: StringOrList | ((act: ConfirmValueAct, input: ControlInput) => StringOrList); valueConfirmed?: StringOrList | ((act: ValueConfirmedAct, input: ControlInput) => StringOrList); valueDisconfirmed?: StringOrList | ((act: ValueDisconfirmedAct, input: ControlInput) => StringOrList); } export declare type AplContent = { document: { [key: string]: any; }; dataSource: { [key: string]: any; }; }; export declare type AplContentFunc = (control: ListControl, input: ControlInput) => AplContent; export declare type AplDocumentPropNewStyle = AplContent | AplContentFunc; export declare type ListControlAplRenderComponentFunc = (control: ListControl, props: ListAPLComponentProps, input: ControlInput, resultBuilder: ControlResponseBuilder) => { [key: string]: any; }; /** * Props associated with the APL produced by ListControl. */ export declare class ListControlAPLProps { /** * Determines if APL should be produced. * * Default: true */ enabled?: boolean | ((input: ControlInput) => boolean); /** * Custom APL to request value from list of choices. */ requestValue?: AplDocumentPropNewStyle; requestChangedValue?: AplDocumentPropNewStyle; /** * Determines the APL Component rendering mode. * * Usage: * * 1) Use pre-defined built-ins under ListControlComponentAPLBuiltIns.* namespace which provides both default * implementations and customization of props(ListAPLComponentProps) to render an APL component. * * e.g renderComponent: ListControlComponentAPLBuiltIns.ImageListRenderer.default --- Default Implementation * renderComponent: ListControlComponentAPLBuiltIns.ImageListRenderer.of(props: ListAPLComponentProps) --- Override few properties * * 2) Provide a custom function which returns an APL component. * * Default: ListControlComponentAPLBuiltIns.TextListRenderer.default */ renderComponent?: ListControlAplRenderComponentFunc; } /** * Tracks the last act initiated from the control. */ interface LastInitiativeState { /** * Control act name. */ actName?: string; } /** * Props to customize ListControl APLComponent rendering. */ export interface ListAPLComponentProps { /** * Boolean to determine to highlight user selected choice from the * list of items. * * Default: false */ highlightSelected?: boolean; /** * Function that maps the MultiValueListControlState.value to rendered value that * will be presented to the user as a list. * * Default: returns the value unchanged * i.e ListControlRenderedItem.prompt = value */ valueRenderer?: (value: string, input: ControlInput) => ListControlRenderedItem; } /** * State tracked by a ListControl. */ export declare class ListControlState implements ControlState { /** * The value. * * If `erMatch = true` the value is a slot value ID for the slot type `this.slotType`. * If `erMatch = false` the value may be an arbitrary string. */ value: string; /** * Tracks whether the value is an Entity Resolution match. */ erMatch?: boolean; /** * Tracks the most recent elicitation action. * * Note: this isn't cleared immediate after user provides a value as the * value maybe be invalid and has to be re-elicited. Use * state.lastInitiative to test if the most recent turn was a direct elicitation. */ elicitationAction?: string; /** * Index of the page of items most recently spoken. */ spokenItemsPageIndex?: number; /** * Tracks whether the value has been explicitly confirmed by the user. */ isValueConfirmed: boolean; /** * The previous value. */ previousValue?: string; /** * Tracks the last initiative act from the control */ lastInitiative: LastInitiativeState; } /** * A Control that obtains a single value from the user by presenting a list of * available options using voice and/or APL. * * The type of value to obtain is defined by `this.slotType`. * * Capabilities: * - Request a value * - Change a value * - Validate the value * - Confirm the value * - Speak the first few options * - Show all the options on APL enabled devices * - Selection of a value using a spoken ordinal, e.g. "The first one". * - Selection of a value using touch screen. * * Intents that can be handled: * - `GeneralControlIntent`: E.g. `"yes, update my name"` * - `{ValueType}_ValueControlIntent`: E.g. "no change it to Elvis". * - `AMAZON_ORDINAL_ValueControlIntent`: E.g. "no change it to Elvis". * - `AMAZON.YesIntent`, `AMAZON.NoIntent` * * APL events that can be handled: * - touch events indicating selection of an item on screen. * * Limitations: * - This control is not compatible with the `AMAZON.SearchQuery` slot type. */ export declare class ListControl extends Control implements InteractionModelContributor { state: ListControlState; private rawProps; private props; private handleFunc?; private initiativeFunc?; private log; constructor(props: ListControlProps); /** * Merges the user-provided props with the default props. * * Any property defined by the user-provided data overrides the defaults. */ static mergeWithDefaultProps(props: ListControlProps): DeepRequired; static defaultValueRenderer(): (value: string, input: ControlInput) => ListControlRenderedItem; standardInputHandlers: ControlInputHandler[]; canHandle(input: ControlInput): Promise; handle(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private isSetWithValue; private handleSetWithValue; private isSetWithoutValue; private handleSetWithoutValue; private isChangeWithValue; private handleChangeWithValue; private isChangeWithoutValue; private handleChangeWithoutValue; private isBareValue; private handleBareValue; private isMappedBareValueDuringElicitation; private handleMappedBareValue; private isConfirmationAffirmed; private handleConfirmationAffirmed; private isConfirmationDisaffirmed; private handleConfirmationDisaffirmed; private isOrdinalScreenEvent; private handleOrdinalScreenEvent; private isOrdinalSelection; private handleOrdinalSelection; /** * Directly set the value. * * @param value - Value * @param erMatch - Whether the value is an ID defined for `this.slotType` * in the interaction model */ setValue(value: string, erMatch?: boolean): void; /** * Clear the state of this control. */ clear(): void; canTakeInitiative(input: ControlInput): Promise; takeInitiative(input: ControlInput, resultBuilder: ControlResultBuilder): Promise; private wantsToConfirmValue; private confirmValue; private wantsToFixInvalidValue; private fixInvalidValue; private wantsToElicitValue; private elicitValue; validateAndAddActs(input: ControlInput, resultBuilder: ControlResultBuilder, elicitationAction: string): Promise; private askElicitationQuestion; addInitiativeAct(initiativeAct: InitiativeAct, resultBuilder: ControlResultBuilder): void; stringifyStateForDiagram(): string; getChoicesList(input: ControlInput): string[]; private getChoicesFromActivePage; private getPageIndex; renderAct(act: SystemAct, input: ControlInput, builder: ControlResponseBuilder): Promise; renderAPLComponent(input: ControlInput, resultBuilder: ControlResponseBuilder): Promise<{ [key: string]: any; }>; private evaluateAPLPropNewStyle; private addStandardAPL; private getSlotTypes; getListItemIDs(input: ControlInput): string[]; updateInteractionModel(generator: ControlInteractionModelGenerator, imData: ModelData): void; } export {}; //# sourceMappingURL=ListControl.d.ts.map