From 7f86be1037aeb696303607660d979923d25aa484 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Thu, 19 Mar 2026 08:50:38 -0400 Subject: [PATCH] Matrix: accept messageId alias for poll votes --- extensions/matrix/src/tool-actions.test.ts | 19 ++++++++++++++++ extensions/matrix/src/tool-actions.ts | 26 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/extensions/matrix/src/tool-actions.test.ts b/extensions/matrix/src/tool-actions.test.ts index d917f33090f..341569d6beb 100644 --- a/extensions/matrix/src/tool-actions.test.ts +++ b/extensions/matrix/src/tool-actions.test.ts @@ -119,6 +119,25 @@ describe("handleMatrixAction pollVote", () => { ).rejects.toThrow("pollId required"); }); + it("accepts messageId as a pollId alias for poll votes", async () => { + const cfg = {} as CoreConfig; + await handleMatrixAction( + { + action: "pollVote", + roomId: "!room:example", + messageId: "$poll", + pollOptionIndex: 1, + }, + cfg, + ); + + expect(mocks.voteMatrixPoll).toHaveBeenCalledWith("!room:example", "$poll", { + cfg, + optionIds: [], + optionIndexes: [1], + }); + }); + it("passes account-scoped opts to add reactions", async () => { const cfg = { channels: { matrix: { actions: { reactions: true } } } } as CoreConfig; await handleMatrixAction( diff --git a/extensions/matrix/src/tool-actions.ts b/extensions/matrix/src/tool-actions.ts index 4e2bd5aff4a..3798818c0d9 100644 --- a/extensions/matrix/src/tool-actions.ts +++ b/extensions/matrix/src/tool-actions.ts @@ -97,6 +97,27 @@ function readRawParam(params: Record, key: string): unknown { return undefined; } +function readStringAliasParam( + params: Record, + keys: string[], + options: { required?: boolean } = {}, +): string | undefined { + for (const key of keys) { + const raw = readRawParam(params, key); + if (typeof raw !== "string") { + continue; + } + const trimmed = raw.trim(); + if (trimmed) { + return trimmed; + } + } + if (options.required) { + throw new Error(`${keys[0]} required`); + } + return undefined; +} + function readNumericArrayParam( params: Record, key: string, @@ -169,7 +190,10 @@ export async function handleMatrixAction( if (pollActions.has(action)) { const roomId = readRoomId(params); - const pollId = readStringParam(params, "pollId", { required: true }); + const pollId = readStringAliasParam(params, ["pollId", "messageId"], { required: true }); + if (!pollId) { + throw new Error("pollId required"); + } const optionId = readStringParam(params, "pollOptionId"); const optionIndex = readNumberParam(params, "pollOptionIndex", { integer: true }); const optionIds = [