Class MessageRouter

java.lang.Object
com.tnsai.channels.routing.MessageRouter
All Implemented Interfaces:
ChannelContext

public class MessageRouter extends Object implements 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.

  • Constructor Details

  • Method Details

    • setMessageHandler

      public void setMessageHandler(BiConsumer<UnifiedMessage,MessageRouter.ResponseCallback> handler)
      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

      public void onMessage(UnifiedMessage message)
      Description copied from interface: ChannelContext
      Called when a message arrives from the channel.
      Specified by:
      onMessage in interface ChannelContext
      Parameters:
      message - the platform-agnostic inbound message
    • onTyping

      public void onTyping(String conversationId)
      Description copied from interface: ChannelContext
      Called when the remote user starts typing.
      Specified by:
      onTyping in interface ChannelContext
      Parameters:
      conversationId - the conversation where typing is happening
    • onError

      public void onError(ChannelError error)
      Description copied from interface: ChannelContext
      Called when the adapter encounters an error.
      Specified by:
      onError in interface ChannelContext
      Parameters:
      error - details about what went wrong
    • sendProactive

      public void sendProactive(String channelId, String conversationId, String text)
      Sends a proactive message to a specific channel and conversation.
    • getSessions

      public SessionRegistry getSessions()