UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

267 lines (264 loc) • 12.4 kB
/** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { BoolExpression } from 'adaptive-expressions'; import { Activity, RecognizerResult, TurnContext } from 'botbuilder'; import { Converter, ConverterFactory, Dialog, DialogConfiguration, DialogContainer, DialogContext, DialogEvent, DialogInstance, DialogReason, DialogSet, DialogTurnResult, Recognizer } from 'botbuilder-dialogs'; import { ActionContext } from './actionContext'; import { OnCondition } from './conditions'; import { LanguageGenerator } from './languageGenerator'; import { BoolProperty } from './properties'; import { TriggerSelector } from './triggerSelector'; export interface AdaptiveDialogConfiguration extends DialogConfiguration { recognizer?: string | Recognizer; generator?: string | LanguageGenerator; triggers?: OnCondition[]; autoEndDialog?: BoolProperty; selector?: TriggerSelector; defaultResultProperty?: string; schema?: unknown; dialogs?: string[] | Dialog[] | DialogSet; } /** * The Adaptive Dialog models conversation using events and events to adapt dynamically to changing conversation flow. */ export declare class AdaptiveDialog<O extends object = {}> extends DialogContainer<O> implements AdaptiveDialogConfiguration { static $kind: string; static conditionTracker: string; private readonly adaptiveKey; private readonly defaultOperationKey; private readonly expectedOnlyKey; private readonly entitiesKey; private readonly instanceKey; private readonly operationsKey; private readonly requiresValueKey; private readonly propertyNameKey; private readonly propertyEnding; private readonly utteranceKey; private readonly generatorTurnKey; private readonly changeTurnKey; private _recognizerSet; private installedDependencies; private needsTracker; private dialogSchema; private _internalVersion; /** * Creates a new `AdaptiveDialog` instance. * * @param dialogId (Optional) unique ID of the component within its parents dialog set. */ constructor(dialogId?: string); /** * Optional. Recognizer used to analyze any message utterances. */ recognizer?: Recognizer; /** * Optional. Language Generator override. */ generator?: LanguageGenerator; /** * Trigger handlers to respond to conditions which modify the executing plan. */ triggers: OnCondition[]; /** * Whether to end the dialog when there are no actions to execute. * * @remarks * If true, when there are no actions to execute, the current dialog will end. * If false, when there are no actions to execute, the current dialog will simply end the turn and still be active. * Defaults to a value of true. */ autoEndDialog: BoolExpression; /** * Optional. The selector for picking the possible events to execute. */ selector: TriggerSelector; /** * The property to return as the result when the dialog ends when there are no more Actions and `AutoEndDialog = true`. * * @remarks * Defaults to a value of `dialog.result`. */ defaultResultProperty: string; /* * Gets the JSON Schema for the dialog. * * @returns The dialog schema. * Sets the JSON Schema for the dialog. */ schema: object; /** * @param property The key of the conditional selector configuration. * @returns The converter for the selector configuration. */ getConverter(property: keyof AdaptiveDialogConfiguration): Converter | ConverterFactory; /** * @protected * Ensures all dependencies for the class are installed. */ protected ensureDependenciesInstalled(): void; /** * @protected * Gets the internal version string. * @returns Internal version string. */ protected getInternalVersion(): string; protected onComputeId(): string; /** * Called when the dialog is started and pushed onto the dialog stack. * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param options Optional, initial information to pass to the dialog. * @returns A Promise representing the asynchronous operation. */ beginDialog(dc: DialogContext, options?: O): Promise<DialogTurnResult>; /** * Called when the dialog is _continued_, where it is the active dialog and the * user replies with a new activity. * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @returns A Promise representing the asynchronous operation. */ continueDialog(dc: DialogContext): Promise<DialogTurnResult>; /** * Called when the dialog is ending. * * @param turnContext The context object for this turn. * @param instance State information associated with the instance of this dialog on the dialog stack. * @param reason Reason why the dialog ended. * @returns A Promise representing the asynchronous operation. */ endDialog(turnContext: TurnContext, instance: DialogInstance, reason: DialogReason): Promise<void>; /** * @protected * Called before an event is bubbled to its parent. * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param event The [DialogEvent](xref:botbuilder-dialogs.DialogEvent) being raised. * @returns Whether the event is handled by the current dialog and further processing should stop. */ protected onPreBubbleEvent(dc: DialogContext, event: DialogEvent): Promise<boolean>; /** * @protected * Called after an event was bubbled to all parents and wasn't handled. * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param event The [DialogEvent](xref:botbuilder-dialogs.DialogEvent) being raised. * @returns Whether the event is handled by the current dialog and further processing should stop. */ protected onPostBubbleEvent(dc: DialogContext, event: DialogEvent): Promise<boolean>; /** * Called when a child dialog completed its turn, returning control to this dialog. * * @param dc The dialog context for the current turn of the conversation. * @param _reason Reason why the dialog resumed. * @param _result Optional, value returned from the dialog that was called. * The type of the value returned is dependent on the child dialog. * @returns A Promise representing the asynchronous operation. */ resumeDialog(dc: DialogContext, _reason?: DialogReason, _result?: any): Promise<DialogTurnResult>; /** * Reprompts the user. * * @param context The context object for the turn. * @param instance Current state information for this dialog. * @returns A Promise representing the asynchronous operation. */ repromptDialog(context: DialogContext | TurnContext, instance: DialogInstance): Promise<void>; /** * Creates a child [DialogContext](xref:botbuilder-dialogs.DialogContext) for the given context. * * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @returns The child [DialogContext](xref:botbuilder-dialogs.DialogContext) or null if no [AdaptiveDialogState.actions](xref:botbuilder-dialogs-adaptive.AdaptiveDialogState.actions) are found for the given context. */ createChildContext(dc: DialogContext): DialogContext; /** * Gets [Dialog](xref:botbuilder-dialogs.Dialog) enumerated dependencies. * * @returns [Dialog](xref:botbuilder-dialogs.Dialog)'s enumerated dependencies. */ getDependencies(): Dialog[]; /** * @protected * Event processing implementation. * @param actionContext The [ActionContext](xref:botbuilder-dialogs-adaptive.ActionContext) for the current turn of conversation. * @param dialogEvent The [DialogEvent](xref:botbuilder-dialogs.DialogEvent) being raised. * @param preBubble A flag indicator for preBubble processing. * @returns A Promise representation of a boolean indicator or the result. */ protected processEvent(actionContext: ActionContext, dialogEvent: DialogEvent, preBubble: boolean): Promise<boolean>; /** * @protected * Recognizes intent for current activity given the class recognizer set, if set is null no intent will be recognized. * @param actionContext The [ActionContext](xref:botbuilder-dialogs-adaptive.ActionContext) for the current turn of conversation. * @param activity [Activity](xref:botbuilder-schema.Activity) to recognize. * @returns A Promise representing a [RecognizerResult](xref:botbuilder.RecognizerResult). */ protected onRecognize(actionContext: ActionContext, activity: Activity): Promise<RecognizerResult>; private queueFirstMatch; /** * @protected * Waits for pending actions to complete and moves on to [OnEndOfActions](xref:botbuilder-dialogs-adaptive.OnEndOfActions). * @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @returns A Promise representation of [DialogTurnResult](xref:botbuilder-dialogs.DialogTurnResult). */ protected continueActions(dc: DialogContext): Promise<DialogTurnResult>; /** * @protected * Provides the ability to set scoped services for the current [DialogContext](xref:botbuilder-dialogs.DialogContext). * @param dialogContext The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. */ protected onSetScopedServices(dialogContext: DialogContext): void; /** * @protected * Removes the most current action from the given [ActionContext](xref:botbuilder-dialogs-adaptive.ActionContext) if there are any. * @param actionContext The [ActionContext](xref:botbuilder-dialogs-adaptive.ActionContext) for the current turn of conversation. * @returns A Promise representing a boolean indicator for the result. */ protected endCurrentAction(actionContext: ActionContext): Promise<boolean>; /** * @protected * Awaits for completed actions to finish processing entity assignments and finishes the turn. * @param actionContext The [ActionContext](xref:botbuilder-dialogs-adaptive.ActionContext) for the current turn of conversation. * @returns A Promise representation of [DialogTurnResult](xref:botbuilder-dialogs.DialogTurnResult). */ protected onEndOfActions(actionContext: ActionContext): Promise<DialogTurnResult>; private getUniqueInstanceId; private toActionContext; /** * This function goes through the entity assignments and emits events if present. * * @param actionContext The ActionContext. * @returns true if the event was handled. */ private processQueues; /** * Process entities to identify ambiguity and possible assignment to properties. Broadly the steps are: * Normalize entities to include meta-data * Check to see if an entity is in response to a previous ambiguity event * Assign entities to possible properties * Merge new queues into existing queues of ambiguity events * * @param actionContext The ActionContext. * @param activity The Activity. */ private processEntities; private splitUtterance; private normalizeEntities; private expandEntityObject; private expandEntities; private stripProperty; private expandEntity; private matchesAssignment; private candidates; private addAssignment; private entityPreferences; private defaultOperation; private removeOverlappingPerProperty; private assignEntities; private replaces; private mergeAssignments; } //# sourceMappingURL=adaptiveDialog.d.ts.map