Package com.tnsai.channels.routing
Class MessageRouter
java.lang.Object
com.tnsai.channels.routing.MessageRouter
- All Implemented Interfaces:
ChannelContext
Routes inbound messages from channel adapters to agent sessions
and delivers agent responses back to the originating channel.
This is the central nervous system of TnsAI.Channels — it bridges the channel layer with the agent layer.
The actual agent integration is pluggable via setMessageHandler(java.util.function.BiConsumer<com.tnsai.channels.api.UnifiedMessage, com.tnsai.channels.routing.MessageRouter.ResponseCallback>).
This keeps TnsAI.Channels decoupled from specific agent implementations
while allowing TnsAI.Server to wire in AgentGroup routing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for delivering responses from the agent layer. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonError(ChannelError error) Called when the adapter encounters an error.voidonMessage(UnifiedMessage message) Called when a message arrives from the channel.voidCalled when the remote user starts typing.voidsendProactive(String channelId, String conversationId, String text) Sends a proactive message to a specific channel and conversation.voidSets the handler that processes inbound messages.
-
Constructor Details
-
MessageRouter
-
-
Method Details
-
setMessageHandler
Sets the handler that processes inbound messages. Typically wired by TnsAI.Server to connect to AgentGroup orchestration.- Parameters:
handler- receives the message and a callback for sending responses
-
onMessage
Description copied from interface:ChannelContextCalled when a message arrives from the channel.- Specified by:
onMessagein interfaceChannelContext- Parameters:
message- the platform-agnostic inbound message
-
onTyping
Description copied from interface:ChannelContextCalled when the remote user starts typing.- Specified by:
onTypingin interfaceChannelContext- Parameters:
conversationId- the conversation where typing is happening
-
onError
Description copied from interface:ChannelContextCalled when the adapter encounters an error.- Specified by:
onErrorin interfaceChannelContext- Parameters:
error- details about what went wrong
-
sendProactive
Sends a proactive message to a specific channel and conversation. -
getSessions
-