Slack: add media block fallback text handling

This commit is contained in:
Colin
2026-02-16 14:02:27 -05:00
committed by Peter Steinberger
parent 7aaf1547df
commit ce973332f6
6 changed files with 243 additions and 4 deletions

View File

@@ -43,13 +43,66 @@ describe("sendMessageSlack blocks", () => {
expect(client.chat.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
channel: "C123",
text: " ",
text: "Shared a Block Kit message",
blocks: [{ type: "divider" }],
}),
);
expect(result).toEqual({ messageId: "171234.567", channelId: "C123" });
});
it("derives fallback text from image blocks", async () => {
const client = createClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
blocks: [{ type: "image", image_url: "https://example.com/a.png", alt_text: "Build chart" }],
});
expect(client.chat.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
text: "Build chart",
}),
);
});
it("derives fallback text from video blocks", async () => {
const client = createClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
blocks: [
{
type: "video",
title: { type: "plain_text", text: "Release demo" },
video_url: "https://example.com/demo.mp4",
thumbnail_url: "https://example.com/thumb.jpg",
alt_text: "demo",
},
],
});
expect(client.chat.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
text: "Release demo",
}),
);
});
it("derives fallback text from file blocks", async () => {
const client = createClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
blocks: [{ type: "file", source: "remote", external_id: "F123" }],
});
expect(client.chat.postMessage).toHaveBeenCalledWith(
expect.objectContaining({
text: "Shared a file",
}),
);
});
it("rejects blocks combined with mediaUrl", async () => {
const client = createClient();
await expect(