Class DiscordChannel
- All Implemented Interfaces:
ChannelAdapter
Inbound: opens a Discord Gateway v10 WebSocket. The lifecycle is:
GET /gateway/bot→ obtain the WSS URL.- Connect WSS with
?v=10&encoding=json. - Receive
op=10 HELLOcarryingheartbeat_interval. - Schedule
op=1 HEARTBEATat that interval (with the last observedssequence number). - Send
op=2 IDENTIFYonce with the bot token and the intents bitfield fromDiscordChannelConfig. - Receive
op=0 t=READY→ capture the bot's user_id so we can filter own echoes. - Receive
op=0 t=MESSAGE_CREATE→ convert payload intoUnifiedMessageand deliver viaChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage).
Outbound: each UnifiedResponse becomes a
POST /channels/{channel_id}/messages call carrying
content (and message_reference when the response
targets a specific reply).
v1 deliberately scopes out three Discord features the issue lists:
slash commands (requires POST /applications/{id}/commands
registration + handling INTERACTION_CREATE — defer until
there is a structured slash-command contract), embeds for rich
tool output (UnifiedResponse only carries text + attachments today —
add when the SPI grows an embed-shape), and streaming via message
edits (PATCH /channels/{id}/messages/{id}, gated by
Discord's edit ratelimit — defer to a streaming-aware follow-up).
Thread safety: send(com.tnsai.channels.api.UnifiedResponse) can be called from any agent thread
concurrently with the WebSocket callback and the heartbeater. The
adapter holds only volatile/atomic state and an immutable HTTP client,
so there is no mutable adapter state to guard.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — bootstraps fromDiscordChannelConfig.fromEnvironment().DiscordChannel(DiscordChannelConfig config) Programmatic constructor — used by the factory. -
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
-
DiscordChannel
public DiscordChannel()Default constructor — bootstraps fromDiscordChannelConfig.fromEnvironment(). -
DiscordChannel
Programmatic constructor — used by the factory.
-
-
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
-