/** * @module botbuilder-ai */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { Activity } from 'botbuilder-core'; import { QnAMakerClient } from './qnaMaker'; import { ArrayExpression, BoolExpression, EnumExpression, Expression, IntExpression, NumberExpression, StringExpression } from 'adaptive-expressions'; import { Converter, ConverterFactory, WaterfallDialog, DialogConfiguration, DialogContext, DialogEvent, DialogStateManager, DialogTurnResult, TemplateInterface, WaterfallStepContext } from 'botbuilder-dialogs'; import { JoinOperator, QnAMakerMetadata, QnAMakerOptions, RankerTypes } from './qnamaker-interfaces'; import { Filters } from './qnamaker-interfaces/filters'; import { ServiceType } from './qnamaker-interfaces/serviceType'; /** * QnAMakerDialog response options. */ export interface QnAMakerDialogResponseOptions { /** * Title for active learning card. */ activeLearningCardTitle: string; /** * Text shown for 'no match' option on active learning card. */ cardNoMatchText: string; /** * Activity to be sent in the event of no answer found in KB. */ noAnswer: Partial; /** * Activity to be sent in the end that the 'no match' option is selected on active learning card. */ cardNoMatchResponse: Partial; /** * Indicates whether the dialog response should display only precise answers. */ displayPreciseAnswerOnly: boolean; } /** * Options for QnAMakerDialog. */ export interface QnAMakerDialogOptions { /** * Options for QnAMaker knowledgebase. */ qnaMakerOptions: QnAMakerOptions; /** * QnAMakerDialog response options. */ qnaDialogResponseOptions: QnAMakerDialogResponseOptions; } export interface QnAMakerDialogConfiguration extends DialogConfiguration { knowledgeBaseId?: string | Expression | StringExpression; hostname?: string | Expression | StringExpression; endpointKey?: string | Expression | StringExpression; managedIdentityClientId?: string | Expression | StringExpression; threshold?: number | string | Expression | NumberExpression; top?: number | string | Expression | IntExpression; noAnswer?: string | Partial | TemplateInterface, DialogStateManager>; activeLearningCardTitle?: string | Expression | StringExpression; cardNoMatchText?: string | Expression | StringExpression; cardNoMatchResponse?: string | Partial | TemplateInterface, DialogStateManager>; strictFilters?: QnAMakerMetadata[] | string | Expression | ArrayExpression; logPersonalInformation?: boolean | string | Expression | BoolExpression; isTest?: boolean; rankerType?: RankerTypes | string | Expression | EnumExpression; displayPreciseAnswerOnly?: boolean; strictFiltersJoinOperator?: JoinOperator; includeUnstructuredSources?: boolean; useTeamsAdaptiveCard?: boolean; } /** * Returns an activity with active learning suggestions. * * Important: The activity returned should relay the noMatchesText as an option to the end user. * * @param suggestionsList List of suggestions. * @param noMatchesText If this text is received by the bot during a prompt. */ export declare type QnASuggestionsActivityFactory = (suggestionsList: string[], noMatchesText: string) => Partial; declare type QnAMakerDialogWithoutOtherAuthorization = Omit; /** * A dialog that supports multi-step and adaptive-learning QnA Maker services. * * @summary * An instance of this class targets a specific QnA Maker knowledge base. * It supports knowledge bases that include follow-up prompt and active learning features. * The dialog will also present user with appropriate multi-turn prompt or active learning options. */ export declare class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogConfiguration { static $kind: string; /** * The path for storing and retrieving QnA Maker context data. * * @summary * This represents context about the current or previous call to QnA Maker. * It is stored within the current step's [WaterfallStepContext](xref:botbuilder-dialogs.WaterfallStepContext). * It supports QnA Maker's follow-up prompt and active learning features. */ protected qnAContextData: string; /** * The path for storing and retrieving the previous question ID. * * @summary * This represents the QnA question ID from the previous turn. * It is stored within the current step's [WaterfallStepContext](xref:botbuilder-dialogs.WaterfallStepContext). * It supports QnA Maker's follow-up prompt and active learning features. */ protected previousQnAId: string; /** * The path for storing and retrieving the options for this instance of the dialog. * * @summary * This includes the options with which the dialog was started and options expected by the QnA Maker service. * It is stored within the current step's [WaterfallStepContext](xref:botbuilder-dialogs.WaterfallStepContext). * It supports QnA Maker and the dialog system. */ protected options: string; /** * The default threshold for answers returned, based on score. */ protected defaultThreshold: number; /** * The default maximum number of answers to be returned for the question. */ protected defaultTopN: number; private currentQuery; private qnAData; private turnQnaresult; private defaultNoAnswer; private defaultCardTitle; private defaultCardNoMatchText; private defaultCardNoMatchResponse; /** * Gets or sets the QnA Maker knowledge base ID to query. */ knowledgeBaseId: StringExpression; /** * Gets or sets the QnA Maker host URL for the knowledge base. */ hostname: StringExpression; /** * Gets or sets the QnA Maker endpoint key to use to query the knowledge base. */ endpointKey: StringExpression; /** * Gets or sets the Managed Identity ClientId to use to query the knowledge base. */ managedIdentityClientId: StringExpression; /** * Gets or sets the threshold for answers returned, based on score. */ threshold: NumberExpression; /** * Gets or sets the maximum number of answers to return from the knowledge base. */ top: IntExpression; /** * Gets or sets the template to send to the user when QnA Maker does not find an answer. */ noAnswer: TemplateInterface, DialogStateManager>; /** * Gets or sets the card title to use when showing active learning options to the user. * * _Note: If suggestionsActivityFactory is passed in, this member is unused._ */ activeLearningCardTitle: StringExpression; /** * Gets or sets the button text to use with active learning options, allowing a user to * indicate non of the options are applicable. * * _Note: If suggestionsActivityFactory is passed in, this member is required._ */ cardNoMatchText: StringExpression; /** * Gets or sets the template to send to the user if they select the no match option on an * active learning card. */ cardNoMatchResponse: TemplateInterface, DialogStateManager>; /** * Gets or sets the QnA Maker metadata with which to filter or boost queries to the knowledge base, * or null to apply none. */ strictFilters: QnAMakerMetadata[]; /** * Gets or sets the flag to determine if personal information should be logged in telemetry. * * @summary * Defaults to a value of `=settings.telemetry.logPersonalInformation`, which retrieves * `logPersonalInformation` flag from settings. */ logPersonalInformation: BoolExpression; /** * Gets or sets a value indicating whether gets or sets environment of knowledgebase to be called. */ isTest: boolean; /** * Gets or sets the QnA Maker ranker type to use. */ rankerType: EnumExpression; /** * Gets or sets a value indicating whether to include precise answer in response. */ enablePreciseAnswer: boolean; /** * Gets or sets a value indicating whether the dialog response should display only precise answers. */ displayPreciseAnswerOnly: boolean; /** * Question answering service type - qnaMaker or language */ qnaServiceType: ServiceType; /** * Gets or sets a value - AND or OR - logical operation on list of metadata */ strictFiltersJoinOperator: JoinOperator; /** * Gets or sets the metadata and sources used to filter results. */ filters: Filters; /** * Gets or sets a value indicating whether to include unstructured sources in search for answers. */ includeUnstructuredSources: boolean; /** * Gets or sets a value indicating whether to use a Teams-formatted Adaptive Card in responses instead of a generic Hero Card. */ useTeamsAdaptiveCard: boolean; private suggestionsActivityFactory?; private normalizedHost; /** * Initializes a new instance of the [QnAMakerDialog](xref:QnAMakerDialog) class. * * @param {string} knowledgeBaseId The ID of the QnA Maker knowledge base to query. * @param {string} endpointKey **Deprecated - use withEndpointKey() instead**. The QnA Maker endpoint key to use to query the knowledge base. * @param {string} hostname The QnA Maker host URL for the knowledge base, starting with "https://" and ending with "/qnamaker". * @param {string} noAnswer (Optional) The activity to send the user when QnA Maker does not find an answer. * @param {number} threshold (Optional) The threshold above which to treat answers found from the knowledgebase as a match. * @param {string} activeLearningCardTitle (Optional) The card title to use when showing active learning options to the user, if active learning is enabled. * @param {string} cardNoMatchText (Optional) The button text to use with active learning options, allowing a user to indicate none of the options are applicable. * @param {number} top (Optional) Maximum number of answers to return from the knowledge base. * @param {Activity} cardNoMatchResponse (Optional) The activity to send the user if they select the no match option on an active learning card. * @param {QnAMakerMetadata[]} strictFilters (Optional) QnA Maker metadata with which to filter or boost queries to the knowledge base; or null to apply none. * @param {string} dialogId (Optional) Id of the created dialog. Default is 'QnAMakerDialog'. * @param {string} strictFiltersJoinOperator join operator for strict filters * @param {string} useTeamsAdaptiveCard boolean setting for using Teams Adaptive Cards instead of Hero Cards */ constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, activeLearningCardTitle?: string, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, rankerType?: RankerTypes, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator, enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType, useTeamsAdaptiveCard?: boolean); /** * Initializes a new instance of the [QnAMakerDialog](xref:QnAMakerDialog) class. * * @param {string} knowledgeBaseId The ID of the QnA Maker knowledge base to query. * @param {string} endpointKey **Deprecated - use withEndpointKey() instead**. The QnA Maker endpoint key to use to query the knowledge base. * @param {string} hostname The QnA Maker host URL for the knowledge base, starting with "https://" and ending with "/qnamaker". * @param {string} noAnswer (Optional) The activity to send the user when QnA Maker does not find an answer. * @param {number} threshold (Optional) The threshold above which to treat answers found from the knowledgebase as a match. * @param {Function} suggestionsActivityFactory [QnASuggestionsActivityFactory](xref:botbuilder-ai.QnASuggestionsActivityFactory) used for custom Activity formatting. * @param {string} cardNoMatchText The text to use with the active learning options, allowing a user to indicate none of the options are applicable. * @param {number} top (Optional) Maximum number of answers to return from the knowledge base. * @param {Activity} cardNoMatchResponse (Optional) The activity to send the user if they select the no match option on an active learning card. * @param {QnAMakerMetadata[]} strictFilters (Optional) QnA Maker metadata with which to filter or boost queries to the knowledge base; or null to apply none. * @param {string} dialogId (Optional) Id of the created dialog. Default is 'QnAMakerDialog'. * @param {string} strictFiltersJoinOperator join operator for strict filters * @param {string} useTeamsAdaptiveCard boolean setting for using Teams Adaptive Cards instead of Hero Cards */ constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, suggestionsActivityFactory?: QnASuggestionsActivityFactory, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, rankerType?: RankerTypes, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator, enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType, useTeamsAdaptiveCard?: boolean); /** * Uses the provided QnA Maker EndpointKey to authenticate against the resource to query the knowledge base. * * @param endpointKey The QnA Maker endpoint key to use to query the knowledge base. * @returns The QnAMakerDialog instance. */ withEndpointKey(endpointKey: string): QnAMakerDialogWithoutOtherAuthorization; /** * Uses the provided QnA Maker ManagedIdentityClientId to authenticate against the resource to query the knowledge base. * * @param managedIdentityClientId The QnA Maker managed identity client id to use to query the knowledge base. * @returns The QnAMakerDialog instance. */ withManagedIdentityClientId(managedIdentityClientId: string): QnAMakerDialogWithoutOtherAuthorization; /** * @param property Properties that extend QnAMakerDialogConfiguration. * @returns The expression converter. */ getConverter(property: keyof QnAMakerDialogConfiguration): Converter | ConverterFactory; /** * Called when the dialog is started and pushed onto the dialog stack. * * @summary * If the task is successful, the result indicates whether the dialog is still * active after the turn has been processed by the dialog. * * You can use the [options](#options) parameter to include the QnA Maker context data, * which represents context from the previous query. To do so, the value should include a * `context` property of type [QnAResponseContext](#QnAResponseContext). * * @param {DialogContext} dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param {object} options (Optional) Initial information to pass to the dialog. * @returns {Promise} A promise resolving to the turn result */ beginDialog(dc: DialogContext, options?: object): Promise; /** * Called when the dialog is _continued_, where it is the active dialog and the * user replies with a new [Activity](xref:botframework-schema.Activity). * * @param {DialogContext} dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @returns {DialogContext} A Promise representing the asynchronous operation. */ continueDialog(dc: DialogContext): Promise; /** * Called before an event is bubbled to its parent. * * @param {DialogContext} dc The dialog context for the current turn of conversation. * @param {DialogEvent} e The event being raised. * @returns {Promise} Whether the event is handled by the current dialog and further processing should stop. */ protected onPreBubbleEvent(dc: DialogContext, e: DialogEvent): Promise; /** * Gets an [QnAMakerClient](xref:botbuilder-ai.QnAMakerClient) to use to access the QnA Maker knowledge base. * * @param {DialogContext} dc The dialog context for the current turn of conversation. * @returns {Promise} A promise of QnA Maker instance. */ protected getQnAMakerClient(dc: DialogContext): Promise; /** * Gets the options for the QnA Maker client that the dialog will use to query the knowledge base. * * @param {DialogContext} dc The dialog context for the current turn of conversation. * @returns {Promise} A promise of QnA Maker options to use. */ protected getQnAMakerOptions(dc: DialogContext): Promise; /** * Gets the options the dialog will use to display query results to the user. * * @param {DialogContext} dc The dialog context for the current turn of conversation. * @returns {Promise} A promise of QnA Maker response options to use. */ protected getQnAResponseOptions(dc: DialogContext): Promise; /** * Displays an appropriate response based on the incoming result to the user. If an answer has been identified it * is sent to the user. Alternatively, if no answer has been identified or the user has indicated 'no match' on an * active learning card, then an appropriate message is sent to the user. * * @param {WaterfallStepContext} step the waterfall step context * @returns {Promise} a promise resolving to the dialog turn result */ protected displayQnAResult(step: WaterfallStepContext): Promise; private resetOptions; private callGenerateAnswer; private callTrain; private checkForMultiTurnPrompt; private getHost; } export {}; //# sourceMappingURL=qnaMakerDialog.d.ts.map