fix: honor discord default action runtime account

This commit is contained in:
Tak Hoffman 2026-04-03 14:08:28 -05:00
parent 0bbacca828
commit c7554d3072
No known key found for this signature in database
2 changed files with 32 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
import { resolveDefaultDiscordAccountId } from "../accounts.js";
import { createDiscordRuntimeAccountContext } from "../client.js";
import { readDiscordComponentSpec } from "../components.js";
import {
@ -112,7 +113,7 @@ export async function handleDiscordMessagingAction(
const reactionRuntimeOptions = cfg
? createDiscordRuntimeAccountContext({
cfg,
accountId: accountId ?? "default",
accountId: accountId ?? resolveDefaultDiscordAccountId(cfg),
})
: accountId
? { accountId }

View File

@ -131,6 +131,36 @@ describe("handleDiscordMessagingAction", () => {
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", {});
});
it("uses configured defaultAccount when cfg is provided and accountId is omitted", async () => {
await handleDiscordMessagingAction(
"react",
{
channelId: "C1",
messageId: "M1",
emoji: "✅",
},
enableAllActions,
undefined,
{
channels: {
discord: {
defaultAccount: "work",
accounts: {
work: { token: "token-work" },
},
},
},
} as OpenClawConfig,
);
expect(reactMessageDiscord).toHaveBeenCalledWith(
"C1",
"M1",
"✅",
expect.objectContaining({ accountId: "work" }),
);
});
it("removes reactions on empty emoji", async () => {
await handleDiscordMessagingAction(
"react",