fix(slack): scope download-file to channel and thread context

This commit is contained in:
Peter Steinberger
2026-03-02 02:23:12 +00:00
parent 17bae93680
commit 40fda40aa7
6 changed files with 298 additions and 12 deletions

View File

@@ -216,6 +216,33 @@ describe("handleSlackAction", () => {
);
});
it("passes download scope (channel/thread) to downloadSlackFile", async () => {
downloadSlackFile.mockResolvedValueOnce(null);
const result = await handleSlackAction(
{
action: "downloadFile",
fileId: "F123",
to: "channel:C1",
replyTo: "123.456",
},
slackConfig(),
);
expect(downloadSlackFile).toHaveBeenCalledWith(
"F123",
expect.objectContaining({
channelId: "C1",
threadId: "123.456",
}),
);
expect(result).toEqual(
expect.objectContaining({
details: expect.objectContaining({ ok: false }),
}),
);
});
it.each([
{
name: "JSON blocks",

View File

@@ -290,12 +290,17 @@ export async function handleSlackAction(
}
case "downloadFile": {
const fileId = readStringParam(params, "fileId", { required: true });
const channelTarget = readStringParam(params, "channelId") ?? readStringParam(params, "to");
const channelId = channelTarget ? resolveSlackChannelId(channelTarget) : undefined;
const threadId = readStringParam(params, "threadId") ?? readStringParam(params, "replyTo");
const maxBytes = account.config?.mediaMaxMb
? account.config.mediaMaxMb * 1024 * 1024
: 20 * 1024 * 1024;
const downloaded = await downloadSlackFile(fileId, {
...readOpts,
maxBytes,
channelId,
threadId: threadId ?? undefined,
});
if (!downloaded) {
return jsonResult({