mirror of https://github.com/openclaw/openclaw.git
fix: honor slack default pairing account
This commit is contained in:
parent
2a13508379
commit
299ed8cb39
|
|
@ -10,6 +10,9 @@ import { clearSlackRuntime, setSlackRuntime } from "./runtime.js";
|
|||
const { handleSlackActionMock } = vi.hoisted(() => ({
|
||||
handleSlackActionMock: vi.fn(),
|
||||
}));
|
||||
const { sendMessageSlackMock } = vi.hoisted(() => ({
|
||||
sendMessageSlackMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./action-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./action-runtime.js")>("./action-runtime.js");
|
||||
|
|
@ -19,8 +22,14 @@ vi.mock("./action-runtime.js", async () => {
|
|||
};
|
||||
});
|
||||
|
||||
vi.mock("./send.runtime.js", () => ({
|
||||
sendMessageSlack: sendMessageSlackMock,
|
||||
}));
|
||||
|
||||
beforeEach(async () => {
|
||||
handleSlackActionMock.mockReset();
|
||||
sendMessageSlackMock.mockReset();
|
||||
sendMessageSlackMock.mockResolvedValue({ messageId: "msg-1", channelId: "D123" });
|
||||
setSlackRuntime({
|
||||
channel: {
|
||||
slack: {
|
||||
|
|
@ -180,6 +189,41 @@ describe("slackPlugin actions", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("uses configured defaultAccount for pairing approval notifications", async () => {
|
||||
setSlackRuntime({
|
||||
config: {
|
||||
loadConfig: () =>
|
||||
({
|
||||
channels: {
|
||||
slack: {
|
||||
defaultAccount: "work",
|
||||
accounts: {
|
||||
work: {
|
||||
botToken: "xoxb-work",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}) as OpenClawConfig,
|
||||
},
|
||||
} as never);
|
||||
|
||||
const notify = slackPlugin.pairing?.notifyApproval;
|
||||
if (!notify) {
|
||||
throw new Error("slack pairing notify unavailable");
|
||||
}
|
||||
|
||||
await notify({
|
||||
id: "U12345678",
|
||||
message: "approved",
|
||||
});
|
||||
|
||||
expect(sendMessageSlackMock).toHaveBeenCalledWith(
|
||||
"user:U12345678",
|
||||
expect.stringContaining("approved"),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps blocks optional in the message tool schema", () => {
|
||||
const discovery = slackPlugin.actions?.describeMessageTool({
|
||||
cfg: {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import {
|
|||
} from "openclaw/plugin-sdk/status-helpers";
|
||||
import {
|
||||
listEnabledSlackAccounts,
|
||||
resolveDefaultSlackAccountId,
|
||||
resolveSlackAccount,
|
||||
resolveSlackReplyToMode,
|
||||
type ResolvedSlackAccount,
|
||||
|
|
@ -489,7 +490,7 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
|
|||
const cfg = getSlackRuntime().config.loadConfig();
|
||||
const account = resolveSlackAccount({
|
||||
cfg,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
accountId: resolveDefaultSlackAccountId(cfg),
|
||||
});
|
||||
const { sendMessageSlack } = await loadSlackSendRuntime();
|
||||
const token = getTokenForOperation(account, "write");
|
||||
|
|
|
|||
Loading…
Reference in New Issue