@@ -34,7 +34,10 @@ import {
|
34 | 34 | } from "../../infra/outbound/channel-target-prefix.js"; |
35 | 35 | import { isSubagentSessionKey } from "../../routing/session-key.js"; |
36 | 36 | import { parseAgentSessionKey } from "../../sessions/session-key-utils.js"; |
37 | | -import { normalizeMessageChannel } from "../../utils/message-channel.js"; |
| 37 | +import { |
| 38 | +isDeliverableMessageChannel, |
| 39 | +normalizeMessageChannel, |
| 40 | +} from "../../utils/message-channel.js"; |
38 | 41 | import type { GatewayRequestHandlers, RespondFn } from "./types.js"; |
39 | 42 | |
40 | 43 | type CronJobIdParams = { id?: string; jobId?: string }; |
@@ -67,6 +70,22 @@ async function listConfiguredAnnounceChannelIds(cfg: OpenClawConfig): Promise<st
|
67 | 70 | return await listConfiguredMessageChannels(cfg); |
68 | 71 | } |
69 | 72 | |
| 73 | +function hasExplicitChannelConfigEntry(cfg: OpenClawConfig): boolean { |
| 74 | +const channels = cfg.channels; |
| 75 | +if (!channels || typeof channels !== "object" || Array.isArray(channels)) { |
| 76 | +return false; |
| 77 | +} |
| 78 | +return Object.entries(channels).some(([channelId, entry]) => { |
| 79 | +if (channelId === "defaults" || channelId === "modelByChannel") { |
| 80 | +return false; |
| 81 | +} |
| 82 | +if (!entry || typeof entry !== "object" || Array.isArray(entry)) { |
| 83 | +return false; |
| 84 | +} |
| 85 | +return Object.keys(entry).length > 0; |
| 86 | +}); |
| 87 | +} |
| 88 | + |
70 | 89 | async function assertConfiguredAnnounceChannel(params: { |
71 | 90 | cfg: OpenClawConfig; |
72 | 91 | channel?: string; |
@@ -90,6 +109,12 @@ async function assertConfiguredAnnounceChannel(params: {
|
90 | 109 | } |
91 | 110 | |
92 | 111 | if (configuredChannels.length === 0) { |
| 112 | +if (!hasExplicitChannelConfigEntry(params.cfg)) { |
| 113 | +if (!isDeliverableMessageChannel(normalizedChannel)) { |
| 114 | +throw new Error(`${params.field} is not a known channel: ${normalizedChannel}`); |
| 115 | +} |
| 116 | +return; |
| 117 | +} |
93 | 118 | throw new Error(`${params.field} is not configured: ${normalizedChannel}`); |
94 | 119 | } |
95 | 120 | |
|