Documentation - v1.2.0-alpha.3
    Preparing search index...

    Handles incoming activities from channels and dispatches them to the appropriate handlers.

    This class is provided to simplify the migration from Bot Framework SDK v4 to the Agents Hosting framework.

    The ActivityHandler serves as the central hub for processing incoming activities in conversational AI applications. It provides a comprehensive framework for handling various activity types including messages, conversation updates, message reactions, typing indicators, installation updates, and invoke operations such as adaptive cards and search.

    • Activity Routing: Automatically routes activities to appropriate handlers based on activity type
    • Handler Registration: Provides fluent API methods (onMessage, onConversationUpdate, etc.) for registering event handlers
    • Invoke Support: Built-in handling for adaptive card actions and search invoke operations
    • Error Handling: Robust error handling with proper HTTP status codes for invoke operations
    • Extensibility: Designed for inheritance to allow custom behavior and specialized handlers
    const handler = new ActivityHandler()
    .onMessage(async (context, next) => {
    await context.sendActivity('Hello!');
    await next();
    })
    .onMembersAdded(async (context, next) => {
    // Welcome new members
    await next();
    });

    Developers can extend this class to implement domain-specific logic, override default behaviors, or add support for custom activity types and invoke operations.

    Index

    Constructors

    Properties

    handlers: { [type: string]: AgentHandler[] } = {}

    Collection of handlers registered for different activity types

    Methods

    • Protected

      Returns the default next event handler. This method creates a function that calls the default handler.

      Parameters

      • context: TurnContext

        The turn context for the current turn of conversation

      Returns () => Promise<void>

      A function that calls the default handler

    • Protected

      Dispatches the ConversationUpdate activity. This method dispatches conversation update activities to the appropriate handlers.

      Parameters

      • context: TurnContext

        The turn context for the current turn of conversation

      Returns Promise<void>

    • Protected

      Dispatches the MessageReaction activity. This method dispatches message reaction activities to the appropriate handlers.

      Parameters

      • context: TurnContext

        The turn context for the current turn of conversation

      Returns Promise<void>

    • Protected

      Executes the handlers for a specific activity type. This method calls each registered handler for the specified activity type.

      Parameters

      • context: TurnContext

        The turn context for the current turn of conversation

      • type: string

        The activity type to handle

      • onNext: () => Promise<void>

        The function to call when all handlers have been executed

      Returns Promise<any>

      The value returned by the last handler

    • Registers a handler for the ConversationUpdate activity type. This is called when the conversation is updated, such as when members are added or removed.

      Parameters

      Returns this

      The current instance for method chaining

    • Registers an activity event handler for the dialog event, emitted as the last event for an incoming activity. This handler is called after all other handlers have been processed.

      Parameters

      Returns this

      The current instance for method chaining

    • Runs the activity handler pipeline. This method is called to process an incoming activity through the registered handlers.

      Parameters

      • context: TurnContext

        The turn context for the current turn of conversation

      Returns Promise<void>

      Error if context is missing, activity is missing, or activity type is missing