mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Mattermost: fix interaction action lookup sentinel
This commit is contained in:
@@ -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" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user