Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slack-empty-table-cells.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chat-adapter/slack": patch
---

Fix empty table cells causing `invalid_blocks` error from Slack API. Empty cells now fall back to a single space to satisfy the Block Kit requirement that cell text must be more than 0 characters.
27 changes: 27 additions & 0 deletions packages/adapter-slack/src/cards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,31 @@ describe("cardToBlockKit with CardLink", () => {
expect(blocks[1].type).toBe("section");
expect(blocks[1].text.text).toContain("```");
});

it("replaces empty table cells with a space to satisfy Slack API", () => {
const card = Card({
children: [
Table({
headers: ["Kind", ""],
rows: [
["FORM", "Form Submission"],
["and more...", ""],
],
}),
],
});

const blocks = cardToBlockKit(card);
const tableBlock = blocks[0];
expect(tableBlock.type).toBe("table");
// Every cell must have non-empty text (Slack rejects empty strings)
for (const row of tableBlock.rows) {
for (const cell of row) {
expect(cell.text.length).toBeGreaterThan(0);
}
}
// Empty cells become a space
expect(tableBlock.rows[0][1].text).toBe(" "); // empty header
expect(tableBlock.rows[2][1].text).toBe(" "); // empty data cell
});
});
4 changes: 2 additions & 2 deletions packages/adapter-slack/src/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ function convertTableToBlocks(
// First row is headers, subsequent rows are data
const headerRow = element.headers.map((header) => ({
type: "raw_text" as const,
text: convertEmoji(header),
text: convertEmoji(header) || " ",
}));

const dataRows = element.rows.map((row) =>
row.map((cell) => ({
type: "raw_text" as const,
text: convertEmoji(cell),
text: convertEmoji(cell) || " ",
}))
);

Expand Down
17 changes: 17 additions & 0 deletions packages/adapter-slack/src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ describe("SlackMarkdownConverter", () => {
expect(blocks?.[1].type).toBe("section");
expect(blocks?.[1].text.text).toContain("```");
});

it("should replace empty table cells with a space to satisfy Slack API", () => {
const ast = converter.toAst(
"| Kind | Label |\n|------|-------|\n| FORM | Form Submission |\n| and more... | |"
);
const blocks = converter.toBlocksWithTable(ast);
const tableBlock = blocks?.[0];
expect(tableBlock?.type).toBe("table");
// Every cell must have non-empty text (Slack rejects empty strings)
for (const row of tableBlock?.rows ?? []) {
for (const cell of row) {
expect(cell.text.length).toBeGreaterThan(0);
}
}
// The empty cell should be a space
expect(tableBlock?.rows[2][1].text).toBe(" ");
});
});

describe("nested lists", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-slack/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function mdastTableToSlackBlock(
for (const row of node.children) {
const cells = getNodeChildren(row).map((cell) => ({
type: "raw_text" as const,
text: getNodeChildren(cell).map(cellConverter).join(""),
text: getNodeChildren(cell).map(cellConverter).join("") || " ",
}));
rows.push(cells);
}
Expand Down