UNPKG

node-nlp

Version:

Library for NLU (Natural Language Understanding) done in Node.js

1,187 lines (953 loc) 224 kB
//============================================================================= // // TYPES // //============================================================================= /** * Text based prompts that can be sent to a user. * * _{string}_ - A simple message to send the user. * * _{string[]}_ - Array of possible messages to send the user. One will be chosen at random. */ export type TextType = string|string[]; /** * Message based prompts that can be sent to a user. * * _{IMessage}_ - Message to send the user expressed using JSON. The message can contain attachments and suggested actions. Not all channels natively support all message properties but most channels will down render unsupported fields. * * _{IIsMessage}_ - An instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. This class helps to localize your messages and provides helpers to aid with formatting the text portions of your message. */ export type MessageType = IMessage|IIsMessage; /** * Flexible range of possible prompts that can be sent to a user. * * _{string}_ - A simple message to send the user. * * _{string[]}_ - Array of possible messages to send the user. One will be chosen at random. * * _{IMessage}_ - Message to send the user expressed using JSON. The message can contain attachments and suggested actions. Not all channels natively support all message properties but most channels will down render unsupported fields. * * _{IIsMessage}_ - An instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. This class helps to localize your messages and provides helpers to aid with formatting the text portions of your message. */ export type TextOrMessageType = string|string[]|IMessage|IIsMessage; /** * Some methods can take either an `IAttachment` in JSON form or one the various card builder classes * that implement `IIsAttachment`. */ export type AttachmentType = IAttachment|IIsAttachment; /** * Supported rules for matching a users utterance. * * _{RegExp}_ - A regular expression will be used to match the users utterance. * * _{string}_ - A named intent returned from a recognizer will be used to match the users utterance. * * _{(RegExp|string)[]}_ - An array of either regular expressions or named intents can be passed to match the users utterance in a number of possible ways. The rule generating the highest score (best match) will be used for scoring purposes. */ export type MatchType = RegExp|string|(RegExp|string)[]; /** * List of text values. The values can be expressed as a pipe delimited string like "value1|value2|value3" * or simple array of values. */ export type ValueListType = string|string[]; //============================================================================= // // INTERFACES // //============================================================================= /** * An event received from or being sent to a source. * @example * <pre><code> * session.send({ type: 'typing' }); * </code></pre> */ export interface IEvent { /** Defines type of event. Should be 'message' for an IMessage. */ type: string; /** SDK thats processing the event. Will always be 'botbuilder'. */ agent: string; /** The original source of the event (i.e. 'facebook', 'skype', 'slack', etc.) */ source: string; /** The original event in the sources native schema. For outgoing messages can be used to pass source specific event data like custom attachments. */ sourceEvent: any; /** Address routing information for the event. Save this field to external storage somewhere to later compose a proactive message to the user. */ address: IAddress; /** * For incoming messages this is the user that sent the message. By default this is a copy of [address.user](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iaddress.html#user) but you can configure your bot with a * [lookupUser](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iuniversalbotsettings.html#lookupuser) function that lets map the incoming user to an internal user id. */ user: IIdentity; /** The ID of the event this update is related to. */ replyToId?: string; } /** * The Properties of a conversation have changed. * @example * <pre><code> * bot.on('conversationUpdate', function (update) { * // ... process update ... * }); * </code></pre> */ export interface IConversationUpdate extends IEvent { /** Array of members added to the conversation. */ membersAdded?: IIdentity[]; /** Array of members removed from the conversation. */ membersRemoved?: IIdentity[]; /** Array of reactions added to an activity. */ reactionsAdded?: IMessageReaction[]; /** Array of reactions removed from an activity. */ reactionsRemoved?: IMessageReaction[]; /** The conversations new topic name. */ topicName?: string; /** If true then history was disclosed. */ historyDisclosed?: boolean; } /** * The Properties of a message have changed. * @example * <pre><code> * bot.on('messageReaction', function (update) { * // ... process update ... * }); * </code></pre> */ export interface IMessageUpdate extends IEvent { /** Array of reactions added to an activity. */ reactionsAdded?: IMessageReaction[]; /** Array of reactions removed from an activity. */ reactionsRemoved?: IMessageReaction[]; } /** Message reaction object. */ export interface IMessageReaction { /** Message reaction type. */ type: string; } /** * A user has updated their contact list. /** * A user has updated their contact list. * @example * <pre><code> * bot.on('contactRelationUpdate', function (update) { * // ... process update ... * }); * </code></pre> */ export interface IContactRelationUpdate extends IEvent { /** The action taken. Valid values are "add" or "remove". */ action: string; } /** * A chat message sent between a User and a Bot. Messages from the bot to the user come in two flavors: * * * __reactive messages__ are messages sent from the Bot to the User as a reply to an incoming message from the user. * * __proactive messages__ are messages sent from the Bot to the User in response to some external event like an alarm triggering. * * In the reactive case the you should copy the [address](#address) field from the incoming message to the outgoing message (if you use the [Message]( /en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class and initialize it with the * [session](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html) this will happen automatically) and then set the [text](#text) or [attachments](#attachments). For proactive messages you’ll need save the [address](#address) from the incoming message to * an external storage somewhere. You can then later pass this in to [UniversalBot.beginDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot.html#begindialog) or copy it to an outgoing message passed to * [UniversalBot.send()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot.html#send). * * Composing a message to the user using the incoming address object will by default send a reply to the user in the context of the current conversation. Some channels allow for the starting of new conversations with the user. To start a new proactive conversation with the user simply delete * the [conversation](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iaddress.html#conversation) field from the address object before composing the outgoing message. * @example * <pre><code> * session.send({ * type: 'message', * text: "Hello World!" * }); * </code></pre> */ export interface IMessage extends IEvent { /** UTC Time when message was sent (set by service.) */ timestamp?: string; /** Local time when message was sent (set by client or bot, Ex: 2016-09-23T13:07:49.4714686-07:00.) */ localTimestamp?: string; /** Text to be displayed by as fall-back and as short description of the message content in e.g. list of recent conversations. */ summary?: string; /** Spoken message as [Speech Synthesis Markup Language](https://msdn.microsoft.com/en-us/library/hh378377(v=office.14).aspx). */ speak?: string; /** Message text. */ text?: string; /** Identified language of the message text if known. */ textLocale?: string; /** For incoming messages contains attachments like images sent from the user. For outgoing messages contains objects like cards or images to send to the user. */ attachments?: IAttachment[]; /** Structured objects passed to the bot or user. */ entities?: any[]; /** Format of text fields. The default value is 'markdown'. */ textFormat?: string; /** Hint for how clients should layout multiple attachments. The default value is 'list'. */ attachmentLayout?: string; /** Hint for clients letting them know if the bot is expecting further input or not. The built-in prompts will automatically populate this value for outgoing messages. */ inputHint?: string; /** Open-ended value. */ value?: any; /** Name of the operation to invoke or the name of the event. */ name?: string; /** Reference to another conversation or message. */ relatesTo?: IAddress; /** Code indicating why the conversation has ended. */ code?: string; } /** * Implemented by classes that can be converted into an IMessage, like the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message) builder class. * @example * <pre><code> * var msg = new builder.Message(session) * .text("Hello World!"); * session.send(msg); * </code></pre> */ export interface IIsMessage { /** Returns the JSON object for the message. */ toMessage(): IMessage; } /** * Optional message properties that can be sent to things like prompts or [session.say()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session#say). * @example * <pre><code> * session.say("Please wait...", "<speak>Please wait</speak>", { * inputHint: builder.InputHint.ignoringInput * }); * </code></pre> */ export interface IMessageOptions { /** For incoming messages contains attachments like images sent from the user. For outgoing messages contains objects like cards or images to send to the user. */ attachments?: IAttachment[]; /** Structured objects passed to the bot or user. */ entities?: any[]; /** Format of text fields. The default value is 'markdown'. */ textFormat?: string; /** Hint for how clients should layout multiple attachments. The default value is 'list'. */ attachmentLayout?: string; /** Hint for clients letting them know if the bot is expecting further input or not. The built-in prompts will automatically populate this value for outgoing messages. */ inputHint?: string; } /** Represents a user, bot, or conversation. */ export interface IIdentity { /** Channel specific ID for this identity. */ id: string; /** Friendly name for this identity. */ name?: string; /** If true the identity is a group. Typically only found on conversation identities. */ isGroup?: boolean; /** Indicates the type of the conversation in channels that distinguish. */ conversationType?: string; } /** List of members within a conversation. */ export interface IConversationMembers { /** Conversation ID. */ id: string; /** List of members in this conversation. */ members: IIdentity[]; } /** Result object returned from `ChatConnector.getConversations()`. */ export interface IConversationsResult { /** Paging token. */ continuationToken: string; /** List of conversations. */ conversations: IConversationMembers[]; } /** * An interface representing TokenResponse. * A response that includes a user token * */ export interface ITokenResponse { /** * The connection name */ connectionName: string; /** * The user token */ token: string; /** * Expiration for the token, in ISO 8601 format * (e.g. "2007-04-05T14:30Z") */ expiration: string; } /** Exported bot state data. */ export interface IBotStateData { /** ID of the conversation the data is for (if relevant.) */ conversationId?: string; /** ID of the user the data is for (if relevant.) */ userId?: string; /** Exported data. */ data: string; /** Timestamp of when the data was last modified. */ lastModified: string; } /** Result object returned from `ChatConnector.exportBotStateData()`. */ export interface IBotStateDataResult { /** Paging token. */ continuationToken: string; /** Exported bot state records. */ botStateData: IBotStateData[]; } /** * Address routing information for an [event](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ievent.html#address). * Addresses are bidirectional meaning they can be used to address both incoming and outgoing events. * They're also connector specific meaning that [connectors](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iconnector.html) * are free to add their own fields to the address. * * To send a __proactive message__ to a user bots should save the address from a received [message](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.imessage). * Depending on the channel addresses can change, so bots should periodically update the address stored for a given * user. */ export interface IAddress { /** Unique identifier for channel. */ channelId: string; /** User that sent or should receive the message. */ user: IIdentity; /** Bot that either received or is sending the message. */ bot: IIdentity; /** * Represents the current conversation and tracks where replies should be routed to. * Can be deleted to start a new conversation with a [user](#user) on channels that support new conversations. */ conversation?: IIdentity; } /** [ChatConnector](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.chatconnector) specific address. */ export interface IChatConnectorAddress extends IAddress { /** Incoming Message ID. */ id?: string; /** Specifies the URL to post messages back. */ serviceUrl?: string; } /** Additional properties that can be passed in with the address to [UniversalBot.beginDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot#begindialog). */ export interface IStartConversationAddress extends IChatConnectorAddress { /** (Optional) when creating a new conversation, use this activity as the initial message to the conversation. */ activity?: any; /** (Optional) channel specific payload for creating the conversation. */ channelData?: any; /** (Optional) if true the conversation should be a group conversation. */ isGroup?: boolean; /** (Optional) members to add to the conversation. If missing, the conversation will be started with the [user](#user). */ members?: IIdentity[]; /** (Optional) topic of the conversation (if supported by the channel) */ topicName?: string; } /** * Many messaging channels provide the ability to attach richer objects. Bot Builder lets you express these attachments in a cross channel way and [connectors](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iconnector.html) will do their best to render the * attachments using the channels native constructs. If you desire more control over the channels rendering of a message you can use [IEvent.sourceEvent](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ievent.html#sourceevent) to provide attachments using * the channels native schema. The types of attachments that can be sent varies by channel but these are the basic types: * * * __Media and Files:__ Basic files can be sent by setting [contentType](#contenttype) to the MIME type of the file and then passing a link to the file in [contentUrl](#contenturl). * * __Cards:__ A rich set of visual cards can by setting [contentType](#contenttype) to the cards type and then passing the JSON for the card in [content](#content). If you use one of the rich card builder classes like * [HeroCard](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.herocard.html) the attachment will automatically filled in for you. */ export interface IAttachment { /** MIME type string which describes type of attachment. */ contentType: string; /** (Optional) object structure of attachment. */ content?: any; /** (Optional) reference to location of attachment content. */ contentUrl?: string; /** (Optional) name of the attachment. */ name?: string; /** (Optional) link to the attachments thumbnail. */ thumbnailUrl?: string; } /** Implemented by classes that can be converted into an attachment. */ export interface IIsAttachment { /** Returns the JSON object for the attachment. */ toAttachment(): IAttachment; } /** Displays a signin card and button to the user. Some channels may choose to render this as a text prompt and link to click. */ export interface ISigninCard { /** Title of the Card. */ title: string; /** Sign in action. */ buttons: ICardAction[]; } /** * An interface representing OAuthCard. * A card representing a request to peform a sign in via OAuth * */ export interface IOAuthCard { /** * Text for signin request */ text: string; /** * The name of the registered connection */ connectionName: string; /** * Action to use to perform signin */ buttons: ICardAction[]; } /** * Displays a card to the user using either a smaller thumbnail layout or larger hero layout (the attachments [contentType](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.iattachment.html#contenttype) determines which). * All of the cards fields are optional so this card can be used to specify things like a keyboard on certain channels. Some channels may choose to render a lower fidelity version of the card or use an alternate representation. */ export interface IThumbnailCard { /** Title of the Card. */ title?: string; /** Subtitle appears just below Title field, differs from Title in font styling only. */ subtitle?: string; /** Text field appears just below subtitle, differs from Subtitle in font styling only. */ text?: string; /** Messaging supports all media formats: audio, video, images and thumbnails as well to optimize content download. */ images?: ICardImage[]; /** This action will be activated when user taps on the card. Not all channels support tap actions and some channels may choose to render the tap action as the titles link. */ tap?: ICardAction; /** Set of actions applicable to the current card. Not all channels support buttons or cards with buttons. Some channels may choose to render the buttons using a custom keyboard. */ buttons?: ICardAction[]; } /** Displays a rich receipt to a user for something they've either bought or are planning to buy. */ export interface IReceiptCard { /** Title of the Card. */ title: string; /** Array of receipt items. */ items: IReceiptItem[]; /** Array of additional facts to display to user (shipping charges and such.) Not all facts will be displayed on all channels. */ facts: IFact[]; /** This action will be activated when user taps on the card. Not all channels support tap actions. */ tap: ICardAction; /** Total amount of money paid (or should be paid.) */ total: string; /** Total amount of TAX paid (or should be paid.) */ tax: string; /** Total amount of VAT paid (or should be paid.) */ vat: string; /** Set of actions applicable to the current card. Not all channels support buttons and the number of allowed buttons varies by channel. */ buttons: ICardAction[]; } /** An individual item within a [receipt](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ireceiptcard.html). */ export interface IReceiptItem { /** Title of the item. */ title: string; /** Subtitle appears just below Title field, differs from Title in font styling only. On some channels may be combined with the [title](#title) or [text](#text). */ subtitle: string; /** Text field appears just below subtitle, differs from Subtitle in font styling only. */ text: string; /** Image to display on the card. Some channels may either send the image as a separate message or simply include a link to the image. */ image: ICardImage; /** Amount with currency. */ price: string; /** Number of items of given kind. */ quantity: string; /** This action will be activated when user taps on the Item bubble. Not all channels support tap actions. */ tap: ICardAction; } /** Implemented by classes that can be converted into a receipt item. */ export interface IIsReceiptItem { /** Returns the JSON object for the receipt item. */ toItem(): IReceiptItem; } /** The action that should be performed when a card, button, or image is tapped. */ export interface ICardAction { /** Defines the type of action implemented by this button. Not all action types are supported by all channels. */ type: string; /** Text description for button actions. */ title?: string; /** Parameter for Action. Content of this property depends on Action type. */ value: string; /** (Optional) Picture to display for button actions. Not all channels support button images. */ image?: string; /** (Optional) Text for this action. */ text?: string; /** (Optional) text to display in the chat feed if the button is clicked. */ diplayText?: string; } /** Implemented by classes that can be converted into a card action. */ export interface IIsCardAction { /** Returns the JSON object for the card attachment. */ toAction(): ICardAction; } /** Suggested actions to send to the user and displayed as quick replies. Suggested actions will be displayed only on the channels that support suggested actions. */ export interface ISuggestedActions { /** Optional recipients of the suggested actions. Not supported in all channels. */ to?: string[]; /** Quick reply actions that can be suggested as part of the message. */ actions: ICardAction[]; } /** Implemented by classes that can be converted into suggested actions */ export interface IIsSuggestedActions { /** Returns the JSON object for the suggested actions */ toSuggestedActions(): ISuggestedActions; } /** An image on a card. */ export interface ICardImage { /** Thumbnail image for major content property. */ url: string; /** Image description intended for screen readers. Not all channels will support alt text. */ alt: string; /** Action assigned to specific Attachment. E.g. navigate to specific URL or play/open media content. Not all channels will support tap actions. */ tap: ICardAction; } /** Implemented by classes that can be converted into a card image. */ export interface IIsCardImage { /** Returns the JSON object for the card image. */ toImage(): ICardImage; } /** A fact displayed on a card like a [receipt](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ireceiptcard.html). */ export interface IFact { /** Display name of the fact. */ key: string; /** Display value of the fact. */ value: string; } /** Implemented by classes that can be converted into a fact. */ export interface IIsFact { /** Returns the JSON object for the fact. */ toFact(): IFact; } /** Settings used to initialize an ILocalizer implementation. */ interface IDefaultLocalizerSettings { /** The path to the parent of the bots locale directory */ botLocalePath?: string; /** The default locale of the bot */ defaultLocale?: string; } /** Plugin for localizing messages sent to the user by a bot. */ export interface ILocalizer { /** * Loads the localized table for the supplied locale, and call's the supplied callback once the load is complete. * @param locale The locale to load. * @param callback callback that is called once the supplied locale has been loaded, or an error if the load fails. */ load(locale: string, callback: (err: Error) => void): void; /** * Loads a localized string for the specified language. * @param locale Desired locale of the string to return. * @param msgid String to use as a key in the localized string table. Typically this will just be the english version of the string. * @param namespace (Optional) namespace for the msgid keys. */ trygettext(locale: string, msgid: string, namespace?: string): string; /** * Loads a localized string for the specified language. * @param locale Desired locale of the string to return. * @param msgid String to use as a key in the localized string table. Typically this will just be the english version of the string. * @param namespace (Optional) namespace for the msgid keys. */ gettext(locale: string, msgid: string, namespace?: string): string; /** * Loads the plural form of a localized string for the specified language. * @param locale Desired locale of the string to return. * @param msgid Singular form of the string to use as a key in the localized string table. * @param msgid_plural Plural form of the string to use as a key in the localized string table. * @param count Count to use when determining whether the singular or plural form of the string should be used. * @param namespace (Optional) namespace for the msgid and msgid_plural keys. */ ngettext(locale: string, msgid: string, msgid_plural: string, count: number, namespace?: string): string; } /** Persisted session state used to track a conversations dialog stack. */ export interface ISessionState { /** Dialog stack for the current session. */ callstack: IDialogState[]; /** Timestamp of when the session was last accessed. */ lastAccess: number; /** Version number of the current callstack. */ version: number; } /** An entry on the sessions dialog stack. */ export interface IDialogState { /** ID of the dialog. */ id: string; /** Persisted state for the dialog. */ state: any; } /** * Results returned by a child dialog to its parent via a call to session.endDialog(). */ export interface IDialogResult<T> { /** The reason why the current dialog is being resumed. Defaults to [ResumeReason.completed](/en-us/node/builder/chat-reference/enums/_botbuilder_d_.resumereason#completed). */ resumed?: ResumeReason; /** ID of the child dialog thats ending. */ childId?: string; /** If an error occurred the child dialog can return the error to the parent. */ error?: Error; /** The users response. */ response?: T; } /** Context of the received message passed to various recognition methods. */ export interface IRecognizeContext { /** The message received from the user. For bot originated messages this may only contain the "to" & "from" fields. */ message: IMessage; /** Data for the user that's persisted across all conversations with the bot. */ userData: any; /** Shared conversation data that's visible to all members of the conversation. */ conversationData: any; /** Private conversation data that's only visible to the user. */ privateConversationData: any; /** Data for the active dialog. */ dialogData: any; /** The localizer for the session. */ localizer: ILocalizer; /** The current session logger. */ logger: SessionLogger; /** Returns the users preferred locale. */ preferredLocale(): string; /** * Loads a localized string for the messages language. If arguments are passed the localized string * will be treated as a template and formatted using [sprintf-js](https://github.com/alexei/sprintf.js) (see their docs for details.) * @param msgid String to use as a key in the localized string table. Typically this will just be the english version of the string. * @param args (Optional) arguments used to format the final output string. */ gettext(msgid: string, ...args: any[]): string; /** * Loads the plural form of a localized string for the messages language. The output string will be formatted to * include the count by replacing %d in the string with the count. * @param msgid Singular form of the string to use as a key in the localized string table. Use %d to specify where the count should go. * @param msgid_plural Plural form of the string to use as a key in the localized string table. Use %d to specify where the count should go. * @param count Count to use when determining whether the singular or plural form of the string should be used. */ ngettext(msgid: string, msgid_plural: string, count: number): string; /** Returns a copy of the current dialog stack for the session. */ dialogStack(): IDialogState[]; /** (Optional) The top intent identified for the message. */ intent?: IIntentRecognizerResult; /** (Optional) The name of the library passing the context is from. */ libraryName?: string; /** __DEPRECATED__ use [preferredLocale()](#preferredlocale) instead. */ locale: string; } /** Context passed to `Dialog.recognize()`. */ export interface IRecognizeDialogContext extends IRecognizeContext { /** If true the Dialog is the active dialog on the dialog stack. */ activeDialog: boolean; /** Data persisted for the current dialog . */ dialogData: any; } /** Context passed to `ActionSet.findActionRoutes()`. */ export interface IFindActionRouteContext extends IRecognizeContext { /** The type of route being searched for. */ routeType: string; } /** Options passed when defining a dialog action. */ export interface IDialogActionOptions { /** * (Optional) intent(s) used to trigger the action. Either a regular expression or a named * intent can be provided and multiple intents can be specified. When a named intent is * provided the action will be matched using the recognizers assigned to the library/bot using * [Library.recognizer()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.library#recognizer). * * If a matches option isn't provided then the action can only be matched if an [onFindAction](#onfindaction) * handler is provided. */ matches?: MatchType; /** (Optional) minimum score needed to trigger the action using the value of [matches](#matches). The default value is 0.1. */ intentThreshold?: number; /** * (Optional) custom handler that's invoked whenever the action is being checked to see if it * should be triggered. The handler is passed a context object containing the received message * and any intents detected. The handler should return a confidence score for 0.0 to 1.0 and * routeData that should be passed in during the `selectActionRoute` call. */ onFindAction?: (context: IFindActionRouteContext, callback: (err: Error, score: number, routeData?: IActionRouteData) => void) => void; /** * (Optional) custom handler that's invoked whenever the action is triggered. This lets you * customize the behavior of an action. For instance you could clear the dialog stack before * the new dialog is started, changing the default behavior which is to just push the new * dialog onto the end of the stack. * * It's important to note that this is not a waterfall and you should call `next()` if you * would like the actions default behavior to run. */ onSelectAction?: (session: Session, args?: IActionRouteData, next?: Function) => void; } /** Options passed when defining a `beginDialogAction()`. */ export interface IBeginDialogActionOptions extends IDialogActionOptions { /** (Optional) arguments to pass to the dialog spawned when the action is triggered. */ dialogArgs?: any; } /** Options passed when defining a `triggerAction()`. */ export interface ITriggerActionOptions extends IBeginDialogActionOptions { /** * If specified the user will be asked to confirm that they are ok canceling the current * uncompleted task. */ confirmPrompt?: TextOrMessageType; /** * (Optional) custom handler called when a root dialog is being interrupted by another root * dialog. This gives the dialog an opportunity to perform custom cleanup logic or to prompt * the user to confirm the interruption was intended. * * It's important to note that this is not a waterfall and you should call `next()` if you * would like the actions default behavior to run. */ onInterrupted?: (session: Session, dialogId: string, dialogArgs?: any, next?: Function) => void; } /** Options passed when defining a `cancelAction()`. */ export interface ICancelActionOptions extends IDialogActionOptions { /** * If specified the user will be asked to confirm that they truly would like to cancel an * action when triggered. */ confirmPrompt?: TextOrMessageType; } /** Arguments passed to a triggered action. */ export interface IActionRouteData { /** Named dialog action that was matched. */ action?: string; /** Intent that triggered the action. */ intent?: IIntentRecognizerResult; /** Optional data passed as part of the action binding. */ data?: string; /** ID of the dialog the action is bound to. */ dialogId?: string; /** Index on the dialog stack of the dialog the action is bound to. */ dialogIndex?: number; } /** * A choice that can be passed to [Prompts.choice()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#choice) * or [PromptRecognizers.recognizeChoices()][/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptrecognizers#recognizechoices]. */ export interface IChoice { /** Value to return when selected. */ value: string; /** (Optional) action to use when rendering the choice as a suggested action. */ action?: ICardAction; /** (Optional) list of synonyms to recognize in addition to the value. */ synonyms?: ValueListType; } /** Options passed to [PromptRecognizers.recognizeNumbers()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptrecognizers#recognizenumbers). */ export interface IPromptRecognizeNumbersOptions { /** (Optional) minimum value allowed. */ minValue?: number; /** (Optional) maximum value allowed. */ maxValue?: number; /** (Optional) if true, then only integers will be recognized. */ integerOnly?: boolean; } /** Options passed to [PromptRecognizers.recognizeTimes()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptrecognizers#recognizetimes). */ export interface IPromptRecognizeTimesOptions { /** (Optional) Reference date for relative times. */ refDate?: number; } /** Options passed to [PromptRecognizers.recognizeValues()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptrecognizers#recognizevalues). */ export interface IPromptRecognizeValuesOptions { /** * (Optional) if true, then only some of the tokens in a value need to exist to be considered * a match. The default value is "false". */ allowPartialMatches?: boolean; /** * (Optional) maximum tokens allowed between two matched tokens in the utterance. So with * a max distance of 2 the value "second last" would match the utterance "second from the last" * but it wouldn't match "Wait a second. That's not the last one is it?". * The default value is "2". */ maxTokenDistance?: number; } /** Options passed to [PromptRecognizers.recognizeChoices()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptrecognizers#recognizechoices). */ export interface IPromptRecognizeChoicesOptions extends IPromptRecognizeValuesOptions { /** (Optional) If true, the choices value will NOT be recognized over. */ excludeValue?: boolean; /** (Optional) If true, the choices action will NOT be recognized over. */ excludeAction?: boolean; } /** Options passed to the [built-in prompts](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts). */ export interface IPromptOptions extends IMessageOptions { /** * (Optional) Initial prompt to send the user. This is typically populated by the `Prompts.xxx()` function. */ prompt?: TextOrMessageType; /** (Optional) SSML to send with the initial `prompt`. If the prompt is of type `IMessage` or `IIsMessage`, this value will be ignored. If this value is an array a response will be chosen at random. */ speak?: TextType; /** * (Optional) retry prompt to send if the users response isn't understood. Default is to just * re-prompt with a customizable system prompt. */ retryPrompt?: TextOrMessageType; /** (Optional) SSML to send with the `retryPrompt`. If the retryPrompt is of type `IMessage` or `IIsMessage`, this value will be ignored. If this value is an array a response will be chosen at random. */ retrySpeak?: TextType; /** (Optional) maximum number of times to re-prompt the user. By default the user will be re-prompted indefinitely. */ maxRetries?: number; /** (Optional) flag used to control the re-prompting of a user after a dialog started by an action ends. The default value is true. */ promptAfterAction?: boolean; /** (Optional) type of list to render for PromptType.choice. Default value is ListStyle.auto. */ listStyle?: ListStyle; /** (Optional) reference date when recognizing times. Date expressed in ticks using Date.getTime(). */ refDate?: number; /** (Optional) namespace to use for localization and other purposes. This defaults to the callers namespace. */ libraryNamespace?: string; /** __DEPRECATED__ use [libraryNamespace](#librarynamespace) instead. */ localizationNamespace?: string; } /** * Contextual information tracked for a [Prompt](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompt). This information can be accessed * within a prompt through [session.dialogData](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session#dialogdata). */ export interface IPromptContext { /** Options that the prompt was called with. */ options: IPromptOptions; /** * Number of times the user has interacted with the prompt. The first message sent to the user * is turn-0, the users first reply is turn-1, and so forth. */ turns: number; /** Timestamp of the last turn. */ lastTurn: number; /** * If true, we're returning from an unexpected interruption and should send the initial turn-0 * prompt again. */ isReprompt: boolean; /** * Used to track which [Prompt.matches()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompt#matches) handler is active. This is * used internally to move the handlers waterfall to the next step. */ activeIntent: string; } /** Optional features that should be enabled/disabled when creating a custom [Prompt](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompt) */ export interface IPromptFeatures { /** If true, then the prompt should not execute it's own recognition logic. The default is "false". */ disableRecognizer?: boolean; /** The default retryPrompt to send should the caller not provide one. */ defaultRetryPrompt?: TextOrMessageType; /** The library namespace to use for the [defaultRetryPrompt](#defaultretryprompt). If not specified then the bots default namespace of "*" will be used. */ defaultRetryNamespace?: string; } /** Optional features for [PromptChoice](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptchoice) class. */ export interface IPromptChoiceFeatures extends IPromptFeatures { /** (Optional) if true, the prompt will attempt to recognize numbers in the users utterance as the index of the choice to return. The default value is "true". */ recognizeNumbers?: boolean; /** (Optional) if true, the prompt will attempt to recognize ordinals like "the first one" or "the second one" as the index of the choice to return. The default value is "true". */ recognizeOrdinals?: boolean; /** (Optional) if true, the prompt will attempt to recognize the selected value using the choices themselves. The default value is "true". */ recognizeChoices?: boolean; /** (Optional) style to use as the default when the caller specifies ListStyle.auto and it's determined that keyboards aren't supported. The default value is "ListStyle.list". */ defaultListStyle?: ListStyle; /** (Optional) number of items to show in an inline list when a [defaultListStyle](#defaultliststyle) of ListStyle.list is being applied. The default value is "3". Set this value to "0" to disable inline mode. */ inlineListCount?: number; /** (Optional) minimum score from 0.0 - 1.0 needed for a recognized choice to be considered a match. The default value is "0.4". */ minScore?: number; } /** * Options passed to [Prompts.choice()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#choice) * or in a `session.beginDialog()` call to a custom prompt based on the [PromptChoice](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptchoice) * class. */ export interface IPromptChoiceOptions extends IPromptOptions { /** * (Optional) List of choices to present to the user. If omitted a [PromptChoice.onChoices()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptchoice#onchoices) * handler should be provided. */ choices?: IChoice[]; } /** * Options passed to [Prompts.number()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#number) * or in a `session.beginDialog()` call to a custom prompt based on the [PromptNumber](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptnumber) * class. */ export interface IPromptNumberOptions extends IPromptOptions { /** (Optional) minimum value that can be recognized. */ minValue?: number; /** (Optional) maximum value that can be recognized. */ maxValue?: number; /** (Optional) if true, then only integers will be recognized. The default value is false. */ integerOnly?: boolean; } /** * Options passed to [Prompts.text()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#text) * or in a `session.beginDialog()` call to a custom prompt based on the [PromptText](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompttext) * class. */ export interface IPromptTextOptions extends IPromptOptions { /** (Optional) minimum length that can be recognized. */ minLength?: number; /** (Optional) maximum length that can be recognized. */ maxLength?: number; } /** Optional features for [PromptText](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompttext) class. */ export interface IPromptTextFeatures extends IPromptFeatures { /** * (Optional) The score that should be returned when the prompts [onRecognize()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompt#onrecognize) * handler is called. The default value is "0.5". */ recognizeScore?: number; } /** * Options passed to [Prompts.attachment()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#attachment) * or in a `session.beginDialog()` call to a custom prompt based on the [PromptAttachment](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptattachment) * class. */ export interface IPromptAttachmentOptions extends IPromptOptions { /** * (Optional) list of content types the prompt is waiting for. Types ending with '*' will be * prefixed matched again the received attachment(s). */ contentTypes?: string|string[]; } /** Optional features for [PromptAttachment](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.promptattachment) class. */ export interface IPromptAttachmentFeatures extends IPromptFeatures { /** (Optional) The score that should be returned when attachments are detected. The default value is "1.0". */ recognizeScore?: number; } /** * Route choices to pass to [Prompts.disambiguate()](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.__global.iprompts#disambiguate). * The key for the map should be the localized label to display to the user and the value should be * the route to select when chosen by the user. You can pass `null` for the route to give the user the option to cancel. * @example * <pre><code> * builder.Prompts.disambiguate(session, "What would you like to cancel?", { * "Cancel Item": cancelItemRoute, * "Cancel Order": cancelOrderRoute, * "Neither": null * }); * </code></pre> */ export interface IDisambiguateChoices { [label: string]: IRouteResult; } /** Dialog result returned by a system prompt. */ export interface IPromptResult<T> extends IDialogResult<T> { /** Type of prompt completing. */ promptType?: PromptType; } /** Result returned from an IPromptRecognizer. */ export interface IPromptRecognizerResult<T> extends IPromptResult<T> { /** Returned from a prompt recognizer to indicate that a parent dialog handled (or captured) the utterance. */ handled?: boolean; } /** Strongly typed Text Prompt Result. */ export interface IPromptTextResult extends IPromptResult<string> { } /** Strongly typed Number Prompt Result. */ export interface IPromptNumberResult extends IPromptResult<number> { } /** Strongly typed Confirm Prompt Result. */ export interface IPromptConfirmResult extends IPromptResult<boolean> { } /** Strongly typed Choice Prompt Result. */ export interface IPromptChoiceResult extends IPromptResult<IFindMatchResult> { } /** Strongly typed Time Prompt Result. */ export interface IPromptTimeResult extends IPromptResult<IEntity> { } /** Strongly typed Attachment Prompt Result. */ export interface IPromptAttachmentResult extends IPromptResult<IAttachment[]> { } /** A recognized intent. */ export interface IIntent { /** Intent that was recognized. */ intent: string; /** Confidence on a scale from 0.0 - 1.0 that the proper intent was recognized. */ score: number; } /** A recognized entity. */ export interface IEntity { /** Type of entity that was recognized. */ type: string; /** Value of the recognized entity. */ entity: any; /** Start position of entity within text utterance. */ startIndex?: number; /** End position of entity within text utterance. */ endIndex?: number; /** Confidence on a scale from 0.0 - 1.0 that the proper entity was recognized. */ score?: number; } /** Options used to configure an [IntentRecognizerSet](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentrecognizerset.html). */ export interface IIntentRecognizerSetOptions { /** (optional) Minimum score needed to trigger the recognition of an intent. The default value is 0.1. */ intentThreshold?: number; /** (Optional) The order in which the configured [recognizers](#recognizers) should be evaluated. The default order is parallel. */ recognizeOrder?: RecognizeOrder; /** (Optional) list of intent recognizers to run the users utterance through. */ recognizers?: IIntentRecognizer[]; /** (Optional) Maximum number of recognizers to evaluate at one time when [recognizerOrder](#recognizerorder) is parallel. */ processLimit?: number; /** (Optional) If true the recognition will stop when a score of 1.0 is encountered. The default value is true. */ stopIfExactMatch?: boolean; } /** Options used to configure an [IntentDialog](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentdialog.html). */ export interface IIntentDialogOptions extends IIntentRecognizerSetOptions { /** (Optional) Controls the dialogs processing of incoming user utterances. The default is RecognizeMode.onBeginIfRoot. The default prior to v3.2 was RecognizeMode.onBegin. */ recognizeMode?: RecognizeMode; } /** Interface implemented by intent recognizer plugins like t