fix(regression): preserve mattermost reaction channel routing

This commit is contained in:
Tak Hoffman 2026-03-27 21:30:24 -05:00
parent 42ecfffbff
commit a3961d098a
No known key found for this signature in database
2 changed files with 32 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../../runtime-api.js";
import { resolveMattermostAccount } from "./accounts.js";
import {
evaluateMattermostMentionGate,
resolveMattermostReactionChannelId,
resolveMattermostEffectiveReplyToId,
resolveMattermostReplyRootId,
resolveMattermostThreadSessionContext,
@ -274,3 +275,26 @@ describe("resolveMattermostThreadSessionContext", () => {
});
});
});
describe("resolveMattermostReactionChannelId", () => {
it("prefers broadcast channel_id when present", () => {
expect(
resolveMattermostReactionChannelId({
broadcast: { channel_id: "chan-broadcast" },
data: { channel_id: "chan-data" },
}),
).toBe("chan-broadcast");
});
it("falls back to data.channel_id when broadcast channel_id is missing", () => {
expect(
resolveMattermostReactionChannelId({
data: { channel_id: "chan-data" },
}),
).toBe("chan-data");
});
it("returns undefined when neither payload location includes channel_id", () => {
expect(resolveMattermostReactionChannelId({})).toBeUndefined();
});
});

View File

@ -212,6 +212,13 @@ export function resolveMattermostThreadSessionContext(params: {
parentSessionKey: threadKeys.parentSessionKey,
};
}
export function resolveMattermostReactionChannelId(
payload: Pick<MattermostEventPayload, "broadcast" | "data">,
): string | undefined {
return payload.broadcast?.channel_id?.trim() || payload.data?.channel_id?.trim() || undefined;
}
function buildMattermostAttachmentPlaceholder(mediaList: MattermostMediaInfo[]): string {
if (mediaList.length === 0) {
return "";
@ -1492,7 +1499,7 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
const senderName = senderInfo?.username?.trim() || userId;
// Resolve the channel from broadcast or post to route to the correct agent session
const channelId = payload.broadcast?.channel_id;
const channelId = resolveMattermostReactionChannelId(payload);
if (!channelId) {
// Without a channel id we cannot verify DM/group policies — drop to be safe
logVerboseMessage(