Skip to main content

Class: ChannelRouter

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:89

Central routing hub for all external messaging channels.

Example​

const router = new ChannelRouter();

// Register adapters
router.registerAdapter(telegramAdapter);
router.registerAdapter(discordAdapter);

// Add bindings
router.addBinding({
bindingId: 'b1',
seedId: 'cipher-001',
ownerUserId: 'user-1',
platform: 'telegram',
channelId: '123456789',
conversationType: 'direct',
isActive: true,
autoBroadcast: false,
});

// Handle inbound messages
router.onMessage(async (message, binding, session) => {
// Route to StimulusRouter or agent runtime
await stimulusRouter.ingestChannelMessage(message, binding.seedId);
});

// Send outbound message
await router.sendMessage('cipher-001', 'telegram', '123456789', {
blocks: [{ type: 'text', text: 'Hello from Cipher!' }],
});

Constructors​

Constructor​

new ChannelRouter(): ChannelRouter

Returns​

ChannelRouter

Methods​

addBinding()​

addBinding(binding): void

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:180

Add or update a channel binding.

Parameters​

binding​

ChannelBindingConfig

Returns​

void


broadcast()​

broadcast(seedId, content): Promise<ChannelSendResult[]>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:255

Broadcast a message from an agent to all auto-broadcast bindings.

Parameters​

seedId​

string

content​

MessageContent

Returns​

Promise<ChannelSendResult[]>


getAdapter()​

getAdapter(platform): IChannelAdapter | undefined

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:152

Get a registered adapter by platform.

Parameters​

platform​

string

Returns​

IChannelAdapter | undefined


getBindingsForConversation()​

getBindingsForConversation(platform, conversationId): ChannelBindingConfig[]

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:203

Get all bindings for a platform + conversation.

Parameters​

platform​

ChannelPlatform

conversationId​

string

Returns​

ChannelBindingConfig[]


getBindingsForSeed()​

getBindingsForSeed(seedId): ChannelBindingConfig[]

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:196

Get all bindings for a seed.

Parameters​

seedId​

string

Returns​

ChannelBindingConfig[]


getBroadcastBindings()​

getBroadcastBindings(seedId): ChannelBindingConfig[]

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:214

Get all auto-broadcast bindings for a seed (used when agent publishes a post).

Parameters​

seedId​

string

Returns​

ChannelBindingConfig[]


getOrCreateSession()​

getOrCreateSession(seedId, platform, conversationId): ChannelSession

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:298

Get or create a session for an agent + conversation.

Parameters​

seedId​

string

platform​

ChannelPlatform

conversationId​

string

Returns​

ChannelSession


getSessionsForSeed()​

getSessionsForSeed(seedId): ChannelSession[]

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:326

Get active sessions for a seed.

Parameters​

seedId​

string

Returns​

ChannelSession[]


getStats()​

getStats(): object

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:332

Returns​

object

activeSessions​

activeSessions: number

adapters​

adapters: number

bindings​

bindings: number

totalSessions​

totalSessions: number


listAdapters()​

listAdapters(): ChannelInfo[]

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:159

List all registered adapters with their info.

Returns​

ChannelInfo[]


onMessage()​

onMessage(handler): () => void

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:225

Register a handler for inbound messages. Returns unsubscribe function.

Parameters​

handler​

InboundMessageHandler

Returns​

(): void

Returns​

void


registerAdapter()​

registerAdapter(adapter, options?): void

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:113

Register a channel adapter. The router will subscribe to its events.

Parameters​

adapter​

IChannelAdapter

options?​

RegisterAdapterOptions

Returns​

void


removeBinding()​

removeBinding(bindingId): void

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:188

Remove a channel binding.

Parameters​

bindingId​

string

Returns​

void


routeInboundMessage()​

routeInboundMessage(message): Promise<void>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:368

Internal

Route one inbound message through binding resolution + group policy + handler dispatch. Adapter 'message' events flow through the same path; exposed publicly for hosts and tests that inject messages directly.

Parameters​

message​

ChannelMessage

Returns​

Promise<void>


sendMessage()​

sendMessage(seedId, platform, conversationId, content): Promise<ChannelSendResult>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:233

Send a message from an agent to a specific conversation.

Parameters​

seedId​

string

platform​

ChannelPlatform

conversationId​

string

content​

MessageContent

Returns​

Promise<ChannelSendResult>


sendTypingIndicator()​

sendTypingIndicator(platform, conversationId, isTyping): Promise<void>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:282

Send a typing indicator for an agent on a channel.

Parameters​

platform​

ChannelPlatform

conversationId​

string

isTyping​

boolean

Returns​

Promise<void>


shutdown()​

shutdown(): Promise<void>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:353

Shut down all adapters and clear state.

Returns​

Promise<void>


unregisterAdapter()​

unregisterAdapter(platformKey): Promise<void>

Defined in: packages/agentos/src/io/channels/ChannelRouter.ts:135

Unregister and shut down an adapter.

Parameters​

platformKey​

string

Returns​

Promise<void>