mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:30:47 +00:00
fix(slack): forward media roots for uploads
This commit is contained in:
@@ -19,6 +19,21 @@ async function loadSlackActionRuntime() {
|
||||
return await slackActionRuntimePromise;
|
||||
}
|
||||
|
||||
function resolveSlackActionContext(params: {
|
||||
toolContext: unknown;
|
||||
mediaLocalRoots: readonly string[] | undefined;
|
||||
mediaReadFile: ((filePath: string) => Promise<Buffer>) | undefined;
|
||||
}): SlackActionContext | undefined {
|
||||
if (!params.toolContext && !params.mediaLocalRoots && !params.mediaReadFile) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...(params.toolContext as SlackActionContext | undefined),
|
||||
...(params.mediaLocalRoots ? { mediaLocalRoots: params.mediaLocalRoots } : {}),
|
||||
...(params.mediaReadFile ? { mediaReadFile: params.mediaReadFile } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function createSlackActions(
|
||||
providerId: string,
|
||||
options?: { invoke?: SlackActionInvoke },
|
||||
@@ -32,14 +47,16 @@ export function createSlackActions(
|
||||
ctx,
|
||||
normalizeChannelId: resolveSlackChannelId,
|
||||
includeReadThreadId: true,
|
||||
invoke: async (action, cfg, toolContext) =>
|
||||
await (options?.invoke
|
||||
? options.invoke(action, cfg, toolContext)
|
||||
: (await loadSlackActionRuntime()).handleSlackAction(action, cfg, {
|
||||
...(toolContext as SlackActionContext | undefined),
|
||||
mediaLocalRoots: ctx.mediaLocalRoots,
|
||||
mediaReadFile: ctx.mediaReadFile,
|
||||
})),
|
||||
invoke: async (action, cfg, toolContext) => {
|
||||
const actionContext = resolveSlackActionContext({
|
||||
toolContext,
|
||||
mediaLocalRoots: ctx.mediaLocalRoots,
|
||||
mediaReadFile: ctx.mediaReadFile,
|
||||
});
|
||||
return await (options?.invoke
|
||||
? options.invoke(action, cfg, actionContext)
|
||||
: (await loadSlackActionRuntime()).handleSlackAction(action, cfg, actionContext));
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -283,6 +283,47 @@ describe("slackPlugin actions", () => {
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards media access through the bundled Slack action invoke path", async () => {
|
||||
handleSlackActionMock.mockResolvedValueOnce({ ok: true });
|
||||
const handleAction = requireSlackHandleAction();
|
||||
const mediaLocalRoots = ["/tmp/workspace-agent"];
|
||||
const mediaReadFile = vi.fn(async () => Buffer.from("file"));
|
||||
|
||||
await handleAction({
|
||||
action: "upload-file",
|
||||
channel: "slack",
|
||||
accountId: "default",
|
||||
cfg: {},
|
||||
params: {
|
||||
to: "channel:C123",
|
||||
filePath: "/tmp/workspace-agent/renders/file.wav",
|
||||
initialComment: "render",
|
||||
},
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
toolContext: {
|
||||
currentChannelId: "C123",
|
||||
replyToMode: "all",
|
||||
},
|
||||
} as never);
|
||||
|
||||
expect(handleSlackActionMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: "uploadFile",
|
||||
to: "channel:C123",
|
||||
filePath: "/tmp/workspace-agent/renders/file.wav",
|
||||
initialComment: "render",
|
||||
}),
|
||||
{},
|
||||
expect.objectContaining({
|
||||
currentChannelId: "C123",
|
||||
replyToMode: "all",
|
||||
mediaLocalRoots,
|
||||
mediaReadFile,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("slackPlugin status", () => {
|
||||
|
||||
Reference in New Issue
Block a user