Class OpenClawRoutingService
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 (hasstreamandsessionKey)"chat"— chat deltas and finals (hasstate,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
bridgeOpenClawBridgeChannelroutingConfigIOptions<OpenClawRoutingConfig>handlersIEnumerable<IOpenClawModeHandler>messageProcessorFunc<string, string, Task<string>>loggerILogger<OpenClawRoutingService>commandRegistryICommandRegistry
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
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
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
StopAsync(CancellationToken)
Triggered when the application host is performing a graceful shutdown.
public override Task StopAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenIndicates that the shutdown process should no longer be graceful.