Table of Contents

Class SlackChannel

Namespace
JD.AI.Channels.Slack
Assembly
JD.AI.Channels.Slack.dll

Slack channel adapter using SlackNet Socket Mode. Supports native slash command handling via ICommandAwareChannel.

public sealed class SlackChannel : IChannel, IAsyncDisposable, ICommandAwareChannel
Inheritance
SlackChannel
Implements
Inherited Members

Constructors

SlackChannel(string, string)

public SlackChannel(string botToken, string appToken)

Parameters

botToken string
appToken string

Fields

CommandPrefix

Prefix for Slack slash commands (e.g., "/jdai-help").

public const string CommandPrefix = "/jdai-"

Field Value

string

Properties

ChannelType

Unique channel type identifier (e.g., "discord", "signal", "web").

public string ChannelType { get; }

Property Value

string

DisplayName

Display name for this channel instance.

public string DisplayName { get; }

Property Value

string

IsConnected

Whether the channel is currently connected and healthy.

public bool IsConnected { get; }

Property Value

bool

Methods

ConnectAsync(CancellationToken)

Connects to the messaging platform.

public Task ConnectAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

DisconnectAsync(CancellationToken)

Gracefully disconnects.

public Task DisconnectAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

HandleMessageAsync(MessageEvent)

Process an incoming Slack event (called by event handler registration).

public Task HandleMessageAsync(MessageEvent slackEvent)

Parameters

slackEvent MessageEvent

Returns

Task

HandleSlashCommandAsync(string, string, string, string)

Handles a Slack slash command payload. Called by the gateway when a /jdai-* command is received from Slack's API.

public Task<string> HandleSlashCommandAsync(string commandName, string text, string userId, string channelId)

Parameters

commandName string

The command name without slash (e.g., "jdai-help").

text string

The text after the command.

userId string

Slack user ID.

channelId string

Slack channel ID.

Returns

Task<string>

Response text to send back to Slack.

RegisterCommandsAsync(ICommandRegistry, CancellationToken)

Registers commands from the registry as platform-native commands. Called after ConnectAsync when commands are available.

public Task RegisterCommandsAsync(ICommandRegistry registry, CancellationToken ct = default)

Parameters

registry ICommandRegistry
ct CancellationToken

Returns

Task

SendMessageAsync(string, string, CancellationToken)

Sends a message to the specified conversation/thread.

public Task SendMessageAsync(string conversationId, string content, CancellationToken ct = default)

Parameters

conversationId string
content string
ct CancellationToken

Returns

Task

Events

MessageReceived

Raised when a new inbound message arrives.

public event Func<ChannelMessage, Task>? MessageReceived

Event Type

Func<ChannelMessage, Task>

Remarks

Uses Func<ChannelMessage, Task> instead of EventHandler to support async handlers.