mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:44:32 +00:00
Slack: support Block Kit blocks in editMessage
This commit is contained in:
@@ -207,6 +207,55 @@ describe("handleSlackAction", () => {
|
|||||||
).rejects.toThrow(/requires content, blocks, or mediaUrl/i);
|
).rejects.toThrow(/requires content, blocks, or mediaUrl/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes blocks JSON to editSlackMessage with empty content", async () => {
|
||||||
|
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
|
||||||
|
editSlackMessage.mockClear();
|
||||||
|
await handleSlackAction(
|
||||||
|
{
|
||||||
|
action: "editMessage",
|
||||||
|
channelId: "C123",
|
||||||
|
messageId: "123.456",
|
||||||
|
blocks: JSON.stringify([{ type: "section", text: { type: "mrkdwn", text: "Updated" } }]),
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
);
|
||||||
|
expect(editSlackMessage).toHaveBeenCalledWith("C123", "123.456", "", {
|
||||||
|
blocks: [{ type: "section", text: { type: "mrkdwn", text: "Updated" } }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes blocks arrays to editSlackMessage", async () => {
|
||||||
|
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
|
||||||
|
editSlackMessage.mockClear();
|
||||||
|
await handleSlackAction(
|
||||||
|
{
|
||||||
|
action: "editMessage",
|
||||||
|
channelId: "C123",
|
||||||
|
messageId: "123.456",
|
||||||
|
blocks: [{ type: "divider" }],
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
);
|
||||||
|
expect(editSlackMessage).toHaveBeenCalledWith("C123", "123.456", "", {
|
||||||
|
blocks: [{ type: "divider" }],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("requires content or blocks for editMessage", async () => {
|
||||||
|
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
|
||||||
|
await expect(
|
||||||
|
handleSlackAction(
|
||||||
|
{
|
||||||
|
action: "editMessage",
|
||||||
|
channelId: "C123",
|
||||||
|
messageId: "123.456",
|
||||||
|
content: "",
|
||||||
|
},
|
||||||
|
cfg,
|
||||||
|
),
|
||||||
|
).rejects.toThrow(/requires content or blocks/i);
|
||||||
|
});
|
||||||
|
|
||||||
it("auto-injects threadTs from context when replyToMode=all", async () => {
|
it("auto-injects threadTs from context when replyToMode=all", async () => {
|
||||||
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
|
const cfg = { channels: { slack: { botToken: "tok" } } } as OpenClawConfig;
|
||||||
sendSlackMessage.mockClear();
|
sendSlackMessage.mockClear();
|
||||||
|
|||||||
@@ -231,13 +231,18 @@ export async function handleSlackAction(
|
|||||||
const messageId = readStringParam(params, "messageId", {
|
const messageId = readStringParam(params, "messageId", {
|
||||||
required: true,
|
required: true,
|
||||||
});
|
});
|
||||||
const content = readStringParam(params, "content", {
|
const content = readStringParam(params, "content", { allowEmpty: true });
|
||||||
required: true,
|
const blocks = readSlackBlocksParam(params);
|
||||||
});
|
if (!content && !blocks) {
|
||||||
|
throw new Error("Slack editMessage requires content or blocks.");
|
||||||
|
}
|
||||||
if (writeOpts) {
|
if (writeOpts) {
|
||||||
await editSlackMessage(channelId, messageId, content, writeOpts);
|
await editSlackMessage(channelId, messageId, content ?? "", {
|
||||||
|
...writeOpts,
|
||||||
|
blocks,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await editSlackMessage(channelId, messageId, content);
|
await editSlackMessage(channelId, messageId, content ?? "", { blocks });
|
||||||
}
|
}
|
||||||
return jsonResult({ ok: true });
|
return jsonResult({ ok: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,13 +167,14 @@ export async function editSlackMessage(
|
|||||||
channelId: string,
|
channelId: string,
|
||||||
messageId: string,
|
messageId: string,
|
||||||
content: string,
|
content: string,
|
||||||
opts: SlackActionClientOpts = {},
|
opts: SlackActionClientOpts & { blocks?: (Block | KnownBlock)[] } = {},
|
||||||
) {
|
) {
|
||||||
const client = await getClient(opts);
|
const client = await getClient(opts);
|
||||||
await client.chat.update({
|
await client.chat.update({
|
||||||
channel: channelId,
|
channel: channelId,
|
||||||
ts: messageId,
|
ts: messageId,
|
||||||
text: content,
|
text: content || " ",
|
||||||
|
...(opts.blocks?.length ? { blocks: opts.blocks } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user