UNPKG

relu-core

Version:
1,107 lines (878 loc) 160 kB
//============================================================================= // // INTERFACES // //============================================================================= /** * An event received from or being sent to a source. */ 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 Properties of a conversation have changed. */ export interface IConversationUpdate extends IEvent { /** Array of members added to the conversation. */ membersAdded?: IIdentity[]; /** Array of members removed from the conversation. */ membersRemoved?: IIdentity[]; /** The conversations new topic name. */ topicName?: string; /** If true then history was disclosed. */ historyDisclosed?: boolean; } /** A user has updated their contact list. */ 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. */ export interface IMessage extends IEvent { /** Timestamp of message given by chat service for incoming messages. */ timestamp: 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; /** 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; } /** Implemented by classes that can be converted into a message. */ export interface IIsMessage { /** Returns the JSON object for the message. */ toMessage(): IMessage; } /** 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; } /** * Address routing information for a [message](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.imessage.html#address). * Addresses are bidirectional meaning they can be used to address both incoming and outgoing messages. 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. */ 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; } /** Chat connector specific address. */ export interface IChatConnectorAddress extends IAddress { /** Incoming Message ID. */ id?: string; /** Specifies the URL to post messages back. */ serviceUrl?: 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 and Keyboards:__ A rich set of visual cards and custom keyboards 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; } /** 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[]; } /** * 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 seperate 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; } /** Implemented by classes that can be converted into a card action. */ export interface IIsCardAction { /** Returns the JSON object for the card attachment. */ toAction(): ICardAction; } /** 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 bot's 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 localied 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} */ resumed?: ResumeReason; /** ID of the child dialog thats ending. */ childId?: string; /** If an error occured 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; /** The localizer for the session. */ localizer: ILocalizer ; /** 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 callstack. */ 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 triggered from a button click. */ matches?: RegExp|RegExp[]|string|string[]; /** (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 behaviour of an action. For instance you could clear the dialog stack before * the new dialog is started, changing the default behaviour 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 behaviour to run. */ onSelectAction?: (session: Session, args?: IActionRouteData, next?: Function) => void; /** (Optional) display label for the action which can be presented to the user when disambiguting between actions. */ label?: string; } /** 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. * * _{string}_ - Initial message to send the user. * * _{string[]}_ - Array of possible messages to send user. One will be chosen at random. * * _{IMessage}_ - Message to send the user. Message can contain attachments. * * _{IIsMessage}_ - Instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. */ confirmPrompt?: string|string[]|IMessage|IIsMessage; /** * (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 behaviour 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 truely would like to cancel an * action when triggered. * * _{string}_ - Initial message to send the user. * * _{string[]}_ - Array of possible messages to send user. One will be chosen at random. * * _{IMessage}_ - Message to send the user. Message can contain attachments. * * _{IIsMessage}_ - Instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. */ confirmPrompt?: string|string[]|IMessage|IIsMessage; } /** 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; } /** Options passed to built-in prompts. */ export interface IPromptOptions { /** * (Optional) retry prompt to send if the users response isn't understood. Default is to just * reprompt with the configured [defaultRetryPrompt](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ipromptsoptions.html#defaultretryprompt) * plus the original prompt. * * Note that if the original prompt is an _IMessage_ the retry prompt will be sent as a seperate * message followed by the original message. If the retryPrompt is also an _IMessage_ it will * instead be sent in place of the original message. * * _{string}_ - Initial message to send the user. * * _{string[]}_ - Array of possible messages to send user. One will be chosen at random. * * _{IMessage}_ - Initial message to send the user. Message can contain attachments. * * _{IIsMessage}_ - Instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. */ retryPrompt?: string|string[]|IMessage|IIsMessage; /** (Optional) maximum number of times to reprompt the user. By default the user will be reprompted indefinitely. */ maxRetries?: number; /** (Optional) reference date when recognizing times. Date expressed in ticks using Date.getTime(). */ refDate?: number; /** (Optional) type of list to render for PromptType.choice. Default value is ListStyle.auto. */ listStyle?: ListStyle; /** (Optional) flag used to control the reprompting of a user after a dialog started by an action ends. The default value is true. */ promptAfterAction?: boolean; /** (Optional) namespace to use when localizing a passed in prompt. */ localizationNamespace?: string; } /** Arguments passed to the built-in prompts beginDialog() call. */ export interface IPromptArgs extends IPromptOptions { /** Type of prompt invoked. */ promptType: PromptType; /** * Initial message to send to user. * * _{string}_ - Initial message to send the user. * * _{string[]}_ - Array of possible messages to send user. One will be chosen at random. * * _{IMessage}_ - Initial message to send the user. Message can contain attachments. * * _{IIsMessage}_ - Instance of the [Message](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.message.html) builder class. */ prompt: string|string[]|IMessage|IIsMessage; /** Enum values for a choice prompt. */ enumsValues?: string[]; } /** * Route choices to pass to [Prompts.diambiguate()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompts#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[]> { } /** Plugin for recognizing prompt responses received by a user. */ export interface IPromptRecognizer { /** * Attempts to match a users reponse to a given prompt. * @param args Arguments passed to the recognizer including that language, text, and prompt choices. * @param callback Function to invoke with the result of the recognition attempt. * @param callback.result Returns the result of the recognition attempt. */ recognize<T>(args: IPromptRecognizerArgs, callback: (result: IPromptRecognizerResult<T>) => void): void; } /** Arguments passed to the IPromptRecognizer.recognize() method.*/ export interface IPromptRecognizerArgs { /** Type of prompt being responded to. */ promptType: PromptType; /** Text of the users response to the prompt. */ text: string; /** Language of the text if known. */ language?: string; /** For choice prompts the list of possible choices. */ enumValues?: string[]; /** (Optional) reference date when recognizing times. */ refDate?: number; } /** Global configuration options for the Prompts dialog. */ export interface IPromptsOptions { /** Replaces the default recognizer (SimplePromptRecognizer) used to recognize prompt replies. */ recognizer?: IPromptRecognizer } /** 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: string; /** 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 incomming 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 the [LuisRecognizer](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.luisrecognizer.html) class. */ export interface IIntentRecognizer { /** * Attempts to match a users text utterance to an intent. * @param context Contextual information for a received message that's being recognized. * @param callback Function to invoke with the results of the recognition operation. * @param callback.error Any error that occured or `null`. * @param callback.result The result of the recognition. */ recognize(context: IRecognizeContext, callback: (err: Error, result: IIntentRecognizerResult) => void): void; } /** Results from a call to a recognize() function. The implementation is free to add any additional properties to the result. */ export interface IRecognizeResult { /** Confidence that the users utterance was understood on a scale from 0.0 - 1.0. */ score: number; } /** Results returned by an intent recognizer. */ export interface IIntentRecognizerResult extends IRecognizeResult { /** Top intent that was matched. */ intent: string; /** A regular expression that was matched. */ expression?: RegExp; /** The results of the [expression](#expression) that was matched. matched[0] will be the text that was matched and matched[1...n] is the result of capture groups. */ matched?: string[]; /** Full list of intents that were matched. */ intents?: IIntent[]; /** List of entities recognized. */ entities?: IEntity[]; } /** Options passed to the constructor of a session. */ export interface ISessionOptions { /** Function to invoke when the sessions state is saved. */ onSave: (done: (err: Error) => void) => void; /** Function to invoke when a batch of messages are sent. */ onSend: (messages: IMessage[], done: (err: Error) => void) => void; /** The bots root library of dialogs. */ library: Library; /** The localizer to use for the session. */ localizer: ILocalizer; /** Array of session middleware to execute prior to each request. */ middleware: ISessionMiddleware[]; /** Unique ID of the dialog to use when starting a new conversation with a user. */ dialogId: string; /** (Optional) arguments to pass to the conversations initial dialog. */ dialogArgs?: any; /** (Optional) time to allow between each message sent as a batch. The default value is 250ms. */ autoBatchDelay?: number; /** Default error message to send users when a dialog error occurs. */ dialogErrorMessage?: string|string[]|IMessage|IIsMessage; /** Global actions registered for the bot. */ actions?: ActionSet; } /** result returnd from a call to EntityRecognizer.findBestMatch() or EntityRecognizer.findAllMatches(). */ export interface IFindMatchResult { /** Index of the matched value. */ index: number; /** Value that was matched. */ entity: string; /** Confidence score on a scale from 0.0 - 1.0 that a value matched the users utterance. */ score: number; } /** Context object passed to IBotStorage calls. */ export interface IBotStorageContext { /** (Optional) ID of the user being persisted. If missing __userData__ won't be persisted. */ userId?: string; /** (Optional) ID of the conversation being persisted. If missing __conversationData__ and __privateConversationData__ won't be persisted. */ conversationId?: string; /** (Optional) Address of the message received by the bot. */ address?: IAddress; /** If true IBotStorage should persist __userData__. */ persistUserData: boolean; /** If true IBotStorage should persist __conversationData__. */ persistConversationData: boolean; } /** Data values persisted to IBotStorage. */ export interface IBotStorageData { /** The bots data about a user. This data is global across all of the users conversations. */ userData?: any; /** The bots shared data for a conversation. This data is visible to every user within the conversation. */ conversationData?: any; /** * The bots private data for a conversation. This data is only visible to the given user within the conversation. * The session stores its session state using privateConversationData so it should always be persisted. */ privateConversationData?: any; } /** Replacable storage system used by UniversalBot. */ export interface IBotStorage { /** Reads in data from storage. */ getData(context: IBotStorageContext, callback: (err: Error, data: IBotStorageData) => void): void; /** Writes out data to storage. */ saveData(context: IBotStorageContext, data: IBotStorageData, callback?: (err: Error) => void): void; } /** Options used to initialize a ChatConnector instance. */ export interface IChatConnectorSettings { /** The bots App ID assigned in the Bot Framework portal. */ appId?: string; /** The bots App Password assigned in the Bot Framework Portal. */ appPassword?: string; /** If true the bots userData, privateConversationData, and conversationData will be gzipped prior to writing to storage. */ gzipData?: boolean; } /** Options used to initialize a UniversalBot instance. */ export interface IUniversalBotSettings { /** (Optional) dialog to launch when a user initiates a new conversation with a bot. Default value is '/'. */ defaultDialogId?: string; /** (Optional) arguments to pass to the initial dialog for a conversation. */ defaultDialogArgs?: any; /** (Optional) settings used to configure the frameworks built in default localizer. */ localizerSettings?: IDefaultLocalizerSettings; /** (Optional) function used to map the user ID for an incoming message to another user ID. This can be used to implement user account linking. */ lookupUser?: (address: IAddress, done: (err: Error, user: IIdentity) => void) => void; /** (Optional) maximum number of async options to conduct in parallel. */ processLimit?: number; /** (Optional) time to allow between each message sent as a batch. The default value is 150ms. */ autoBatchDelay?: number; /** (Optional) storage system to use for storing user & conversation data. */ storage?: IBotStorage; /** (optional) if true userData will be persisted. The default value is true. */ persistUserData?: boolean; /** (Optional) if true shared conversationData will be persisted. The default value is false. */ persistConversationData?: boolean; /** (Optional) message to send the user should an unexpected error occur during a conversation. A default message is provided. */ dialogErrorMessage?: string|string[]|IMessage|IIsMessage; } /** Implemented by connector plugins for the UniversalBot. */ export interface IConnector { /** Used to register a handler for receiving incoming invoke events. */ onInvoke?(handler: (event: IEvent, cb?: (err: Error, body: any, status?: number) => void) => void): void; /** Called by the UniversalBot at registration time to register a handler for receiving incoming events from a channel. */ onEvent(handler: (events: IEvent[], callback?: (err: Error) => void) => void): void; /** Called by the UniversalBot to deliver outgoing messages to a user. */ send(messages: IMessage[], callback: (err: Error) => void): void; /** Called when a UniversalBot wants to start a new proactive conversation with a user. The connector should return a properly formated __address__ object with a populated __conversation__ field. */ startConversation(address: IAddress, callback: (err: Error, address?: IAddress) => void): void; } /** Function signature for a piece of middleware that hooks the 'receive' or 'send' events. */ export interface IEventMiddleware { (event: IEvent, next: Function): void; } /** Function signature for a piece of middleware that hooks the 'botbuilder' event. */ export interface ISessionMiddleware { (session: Session, next: Function): void; } /** * Map of middleware hooks that can be registered in a call to __UniversalBot.use()__. */ export interface IMiddlewareMap { /** Called in series when an incoming event is received. */ receive?: IEventMiddleware|IEventMiddleware[]; /** Called in series before an outgoing event is sent. */ send?: IEventMiddleware|IEventMiddleware[]; /** Called in series once an incoming message has been bound to a session. Executed after [receive](#receive) middleware. */ botbuilder?: ISessionMiddleware|ISessionMiddleware[]; } /** * Signature for functions passed as steps to [DialogAction.waterfall()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.dialogaction.html#waterfall). * * Waterfalls let you prompt a user for information using a sequence of questions. Each step of the * waterfall can either execute one of the built-in [Prompts](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.prompts.html), * start a new dialog by calling [session.beginDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#begindialog), * advance to the next step of the waterfall manually using `skip()`, or terminate the waterfall. * * When either a dialog or built-in prompt is called from a waterfall step, the results from that * dialog or prompt will be passed via the `results` parameter to the next step of the waterfall. * Users can say things like "nevermind" to cancel the built-in prompts so you should guard against * that by at least checking for [results.response](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.idialogresult.html#response) * before proceeding. A more detailed explination of why the waterfall is being continued can be * determined by looking at the [code](/en-us/node/builder/chat-reference/enums/_botbuilder_d_.resumereason.html) * returned for [results.resumed](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.idialogresult.html#resumed). * * You can manually advance to the next step of the waterfall using the `skip()` function passed * in. Calling `skip({ response: "some text" })` with an [IDialogResult](/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.idialogresult.html) * lets you more accurately mimic the results from a built-in prompt and can simplify your overall * waterfall logic. * * You can terminate a waterfall early by either falling through every step of the waterfall using * calls to `skip()` or simply not starting another prompt or dialog. * * __note:__ Waterfalls have a hidden last step which will automatically end the current dialog if * if you call a prompt or dialog from the last step. This is useful where you have a deep stack of * dialogs and want a call to [session.endDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#enddialog) * from the last child on the stack to end the entire stack. The close of the last child will trigger * all of its parents to move to this hidden step which will cascade the close all the way up the stack. * This is typically a desired behaviour but if you want to avoid it or stop it somewhere in the * middle you'll need to add a step to the end of your waterfall that either does nothing or calls * something like [session.send()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#send) * which isn't going to advance the waterfall forward. * @example * <pre><code> * var bot = new builder.BotConnectorBot(); * bot.add('/', [ * function (session) { * builder.Prompts.text(session, "Hi! What's your name?"); * }, * function (session, results) { * if (results && results.response) { * // User answered question. * session.send("Hello %s.", results.response); * } else { * // User said nevermind. * session.send("OK. Goodbye."); * } * } * ]); * </code></pre> */ export interface IDialogWaterfallStep { /** * @param session Session object for the current conversation. * @param result * * __result:__ _{any}_ - For the first step of the waterfall this will be `null` or the value of any arguments passed to the handler. * * __result:__ _{IDialogResult}_ - For subsequent waterfall steps this will be the result of the prompt or dialog called in the previous step. * @param skip Fuction used to manually skip to the next step of the waterfall. * @param skip.results (Optional) results to pass to the next waterfall step. This lets you more accurately mimic the results returned from a prompt or dialog. */ (session: Session, result?: any | IDialogResult<any>, skip?: (results?: IDialogResult<any>) => void): any; } /** A per/local mapping of regular expressions to use for a RegExpRecognizer. */ export interface IRegExpMap { [local: string]: RegExp; } /** A per/local mapping of LUIS service url's to use for a LuisRecognizer. */ export interface ILuisModelMap { [local: string]: string; } /** A per/source mapping of custom event data to send. */ export interface ISourceEventMap { [source: string]: any; } /** Options passed to Middleware.dialogVersion(). */ export interface IDialogVersionOptions { /** Current major.minor version for the bots dialogs. Major version increments result in existing conversations between the bot and user being restarted. */ version: number; /** Optional message to send the user when their conversation is ended due to a version number change. A default message is provided. */ message?: string|string[]|IMessage|IIsMessage; /** Optional regular expression to listen for to manually detect a request to reset the users session state. */ resetCommand?: RegExp; } /** Options passed to Middleware.firstRun(). */ export interface IFirstRunOptions { /** Current major.minor version for the bots first run experience. Major version increments result in redirecting users to [dialogId](#dialogid) and minor increments redirect users to [upgradeDialogId](#upgradedialogid). */ version: number; /** Dialog to redirect users to when the major [version](#version) changes. */ dialogId: string; /** (Optional) args to pass to [dialogId](#dialogid). */ dialogArgs?: any; /** (Optional) dialog to redirect users to when the minor [version](#version) changes. Useful for minor Terms of Use changes. */ upgradeDialogId?: string; /** (Optional) args to pass to [upgradeDialogId](#upgradedialogid). */ upgradeDialogArgs?: string; } /** Candidate route returned by [Library.findRoutes()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.library#findroutes). */ export interface IRouteResult { /** Confidence score on a scale from 0.0 - 1.0 that the route is best suited for handling the current message. */ score: number; /** Name of the library the route came from. */ libraryName: string; /** (Optional) type of route returned. */ routeType?: string; /** (Optional) data used to assist with triggering a selected route. */ routeData?: any; } /** Custom route searching logic passed to [Library.onFindRoutes()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.library#onfindroutes). */ export interface IFindRoutesHandler { (context: IRecognizeContext, callback: (err: Error, routes: IRouteResult[]) => void): void; } /** Custom route searching logic passed to [Library.onSelectRoute()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.library#onselectroute). */ export interface ISelectRouteHandler { (session: Session, route: IRouteResult): void; } /** Custom route disambiguation logic passed to [UniversalBot.onDisambiguateRoute()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot#ondisambiguateroute). */ export interface IDisambiguateRouteHandler { (session: Session, routes: IRouteResult[]): void; } /** Interface definition for a video card */ export interface IVideoCard extends IMediaCard { /** Hint of the aspect ratio of the video or animation. (16:9)(4:3) */ aspect: string; } /** Interface definition for an audio card */ export interface IAudioCard extends IMediaCard { } /** Interface definition for an animation card */ export interface IAnimationCard extends IMediaCard { /** Hint of the aspect ratio of the video or animation. (16:9)(4:3) */ aspect: string; } /** Inter