Skip to content

CommandRouter

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:19

Routes slash commands and unmatched text to agent handlers.

ContentTypes = unknown

new CommandRouter<ContentTypes>(config?): CommandRouter<ContentTypes>

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:24

Create a router. A help command is registered when configured.

CommandRouterConfig = {}

CommandRouter<ContentTypes>

get commandList(): string[]

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:53

Return registered commands in insertion order.

string[]

Register the command using the normalized handler arguments.

command(command, handler): this

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:58

Register a slash command. Commands are matched case-insensitively.

string

AgentMessageHandler<string>

this

command(command, description, handler): this

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:60

Register a command with a description shown by the help command.

string

string

AgentMessageHandler<string>

this


default(handler): this

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:98

Register the handler for text that does not match a command.

AgentMessageHandler<string>

this


handle(ctx): Promise<boolean>

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:104

Handle one text context and return whether a handler ran.

MessageContext<string>

Promise<boolean>


middleware(): AgentMiddleware<ContentTypes>

Defined in: sdks/js/agent-sdk/src/middleware/CommandRouter.ts:135

Return middleware that routes text messages to registered handlers.

AgentMiddleware<ContentTypes>