Skip to content

Commit 16c097b

Browse files
authored
fix(slack): deduplicate mirrored question controls (#129445)
1 parent 830700d commit 16c097b

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎extensions/slack/src/outbound-adapter.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Slack tests cover outbound adapter plugin behavior.
2+
import { presentationToInteractiveControlsReply } from "openclaw/plugin-sdk/interactive-runtime";
23
import { beforeEach, describe, expect, it, vi } from "vitest";
34

45
const sendMessageSlackMock = vi.hoisted(() => vi.fn());
@@ -28,6 +29,45 @@ describe("slackOutbound", () => {
2829
sendMessageSlackMock.mockReset();
2930
});
3031

32+
it("sends mirrored question controls once at the Slack message block limit", async () => {
33+
sendMessageSlackMock.mockResolvedValue({ messageId: "171.001", channelId: "C123" });
34+
const questionId = "ask_0123456789abcdef0123456789abcdef";
35+
const presentation = {
36+
blocks: [
37+
{
38+
type: "buttons" as const,
39+
buttons: [
40+
{
41+
label: "Continue",
42+
action: { type: "question" as const, questionId, optionValue: "Continue" },
43+
},
44+
],
45+
},
46+
],
47+
};
48+
const payload = {
49+
channelData: {
50+
askUser: { questionId },
51+
slack: { blocks: Array.from({ length: 49 }, () => ({ type: "divider" as const })) },
52+
},
53+
presentation,
54+
interactive: presentationToInteractiveControlsReply(presentation),
55+
};
56+
const rendered = await slackOutbound.renderPresentation!({
57+
payload,
58+
presentation,
59+
ctx: { cfg, to: "C123", text: "", payload },
60+
});
61+
62+
await slackOutbound.sendPayload!({ cfg, to: "C123", text: "", payload: rendered! });
63+
64+
expect(sendMessageSlackMock).toHaveBeenCalledOnce();
65+
expect(sendMessageSlackMock.mock.calls[0]?.[2]?.blocks).toHaveLength(50);
66+
expect(sendMessageSlackMock.mock.calls[0]?.[2]?.blocks.at(-1)).toMatchObject({
67+
elements: [{ action_id: "openclaw:question_button:1:1" }],
68+
});
69+
});
70+
3171
it("sends payload media first, then finalizes with blocks", async () => {
3272
sendMessageSlackMock
3373
.mockResolvedValueOnce({ messageId: "m-media-1" })

‎extensions/slack/src/reply-blocks.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@ describe("renderSlackMessagePresentationFallbackText", () => {
541541
decision: "allow-once",
542542
},
543543
},
544+
{
545+
label: "Question",
546+
action: {
547+
type: "question",
548+
questionId: "ask_0123456789abcdef0123456789abcdef",
549+
optionValue: "Question",
550+
},
551+
},
544552
{ label: "URL", action: { type: "url", url: "https://example.com/docs" } },
545553
{
546554
label: "Web app",
@@ -585,8 +593,9 @@ describe("renderSlackMessagePresentationFallbackText", () => {
585593
"openclaw:reply_button:1:1",
586594
"openclaw:callback_button:1:2",
587595
"openclaw:approval_button:1:3",
588-
"openclaw:reply_link:1:4",
596+
"openclaw:question_button:1:4",
589597
"openclaw:reply_link:1:5",
598+
"openclaw:reply_link:1:6",
590599
"openclaw:reply_select:1",
591600
"openclaw:callback_select:2",
592601
]);

‎extensions/slack/src/reply-blocks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
SLACK_APPROVAL_SELECT_ACTION_ID,
3434
SLACK_CALLBACK_BUTTON_ACTION_ID,
3535
SLACK_CALLBACK_SELECT_ACTION_ID,
36+
SLACK_QUESTION_BUTTON_ACTION_ID,
3637
SLACK_REPLY_BUTTON_ACTION_ID,
3738
SLACK_REPLY_LINK_ACTION_ID,
3839
SLACK_REPLY_SELECT_ACTION_ID,
@@ -356,6 +357,7 @@ function appendPresentationPart(
356357
const SLACK_BUTTON_CONTROL_ACTION_IDS = [
357358
SLACK_APPROVAL_BUTTON_ACTION_ID,
358359
SLACK_CALLBACK_BUTTON_ACTION_ID,
360+
SLACK_QUESTION_BUTTON_ACTION_ID,
359361
SLACK_REPLY_BUTTON_ACTION_ID,
360362
SLACK_REPLY_LINK_ACTION_ID,
361363
] as const;

0 commit comments

Comments
 (0)