Skip to content

Commit 0961247

Browse files
authored
fix(discord): route polls through canonical delivery (#126250)
* fix(discord): route polls through canonical delivery * test(discord): align canonical poll action coverage * test(gateway): isolate canonical poll fallback coverage * fix(gateway): align canonical poll capability
1 parent af3b860 commit 0961247

26 files changed

Lines changed: 461 additions & 208 deletions

‎extensions/discord/src/actions/handle-action.test.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,6 @@ describe("handleDiscordMessageAction", () => {
442442
action: "upload-file" as const,
443443
params: { to: "channel:c1", filePath: "/tmp/image.png" },
444444
},
445-
{
446-
action: "poll" as const,
447-
params: {
448-
to: "channel:c1",
449-
pollQuestion: "Which option?",
450-
pollOption: ["first", "second"],
451-
},
452-
},
453445
{
454446
action: "sticker" as const,
455447
params: { to: "channel:c1", stickerId: ["sticker-1"] },

‎extensions/discord/src/actions/handle-action.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -307,32 +307,6 @@ export async function handleDiscordMessageAction(
307307
return withAdoptedThreadReplyRoute(result, to, sessionKey);
308308
}
309309

310-
if (action === "poll") {
311-
const to = readStringParam(params, "to", { required: true });
312-
const question = readStringParam(params, "pollQuestion", {
313-
required: true,
314-
});
315-
const answers = readStringArrayParam(params, "pollOption", { required: true });
316-
const allowMultiselect = readBooleanParam(params, "pollMulti");
317-
const durationHours = readPositiveIntegerParam(params, "pollDurationHours");
318-
const result = await handleDiscordAction(
319-
{
320-
action: "poll",
321-
accountId: accountId ?? undefined,
322-
to,
323-
question,
324-
answers,
325-
allowMultiselect,
326-
durationHours: durationHours ?? undefined,
327-
content: readStringParam(params, "message"),
328-
},
329-
cfg,
330-
actionOptions,
331-
);
332-
notifyVisibleOutbound(result, to);
333-
return result;
334-
}
335-
336310
if (action === "react") {
337311
const messageIdRaw = resolveReactionMessageId({ args: params, toolContext: ctx.toolContext });
338312
const messageId = normalizeOptionalStringifiedId(messageIdRaw) ?? "";

‎extensions/discord/src/actions/runtime.messaging.runtime.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
removeReactionDiscord,
2222
searchMessagesDiscord,
2323
sendMessageDiscord,
24-
sendPollDiscord,
2524
sendStickerDiscord,
2625
sendVoiceMessageDiscord,
2726
unpinMessageDiscord,
@@ -52,7 +51,6 @@ export const discordMessagingActionRuntime = {
5251
searchMessagesDiscord,
5352
sendDiscordComponentMessage,
5453
sendMessageDiscord,
55-
sendPollDiscord,
5654
sendStickerDiscord,
5755
sendVoiceMessageDiscord,
5856
unpinMessageDiscord,

‎extensions/discord/src/actions/runtime.messaging.send.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
readPositiveIntegerParam,
1212
readStringArrayParam,
1313
readStringParam,
14-
resolvePollMaxSelections,
1514
} from "../runtime-api.js";
1615
import { DiscordThreadInitialMessageError } from "../send.js";
1716
import { isThreadChannelType } from "../send.permissions.js";
@@ -193,29 +192,6 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
193192
);
194193
return jsonResult({ ok: true });
195194
}
196-
case "poll": {
197-
if (!ctx.isActionEnabled("polls")) {
198-
throw new Error("Discord polls are disabled.");
199-
}
200-
const to = readStringParam(ctx.params, "to", { required: true });
201-
const content = readStringParam(ctx.params, "content");
202-
const question = readStringParam(ctx.params, "question", {
203-
required: true,
204-
});
205-
const answers = readStringArrayParam(ctx.params, "answers", {
206-
required: true,
207-
label: "answers",
208-
});
209-
const allowMultiselect = readBooleanParam(ctx.params, "allowMultiselect");
210-
const durationHours = readPositiveIntegerParam(ctx.params, "durationHours");
211-
const maxSelections = resolvePollMaxSelections(answers.length, allowMultiselect);
212-
await discordMessagingActionRuntime.sendPollDiscord(
213-
to,
214-
{ question, options: answers, maxSelections, durationHours },
215-
ctx.withOpts({ content }),
216-
);
217-
return jsonResult({ ok: true });
218-
}
219195
case "sendMessage": {
220196
if (!ctx.isActionEnabled("messages")) {
221197
throw new Error("Discord message sends are disabled.");

‎extensions/discord/src/actions/runtime.test.ts‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const discordSendMocks = {
8282
searchMessagesDiscord: vi.fn(async () => ({})),
8383
sendDiscordComponentMessage: vi.fn(async () => ({})),
8484
sendMessageDiscord: vi.fn(async () => ({})),
85-
sendPollDiscord: vi.fn(async () => ({})),
8685
sendStickerDiscord: vi.fn(async () => ({})),
8786
sendVoiceMessageDiscord: vi.fn(async () => ({})),
8887
setChannelPermissionDiscord: vi.fn(async () => ({ ok: true })),
@@ -124,7 +123,6 @@ const {
124123
searchMessagesDiscord,
125124
sendDiscordComponentMessage,
126125
sendMessageDiscord,
127-
sendPollDiscord,
128126
sendVoiceMessageDiscord,
129127
setChannelPermissionDiscord,
130128
timeoutMemberDiscord,
@@ -1194,31 +1192,6 @@ describe("handleDiscordMessagingAction", () => {
11941192
).rejects.toThrow(/Discord reactions are disabled/);
11951193
});
11961194

1197-
it("parses string booleans for poll options", async () => {
1198-
await handleMessagingAction(
1199-
"poll",
1200-
{
1201-
to: "channel:123",
1202-
question: "Lunch?",
1203-
answers: ["Pizza", "Sushi"],
1204-
allowMultiselect: "true",
1205-
durationHours: "24",
1206-
},
1207-
enableAllActions,
1208-
);
1209-
1210-
expect(sendPollDiscord).toHaveBeenCalledWith(
1211-
"channel:123",
1212-
{
1213-
question: "Lunch?",
1214-
options: ["Pizza", "Sushi"],
1215-
maxSelections: 2,
1216-
durationHours: 24,
1217-
},
1218-
{ cfg: DISCORD_TEST_CFG, content: undefined },
1219-
);
1220-
});
1221-
12221195
it("rejects Discord permission reads for non-allowlisted target channels", async () => {
12231196
const cfg = {
12241197
channels: {

‎extensions/discord/src/channel-actions.contract.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("discord actions contract", () => {
99
plugin: discordPlugin,
1010
cases: [
1111
{
12-
name: "describes configured Discord actions and capabilities",
12+
name: "describes configured Discord actions and canonical outbound poll",
1313
cfg: {
1414
channels: {
1515
discord: {
@@ -39,6 +39,7 @@ describe("discord actions contract", () => {
3939
},
4040
} as OpenClawConfig,
4141
expectedActions: ["send", "poll", "react", "reactions", "emoji-list"],
42+
expectedCanonicalOutboundActions: ["poll"],
4243
expectedCapabilities: ["presentation"],
4344
},
4445
],

‎extensions/discord/src/channel-actions.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ describe("discordMessageActions", () => {
364364
expect(discovery?.schema).toBeUndefined();
365365
});
366366

367-
it.each(["read", "search", "edit", "delete", "react", "pin", "poll", "channel-info"])(
367+
it.each(["read", "search", "edit", "delete", "react", "pin", "channel-info"])(
368368
"routes %s actions through gateway execution mode",
369369
(action) => {
370370
expect(discordMessageActions.resolveExecutionMode?.({ action: action as never })).toBe(
@@ -375,6 +375,7 @@ describe("discordMessageActions", () => {
375375

376376
it.each([
377377
"send",
378+
"poll",
378379
"upload-file",
379380
"thread-reply",
380381
"sticker",

‎extensions/discord/src/channel-actions.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isTrustedRequesterGuildAdminAction } from "./trusted-requester-actions.
1717

1818
const localExecutionActions = new Set<ChannelMessageActionName>([
1919
"send",
20+
"poll",
2021
"upload-file",
2122
"thread-reply",
2223
"sticker",

‎extensions/discord/src/channel.test.ts‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ describe("discordPlugin outbound", () => {
232232
expect(discordPlugin.actions?.resolveExecutionMode?.({ action: "thread-reply" as never })).toBe(
233233
"local",
234234
);
235+
expect(discordPlugin.actions?.resolveExecutionMode?.({ action: "poll" })).toBe("local");
236+
expect(discordPlugin.actions?.supportsAction?.({ action: "poll" })).toBe(false);
235237
expect(discordPlugin.actions?.resolveExecutionMode?.({ action: "channel-info" as never })).toBe(
236238
"gateway",
237239
);
@@ -426,35 +428,6 @@ describe("discordPlugin outbound", () => {
426428
expect(result.messageId).toBe("video-1");
427429
});
428430

429-
it("threads poll sends through the thread target", async () => {
430-
const sendPollDiscord = vi.fn(async () => discordTestSendResult("poll-1"));
431-
const sendPollSpy = vi.spyOn(sendModule, "sendPollDiscord").mockImplementation(sendPollDiscord);
432-
try {
433-
const result = await discordPlugin.outbound!.sendPoll!({
434-
cfg: EMPTY_DISCORD_TEST_CONFIG,
435-
to: "channel:123",
436-
poll: {
437-
question: "Best shell?",
438-
options: ["molty", "molter"],
439-
},
440-
accountId: "work",
441-
threadId: "thread-123",
442-
});
443-
444-
expect(argAt(sendPollDiscord, 0, 0)).toBe("channel:thread-123");
445-
expect(argAt(sendPollDiscord, 0, 1)).toEqual({
446-
question: "Best shell?",
447-
options: ["molty", "molter"],
448-
});
449-
expect(objectArgAt(sendPollDiscord, 0, 2).accountId).toBe("work");
450-
const pollResult = result as { channel?: string; messageId?: string };
451-
expect(pollResult.channel).toBe("discord");
452-
expect(pollResult.messageId).toBe("poll-1");
453-
} finally {
454-
sendPollSpy.mockRestore();
455-
}
456-
});
457-
458431
it("forwards heartbeat typing through the run config and attached target", async () => {
459432
const sendTypingDiscord = vi.fn(async () => ({ ok: true, channelId: "thread-123" }));
460433
const sendTypingSpy = vi

‎extensions/discord/src/channel.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ const discordMessageActions: ChannelMessageActionAdapter = {
217217
resolveRuntimeDiscordMessageActions()?.prepareSendPayload?.(ctx) ??
218218
discordMessageActionsImpl.prepareSendPayload?.(ctx) ??
219219
null,
220+
supportsAction: ({ action }) => action !== "poll",
220221
handleAction: async (
221222
ctx: Parameters<NonNullable<ChannelMessageActionAdapter["handleAction"]>>[0],
222223
) => {

0 commit comments

Comments
 (0)