Documentation - v1.6.0-beta.24
    Preparing search index...

    Channel extension that adds Slack-specific routing and API access to an AgentApplication.

    Register via app.registerExtension(new SlackAgentExtension(app), ext => { ... }).

    On each turn with channelId === 'slack', a beforeTurn hook resolves the bot token from activity.channelData.ApiToken (injected by Azure Bot Service) or the SLACK_TOKEN environment variable, and stores a SlackApi client in context.turnState under SlackApiKey.

    Type Parameters

    • TState extends TurnState = TurnState

      The turn state type used by the application.

    Hierarchy

    • AgentExtension<TState>
      • SlackAgentExtension
    Index

    Constructors

    • Creates a new SlackAgentExtension and registers the before-turn token injection hook.

      Type Parameters

      • TState extends TurnState<DefaultConversationState, DefaultUserState> = TurnState<DefaultConversationState, DefaultUserState>

        The turn state type used by the application.

      Parameters

      • app: AgentApplication<TState>

        The agent application to attach to.

      Returns SlackAgentExtension<TState>

    Properties

    channelId: string

    The channel ID that this extension is associated with

    Methods

    • Adds a route to the agent application that is only active for the channel specified in this extension. This method creates a channel-specific route by wrapping the provided route selector with an additional check to ensure the incoming activity matches the extension's channel ID.

      Parameters

      • app: AgentApplication<TState>

        The agent application instance to add the route to

      • routeSelector: Selector

        A function that determines if the route should handle the incoming activity

      • routeHandler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState>>

        The handler function that will process the activity when the route is matched

      • OptionalisInvokeRoute: boolean

        Optional. Whether this route handles invoke activities. Defaults to false

      • Optionalrank: number

        Optional. The priority rank of this route for routing precedence. Defaults to RouteRank.Unspecified

      Returns void

      const teamsExtension = new AgentExtension<MyState>('msteams');
      teamsExtension.addRoute(
      app,
      (context) => context.activity.type === 'message',
      async (context, state) => {
      // Handle Teams-specific message
      await context.sendActivity('Hello from Teams!');
      }
      );
    • Registers a route that handles Slack events of a specific type (e.g. 'block_actions'). Matches on the type field of the Slack event envelope or its inner event object.

      Parameters

      • eventType: string

        The Slack event type to match.

      • handler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState>>

        Handler to invoke when the event type matches.

      Returns this

      The extension instance, for chaining.

    • Registers a route that handles all incoming Slack message activities.

      Parameters

      • handler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState>>

        Handler to invoke for every Slack message.

      Returns this

      The extension instance, for chaining.

    • Registers a route that handles Slack message activities whose text equals text.

      Parameters

      • text: string

        Exact text to match against activity.text.

      • handler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState>>

        Handler to invoke on match.

      Returns this

      The extension instance, for chaining.

    • Registers a route that handles Slack message activities whose text matches regex.

      Parameters

      • regex: RegExp

        Regular expression to test against activity.text.

      • handler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState>>

        Handler to invoke on match.

      Returns this

      The extension instance, for chaining.