Class SlackChannel
- All Implemented Interfaces:
ChannelAdapter
Inbound: opens a WebSocket via Slack's Socket Mode protocol. The
adapter calls POST /apps.connections.open with the
xapp-... app token to obtain a WSS URL, then connects and
listens for events_api envelopes. Every envelope is
immediately acked with the matching envelope_id, and the
message sub-events are converted into UnifiedMessage
before being delivered via ChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage).
Outbound: each UnifiedResponse becomes a
POST /chat.postMessage call with the xoxb-... bot
token in the Authorization header. The Slack
conversationId (channel ID) is sent as the channel
field; the optional thread_ts field is populated when the
original message's metadata identified a thread root, keeping replies
threaded.
Why Socket Mode and not the Events API webhook (deviation from the
TNS-350 spec): the framework deliberately has no embedded HTTP server
in tnsai-channels; every existing adapter pulls from its
platform rather than accepting inbound HTTP. Socket Mode keeps that
invariant intact and means the agent can run behind NAT without exposing
a public URL — a hard requirement for a homelab deployment topology.
See SlackChannelConfig for the detailed rationale.
Thread safety: send(com.tnsai.channels.api.UnifiedResponse) can be invoked from any agent thread
concurrently with the inbound WebSocket callback; both routes share
the immutable config and a single OkHttp client instance, so there's
no mutable adapter state to guard.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — bootstraps fromSlackChannelConfig.fromEnvironment().SlackChannel(SlackChannelConfig config) Programmatic constructor — used by the factory and tests. -
Method Summary
Modifier and TypeMethodDescriptionDeclares what this channel supports.Human-readable display name.id()Unique identifier for this channel (e.g.booleanWhether the adapter is currently connected and operational.voidsend(UnifiedResponse response) Send a response back through this channel.voidstart(ChannelContext context) Start listening for inbound messages.voidstop()Stop listening and release resources.
-
Constructor Details
-
SlackChannel
public SlackChannel()Default constructor — bootstraps fromSlackChannelConfig.fromEnvironment(). -
SlackChannel
Programmatic constructor — used by the factory and tests.
-
-
Method Details
-
id
Description copied from interface:ChannelAdapterUnique identifier for this channel (e.g. "telegram", "discord", "slack").- Specified by:
idin interfaceChannelAdapter
-
displayName
Description copied from interface:ChannelAdapterHuman-readable display name.- Specified by:
displayNamein interfaceChannelAdapter
-
capabilities
Description copied from interface:ChannelAdapterDeclares what this channel supports.- Specified by:
capabilitiesin interfaceChannelAdapter
-
start
Description copied from interface:ChannelAdapterStart listening for inbound messages. The adapter should callChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage)when a message arrives.- Specified by:
startin interfaceChannelAdapter- Parameters:
context- callback interface for delivering events to the gateway
-
stop
public void stop()Description copied from interface:ChannelAdapterStop listening and release resources.- Specified by:
stopin interfaceChannelAdapter
-
isRunning
public boolean isRunning()Description copied from interface:ChannelAdapterWhether the adapter is currently connected and operational.- Specified by:
isRunningin interfaceChannelAdapter
-
send
Description copied from interface:ChannelAdapterSend a response back through this channel.- Specified by:
sendin interfaceChannelAdapter- Parameters:
response- the unified response to deliver
-