Mattermost: fix interaction action lookup sentinel

This commit is contained in:
Vincent Koc
2026-03-06 19:11:19 -05:00
parent c18f572ea0
commit 6b7c73a442
2 changed files with 47 additions and 2 deletions

View File

@@ -610,4 +610,49 @@ describe("createMattermostInteractionHandler", () => {
expect(res.statusCode).toBe(403);
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" },
]);
});
});

View File

@@ -380,7 +380,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;
@@ -412,7 +412,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");