Skip to content

Commit c4f9cf1

Browse files
committed
fix: cap slack edit fallback text
1 parent 3077478 commit c4f9cf1

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Docs: https://docs.openclaw.ai
7878
- Slack/commands: drop fallback command argument buttons whose encoded values exceed Slack's button-value limit, so one oversized plugin choice no longer makes Slack reject the whole menu. Thanks @slackapi.
7979
- Slack/messages: merge message-tool presentation and interactive blocks on Slack sends, so buttons and selects are no longer dropped when a structured message body is also present. Thanks @slackapi.
8080
- Slack/messages: cap Block Kit fallback text to Slack's send limit while preserving the rendered blocks, so long context fallbacks no longer make rich Slack messages fail with `msg_too_long`. Thanks @slackapi.
81+
- Slack/messages: cap Block Kit fallback text on message edits while preserving the rendered blocks, so long context fallbacks no longer make Slack reject `chat.update` calls with `msg_too_long`. Thanks @slackapi.
8182
- Channels/WhatsApp: require Baileys outbound message ids before marking auto-replies delivered, so transcript text and ack reactions no longer make failed group replies look sent. Fixes #49225. Thanks @TinyTb.
8283
- CLI/update: scope packaged Node compile caches by OpenClaw version and install metadata, so global installs no longer reuse stale compiled chunks after package updates. Thanks @pashpashpash.
8384
- Channels/Voice call: keep pre-auth webhook in-flight limiting active when socket remote address metadata is missing, so slow-body requests from stripped-IP proxy paths still share the fallback bucket. (#74453) Thanks @davidangularme.

extensions/slack/src/actions.blocks.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createSlackEditTestClient, installSlackBlockTestMocks } from "./blocks.
33

44
installSlackBlockTestMocks();
55
const { editSlackMessage } = await import("./actions.js");
6+
const SLACK_TEXT_LIMIT = 8000;
67

78
describe("editSlackMessage blocks", () => {
89
it("updates with valid blocks", async () => {
@@ -80,6 +81,35 @@ describe("editSlackMessage blocks", () => {
8081
);
8182
});
8283

84+
it("caps long block fallback text while preserving edit blocks", async () => {
85+
const client = createSlackEditTestClient();
86+
const longContextText = "a".repeat(3000);
87+
const blocks = [
88+
{
89+
type: "context",
90+
elements: [
91+
{ type: "mrkdwn", text: longContextText },
92+
{ type: "mrkdwn", text: longContextText },
93+
{ type: "mrkdwn", text: longContextText },
94+
],
95+
},
96+
];
97+
98+
await editSlackMessage("C123", "171234.567", "", {
99+
token: "xoxb-test",
100+
client,
101+
blocks,
102+
});
103+
104+
expect(client.chat.update).toHaveBeenCalledWith(
105+
expect.objectContaining({
106+
text: expect.stringMatching(/$/),
107+
blocks,
108+
}),
109+
);
110+
expect(client.chat.update.mock.calls[0]?.[0].text).toHaveLength(SLACK_TEXT_LIMIT);
111+
});
112+
83113
it("rejects empty blocks arrays", async () => {
84114
const client = createSlackEditTestClient();
85115

extensions/slack/src/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { resolveSlackAccount } from "./accounts.js";
66
import { buildSlackBlocksFallbackText } from "./blocks-fallback.js";
77
import { validateSlackBlocksArray } from "./blocks-input.js";
88
import { createSlackWebClient, getSlackWriteClient } from "./client.js";
9+
import { SLACK_TEXT_LIMIT } from "./limits.js";
910
import { resolveSlackMedia } from "./monitor/media.js";
1011
import type { SlackMediaResult } from "./monitor/media.js";
1112
import { sendMessageSlack } from "./send.js";
1213
import { resolveSlackBotToken } from "./token.js";
14+
import { truncateSlackText } from "./truncate.js";
1315

1416
export type SlackActionClientOpts = {
1517
cfg?: OpenClawConfig;
@@ -234,7 +236,9 @@ export async function editSlackMessage(
234236
await client.chat.update({
235237
channel: channelId,
236238
ts: messageId,
237-
text: trimmedContent || (blocks ? buildSlackBlocksFallbackText(blocks) : " "),
239+
text:
240+
trimmedContent ||
241+
(blocks ? truncateSlackText(buildSlackBlocksFallbackText(blocks), SLACK_TEXT_LIMIT) : " "),
238242
...(blocks ? { blocks } : {}),
239243
});
240244
}

0 commit comments

Comments
 (0)