botbuilder-core
Version: 
Core components for Microsoft Bot Builder. Components in this library can run either in a browser or on the server.
264 lines • 11.6 kB
TypeScript
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
import { ChannelAccount, MessageReaction, TurnContext } from '.';
import { InvokeResponse } from './invokeResponse';
export declare const INVOKE_RESPONSE_KEY: unique symbol;
/**
 * Defines the core behavior for event-emitting activity handlers for bots.
 *
 * @remarks
 * This provides an extensible class for handling incoming activities in an event-driven way.
 * You can register an arbitrary set of handlers for each event type.
 *
 * To register a handler for an event, use the corresponding _on event_ method. If multiple handlers are
 * registered for an event, they are run in the order in which they were registered.
 *
 * This object emits a series of _events_ as it processes an incoming activity.
 * A handler can stop the propagation of the event by not calling the continuation function.
 *
 * | Event type | Description |
 * | :--- | :--- |
 * | Type-specific | Emitted for the specific activity type, before emitting an event for any sub-type. |
 * | Sub-type | Emitted for certain specialized events, based on activity content. |
 *
 * **See also**
 * - The [Bot Framework Activity schema](https://aka.ms/botSpecs-activitySchema)
 */
export declare class ActivityHandlerBase {
    /**
     * Called at the start of the event emission process.
     *
     * @param context The context object for the current turn.
     * @remarks
     * Override this method to use custom logic for emitting events.
     *
     * The default logic is to call any type-specific and sub-type handlers registered via
     * the various _on event_ methods. Type-specific events are defined for:
     * - Message activities
     * - Conversation update activities
     * - Message reaction activities
     * - Event activities
     * - Invoke activities
     * - _Unrecognized_ activities, ones that this class has not otherwise defined an _on event_ method for.
     */
    protected onTurnActivity(context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _message_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _message_ handlers and then continue the event
     * emission process.
     */
    protected onMessageActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _message update_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _message update_ handlers and then continue the event
     * emission process.
     */
    protected onMessageUpdateActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _message delete_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _message delete_ handlers and then continue the event
     * emission process.
     */
    protected onMessageDeleteActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _conversation update_ event.
     *
     * @param context The context object for the current turn.
     * @remarks
     * Override this method to run registered _conversation update_ handlers and then continue the event
     * emission process.
     *
     * The default logic is:
     * - If members other than the bot were added to the conversation,
     *   call [onMembersAddedActivity](xref:botbuilder-core.ActivityHandlerBase.onMembersAddedActivity).
     * - If members other than the bot were removed from the conversation,
     *   call [onMembersRemovedActivity](xref:botbuilder-core.ActivityHandlerBase.onMembersRemovedActivity).
     */
    protected onConversationUpdateActivity(context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _message reaction_ event.
     *
     * @param context The context object for the current turn.
     * @remarks
     * Override this method to run registered _message reaction_ handlers and then continue the event
     * emission process.
     *
     * The default logic is:
     * - If reactions were added to a message,
     *   call [onReactionsAddedActivity](xref:botbuilder-core.ActivityHandlerBase.onReactionsAddedActivity).
     * - If reactions were removed from a message,
     *   call [onReactionsRemovedActivity](xref:botbuilder-core.ActivityHandlerBase.onReactionsRemovedActivity).
     */
    protected onMessageReactionActivity(context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _event_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _event_ handlers and then continue the event
     * emission process.
     */
    protected onEventActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for invoke calls.
     *
     * @param _context The context object for the current turn.
     * @returns {Promise<InvokeResponse>} An Invoke Response for the activity.
     * @remarks
     * Override this method to handle particular invoke calls.
     */
    protected onInvokeActivity(_context: TurnContext): Promise<InvokeResponse>;
    /**
     * Provides a hook for emitting the _end of conversation_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _end of conversation_ handlers and then continue the event
     * emission process.
     */
    protected onEndOfConversationActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _typing_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _typing_ handlers and then continue the event
     * emission process.
     */
    protected onTypingActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _installationupdate_ event.
     *
     * @param context The context object for the current turn.
     * @remarks
     * Override this method to run registered _installationupdate_ handlers and then continue the event
     * emission process.
     */
    protected onInstallationUpdateActivity(context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _installationupdateadd_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _installationupdateadd_ handlers and then continue the event
     * emission process.
     */
    protected onInstallationUpdateAddActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _installationupdateremove_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _installationupdateremove_ handlers and then continue the event
     * emission process.
     */
    protected onInstallationUpdateRemoveActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _unrecognized_ event.
     *
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _unrecognized_ handlers and then continue the event
     * emission process.
     */
    protected onUnrecognizedActivity(_context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _members added_ event,
     * a sub-type of the _conversation update_ event.
     *
     * @param _membersAdded An array of the members added to the conversation.
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _members added_ handlers and then continue the event
     * emission process.
     */
    protected onMembersAddedActivity(_membersAdded: ChannelAccount[], _context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _members removed_ event,
     * a sub-type of the _conversation update_ event.
     *
     * @param _membersRemoved An array of the members removed from the conversation.
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _members removed_ handlers and then continue the event
     * emission process.
     */
    protected onMembersRemovedActivity(_membersRemoved: ChannelAccount[], _context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _reactions added_ event,
     * a sub-type of the _message reaction_ event.
     *
     * @param _reactionsAdded An array of the reactions added to a message.
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _reactions added_ handlers and then continue the event
     * emission process.
     */
    protected onReactionsAddedActivity(_reactionsAdded: MessageReaction[], _context: TurnContext): Promise<void>;
    /**
     * Provides a hook for emitting the _reactions removed_ event,
     * a sub-type of the _message reaction_ event.
     *
     * @param _reactionsRemoved An array of the reactions removed from a message.
     * @param _context The context object for the current turn.
     * @remarks
     * Override this method to run registered _reactions removed_ handlers and then continue the event
     * emission process.
     */
    protected onReactionsRemovedActivity(_reactionsRemoved: MessageReaction[], _context: TurnContext): Promise<void>;
    /**
     * Invoked when a command activity is received when the base behavior of
     * `onTurn()` is used.
     * Commands are requests to perform an action and receivers typically respond with
     * one or more commandResult activities. Receivers are also expected to explicitly
     * reject unsupported command activities.
     *
     * @param _context A context object for this turn.
     * @returns A promise that represents the work queued to execute.
     */
    protected onCommandActivity(_context: TurnContext): Promise<void>;
    /**
     * Invoked when a commandResult activity is received when the base behavior of
     * `onTurn()` is used.
     * CommandResult activity can be used to communicate the result of a command execution.
     *
     * @param _context A context object for this turn.
     * @returns A promise that represents the work queued to execute.
     */
    protected onCommandResultActivity(_context: TurnContext): Promise<void>;
    /**
     * Called to initiate the event emission process.
     *
     * @param context The context object for the current turn.
     * @remarks
     * Typically, you would provide this method as the function handler that the adapter calls
     * to perform the bot's logic after the received activity has been pre-processed by the adapter
     * and routed through any middleware.
     *
     * For example:
     * ```javascript
     *  server.post('/api/messages', (req, res) => {
     *      adapter.processActivity(req, res, async (context) => {
     *          // Route to main dialog.
     *          await bot.run(context);
     *      });
     * });
     * ```
     *
     * **See also**
     * - [BotFrameworkAdapter.processActivity](xref:botbuilder.BotFrameworkAdapter.processActivity)
     */
    run(context: TurnContext): Promise<void>;
}
//# sourceMappingURL=activityHandlerBase.d.ts.map