diff --git a/extensions/mattermost/src/mattermost/interactions.test.ts b/extensions/mattermost/src/mattermost/interactions.test.ts index 40715bf885e..7f823d8fbde 100644 --- a/extensions/mattermost/src/mattermost/interactions.test.ts +++ b/extensions/mattermost/src/mattermost/interactions.test.ts @@ -735,6 +735,51 @@ describe("createMattermostInteractionHandler", () => { expect(res.body).toContain("Unknown action"); }); + it("accepts actions when the button name matches the action id", async () => { + const context = { action_id: "approve", __openclaw_channel_id: "chan-1" }; + const token = generateInteractionToken(context, "acct"); + const requestLog: Array<{ path: string; method?: string }> = []; + const handler = createMattermostInteractionHandler({ + client: { + request: async (path: string, init?: { method?: string }) => { + requestLog.push({ path, method: init?.method }); + if (init?.method === "PUT") { + return { id: "post-1" }; + } + return { + channel_id: "chan-1", + message: "Choose", + props: { + attachments: [{ actions: [{ id: "approve", name: "approve" }] }], + }, + }; + }, + } as unknown as MattermostClient, + botUserId: "bot", + accountId: "acct", + }); + + const req = createReq({ + body: { + user_id: "user-1", + user_name: "alice", + channel_id: "chan-1", + post_id: "post-1", + context: { ...context, _token: token }, + }, + }); + const res = createRes(); + + await handler(req, res); + + expect(res.statusCode).toBe(200); + expect(res.body).toBe("{}"); + expect(requestLog).toEqual([ + { path: "/posts/post-1", method: undefined }, + { path: "/posts/post-1", method: "PUT" }, + ]); + }); + it("lets a custom interaction handler short-circuit generic completion updates", async () => { const context = { action_id: "mdlprov", __openclaw_channel_id: "chan-1" }; const token = generateInteractionToken(context, "acct"); diff --git a/extensions/mattermost/src/mattermost/interactions.ts b/extensions/mattermost/src/mattermost/interactions.ts index ee763a12a6d..9e888d658cb 100644 --- a/extensions/mattermost/src/mattermost/interactions.ts +++ b/extensions/mattermost/src/mattermost/interactions.ts @@ -503,7 +503,7 @@ export function createMattermostInteractionHandler(params: { const userName = payload.user_name ?? payload.user_id; let originalMessage = ""; - let clickedButtonName = actionId; + let clickedButtonName: string | null = null; try { const originalPost = await client.request<{ channel_id?: string | null; @@ -535,7 +535,7 @@ export function createMattermostInteractionHandler(params: { break; } } - if (clickedButtonName === actionId) { + if (clickedButtonName === null) { log?.(`mattermost interaction: action ${actionId} not found in post ${payload.post_id}`); res.statusCode = 403; res.setHeader("Content-Type", "application/json");