UNPKG

@microsoft/botbuilder-m365

Version:

M365 extensions for Microsoft BotBuilder, Alpha release.

155 lines 9.13 kB
/** * @module botbuilder-m365 */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { TurnContext, Storage, BotAdapter, ConversationReference, Activity, ResourceResponse } from 'botbuilder'; import { TurnState, TurnStateManager } from './TurnState'; import { DefaultTurnState } from './DefaultTurnStateManager'; import { AdaptiveCards, AdaptiveCardsOptions } from './AdaptiveCards'; import { MessageExtensions } from './MessageExtensions'; import { AI, AIOptions } from './AI'; import { TaskModules, TaskModulesOptions } from './TaskModules'; export interface Query<TParams extends Record<string, any>> { count: number; skip: number; parameters: TParams; } export interface ApplicationOptions<TState extends TurnState> { adapter?: BotAdapter; botAppId?: string; storage?: Storage; ai?: AIOptions<TState>; turnStateManager?: TurnStateManager<TState>; adaptiveCards?: AdaptiveCardsOptions; taskModules?: TaskModulesOptions; removeRecipientMention?: boolean; startTypingTimer?: boolean; longRunningMessages?: boolean; } export declare type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>; export declare type ConversationUpdateEvents = 'channelCreated' | 'channelRenamed' | 'channelDeleted' | 'channelRestored' | 'membersAdded' | 'membersRemoved' | 'teamRenamed' | 'teamDeleted' | 'teamArchived' | 'teamUnarchived' | 'teamRestored'; export declare type RouteHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<void>; export declare type RouteSelector = (context: TurnContext) => Promise<boolean>; export declare type MessageReactionEvents = 'reactionsAdded' | 'reactionsRemoved'; export declare type TurnEvents = 'beforeTurn' | 'afterTurn'; export declare class Application<TState extends TurnState = DefaultTurnState> { private readonly _options; private readonly _routes; private readonly _invokeRoutes; private readonly _adaptiveCards; private readonly _messageExtensions; private readonly _taskModules; private readonly _ai?; private readonly _beforeTurn; private readonly _afterTurn; private _typingTimer; constructor(options?: ApplicationOptions<TState>); get adaptiveCards(): AdaptiveCards<TState>; get ai(): AI<TState>; get messageExtensions(): MessageExtensions<TState>; get options(): ApplicationOptions<TState>; get taskModules(): TaskModules<TState>; /** * Adds a new route to the application. * * Routes will be matched in the order they're added to the application. The first selector to * return `true` when an activity is received will have its handler called. * * @param {RouteSelector} selector Promise to determine if the route should be triggered. * @param {RouteHandler<TurnState>} handler Function to call when the route is triggered. * @param {boolean} isInvokeRoute boolean indicating if the RouteSelector is an invokable Teams activity as part of its routing logic. Defaults to `false`. * @returns {this} The application instance for chaining purposes. */ addRoute(selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute?: boolean): this; /** * Handles incoming activities of a given type. * * @param {string | RegExp | RouteSelector | string[] | RegExp[] | RouteSelector[] } type Name of the activity type to match or a regular expression to match against the incoming activity type. An array of type names or expression can also be passed in. * @param {Promise<void>} handler Function to call when the route is triggered. * @returns {this} The application instance for chaining purposes. */ activity(type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>): this; /** * Handles conversation update events. * * @param {ConversationUpdateEvents | ConversationUpdateEvents[]} event Name of the conversation update event(s) to handle. * @param {Promise<void>} handler Function to call when the route is triggered. * @returns {this} The application instance for chaining purposes. */ conversationUpdate(event: ConversationUpdateEvents | ConversationUpdateEvents[], handler: (context: TurnContext, state: TState) => Promise<void>): this; /** * Starts a new "proactive" session with a conversation the bot is already a member of. * * @param {TurnContext} context Context of the conversation to proactively message. This can be derived from either a TurnContext, ConversationReference, or Activity. * @param {Promise<void>} logic The bot's logic that should be run using the new proactive turn context. */ continueConversationAsync(context: TurnContext, logic: (context: TurnContext) => Promise<void>): Promise<void>; continueConversationAsync(conversationReference: Partial<ConversationReference>, logic: (context: TurnContext) => Promise<void>): Promise<void>; continueConversationAsync(activity: Partial<Activity>, logic: (context: TurnContext) => Promise<void>): Promise<void>; /** * Handles incoming messages with a given keyword. * * @param {string | RegExp | RouteSelector | (string | RegExp | RouteSelector[])} keyword Substring of text or a regular expression to match against the text of an incoming message. An array of keywords or expression can also be passed in. * @param {Promise<void>} handler Function to call when the route is triggered. * @returns {this} The application instance for chaining purposes. */ message(keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[], handler: (context: TurnContext, state: TState) => Promise<void>): this; /** * Handles message reaction events. * * @param {MessageReactionEvents | MessageReactionEvents[]} event Name of the message reaction event to handle. * @param {Promise<void>} handler Function to call when the route is triggered. * @returns {this} The application instance for chaining purposes. */ messageReactions(event: MessageReactionEvents | MessageReactionEvents[], handler: (context: TurnContext, state: TState) => Promise<void>): this; /** * Dispatches an incoming activity to a handler registered with the application. * * @param {TurnContext} turnContext Context class for the current turn of conversation with the user. * @returns {boolean} True if the activity was successfully dispatched to a handler. False if no matching handlers could be found. */ run(turnContext: TurnContext): Promise<boolean>; /** * Sends a proactive activity to an existing conversation the bot is a member of. * * @param context Context of the conversation to proactively message. This can be derived from either a TurnContext, ConversationReference, or Activity. * @param activityOrText Activity or message to send to the conversation. * @param speak Optional. Text to speak for channels that support voice. * @param inputHint Optional. Input hint for channels that support voice. * @returns A Resource response containing the ID of the activity that was sent. */ sendProactiveActivity(context: TurnContext, activityOrText: string | Partial<Activity>, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined>; sendProactiveActivity(conversationReference: Partial<ConversationReference>, activityOrText: string | Partial<Activity>, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined>; sendProactiveActivity(activity: Partial<Activity>, activityOrText: string | Partial<Activity>, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined>; /** * Manually start a timer to periodically send "typing" activities. * * * The timer will automatically end once an outgoing activity has been sent. If the timer is * already running or the current activity, is not a "message" the call is ignored. * * @param {TurnContext} context The context for the current turn with the user. */ startTypingTimer(context: TurnContext): void; /** * Manually stop the typing timer. * * * If the timer isn't running nothing happens. */ stopTypingTimer(): void; /** * Registers a turn event handler. * * @param {TurnEvents | TurnEvents[]} event Name of the turn event to handle. * @param {Promise<void>} handler Function to call when the event is triggered. * @returns {this} The application instance for chaining purposes. */ turn(event: TurnEvents | TurnEvents[], handler: ApplicationEventHandler<TState>): this; private callEventHandlers; private startLongRunningCall; } //# sourceMappingURL=Application.d.ts.map