Slack: reject blocks plus media in send paths

This commit is contained in:
Colin
2026-02-16 12:33:43 -05:00
committed by Peter Steinberger
parent 10d876e319
commit c943ffab7c
4 changed files with 41 additions and 0 deletions

View File

@@ -221,6 +221,21 @@ describe("handleSlackAction", () => {
).rejects.toThrow(/requires content, blocks, or mediaUrl/i);
});
it("rejects blocks combined with mediaUrl", async () => {
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
await expect(
handleSlackAction(
{
action: "sendMessage",
to: "channel:C123",
blocks: [{ type: "divider" }],
mediaUrl: "https://example.com/image.png",
},
cfg,
),
).rejects.toThrow(/does not support blocks with mediaUrl/i);
});
it("passes blocks JSON to editSlackMessage with empty content", async () => {
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
editSlackMessage.mockClear();

View File

@@ -185,6 +185,9 @@ export async function handleSlackAction(
if (!content && !mediaUrl && !blocks) {
throw new Error("Slack sendMessage requires content, blocks, or mediaUrl.");
}
if (mediaUrl && blocks) {
throw new Error("Slack sendMessage does not support blocks with mediaUrl.");
}
const threadTs = resolveThreadTsFromContext(
readStringParam(params, "threadTs"),
to,

View File

@@ -613,6 +613,26 @@ describe("slack actions adapter", () => {
expect(handleSlackAction).not.toHaveBeenCalled();
});
it("rejects send when both blocks and media are provided", async () => {
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
const actions = createSlackActions("slack");
await expect(
actions.handleAction?.({
channel: "slack",
action: "send",
cfg,
params: {
to: "channel:C1",
message: "",
media: "https://example.com/image.png",
blocks: JSON.stringify([{ type: "divider" }]),
},
}),
).rejects.toThrow(/does not support blocks with media/i);
expect(handleSlackAction).not.toHaveBeenCalled();
});
it("forwards blocks JSON for edit", async () => {
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
const actions = createSlackActions("slack");

View File

@@ -41,6 +41,9 @@ export async function handleSlackMessageAction(params: {
if (!content && !mediaUrl && !blocks) {
throw new Error("Slack send requires message, blocks, or media.");
}
if (mediaUrl && blocks) {
throw new Error("Slack send does not support blocks with media.");
}
const threadId = readStringParam(actionParams, "threadId");
const replyTo = readStringParam(actionParams, "replyTo");
return await invoke(