mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 16:21:26 +00:00
fix(routing): preserve explicit cron account and bound message defaults
Co-authored-by: lbo728 <72309817+lbo728@users.noreply.github.com> Co-authored-by: stakeswky <64798754+stakeswky@users.noreply.github.com>
This commit is contained in:
@@ -1021,4 +1021,32 @@ describe("runMessageAction accountId defaults", () => {
|
||||
expect(ctx.accountId).toBe("ops");
|
||||
expect(ctx.params.accountId).toBe("ops");
|
||||
});
|
||||
|
||||
it("falls back to the agent's bound account when accountId is omitted", async () => {
|
||||
await runMessageAction({
|
||||
cfg: {
|
||||
bindings: [{ agentId: "agent-b", match: { channel: "discord", accountId: "account-b" } }],
|
||||
} as OpenClawConfig,
|
||||
action: "send",
|
||||
params: {
|
||||
channel: "discord",
|
||||
target: "channel:123",
|
||||
message: "hi",
|
||||
},
|
||||
agentId: "agent-b",
|
||||
});
|
||||
|
||||
expect(handleAction).toHaveBeenCalled();
|
||||
const ctx = (handleAction.mock.calls as unknown as Array<[unknown]>)[0]?.[0] as
|
||||
| {
|
||||
accountId?: string | null;
|
||||
params: Record<string, unknown>;
|
||||
}
|
||||
| undefined;
|
||||
if (!ctx) {
|
||||
throw new Error("expected action context");
|
||||
}
|
||||
expect(ctx.accountId).toBe("account-b");
|
||||
expect(ctx.params.accountId).toBe("account-b");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,6 +14,8 @@ import type {
|
||||
} from "../../channels/plugins/types.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { getAgentScopedMediaLocalRoots } from "../../media/local-roots.js";
|
||||
import { buildChannelAccountBindings } from "../../routing/bindings.js";
|
||||
import { normalizeAgentId } from "../../routing/session-key.js";
|
||||
import {
|
||||
isDeliverableMessageChannel,
|
||||
normalizeMessageChannel,
|
||||
@@ -753,7 +755,14 @@ export async function runMessageAction(
|
||||
}
|
||||
|
||||
const channel = await resolveChannel(cfg, params);
|
||||
const accountId = readStringParam(params, "accountId") ?? input.defaultAccountId;
|
||||
let accountId = readStringParam(params, "accountId") ?? input.defaultAccountId;
|
||||
if (!accountId && resolvedAgentId) {
|
||||
const byAgent = buildChannelAccountBindings(cfg).get(channel);
|
||||
const boundAccountIds = byAgent?.get(normalizeAgentId(resolvedAgentId));
|
||||
if (boundAccountIds && boundAccountIds.length > 0) {
|
||||
accountId = boundAccountIds[0];
|
||||
}
|
||||
}
|
||||
if (accountId) {
|
||||
params.accountId = accountId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user