Table of Contents

Class OpenClawRoutingService

Namespace
JD.AI.Channels.OpenClaw.Routing
Assembly
JD.AI.Channels.OpenClaw.dll

Hosted service that connects the OpenClaw bridge and routes incoming messages to JD.AI agents based on per-channel routing configuration.

OpenClaw broadcasts two event types to WebSocket clients:

  • "agent" — lifecycle, assistant, tool events (has stream and sessionKey)
  • "chat" — chat deltas and finals (has state, sessionKey)

User input is NOT broadcast as a WebSocket event. To detect user messages, we watch for agent lifecycle "start" events and query chat.history for the session.

public sealed class OpenClawRoutingService : BackgroundService, IHostedService, IDisposable
Inheritance
OpenClawRoutingService
Implements
Inherited Members

Constructors

OpenClawRoutingService(OpenClawBridgeChannel, IOptions<OpenClawRoutingConfig>, IEnumerable<IOpenClawModeHandler>, Func<string, string, Task<string?>>, ILogger<OpenClawRoutingService>, ICommandRegistry?)

public OpenClawRoutingService(OpenClawBridgeChannel bridge, IOptions<OpenClawRoutingConfig> routingConfig, IEnumerable<IOpenClawModeHandler> handlers, Func<string, string, Task<string?>> messageProcessor, ILogger<OpenClawRoutingService> logger, ICommandRegistry? commandRegistry = null)

Parameters

bridge OpenClawBridgeChannel
routingConfig IOptions<OpenClawRoutingConfig>
handlers IEnumerable<IOpenClawModeHandler>
messageProcessor Func<string, string, Task<string>>
logger ILogger<OpenClawRoutingService>
commandRegistry ICommandRegistry

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.

GetRecentEvents()

Gets recent events for diagnostic inspection.

public IReadOnlyList<(DateTimeOffset Time, string EventName, string Summary)> GetRecentEvents()

Returns

IReadOnlyList<(DateTimeOffset Time, string EventName, string Summary)>

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

public override Task StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the shutdown process should no longer be graceful.

Returns

Task

A Task that represents the asynchronous Stop operation.