mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 12:20:23 +00:00
Mattermost: align group mention resolver and remove redundant gate calc
This commit is contained in:
committed by
Muhammed Mukhthar CM
parent
8bc0314342
commit
d0297888b9
46
extensions/mattermost/src/group-mentions.test.ts
Normal file
46
extensions/mattermost/src/group-mentions.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveMattermostGroupRequireMention } from "./group-mentions.js";
|
||||
|
||||
describe("resolveMattermostGroupRequireMention", () => {
|
||||
it("defaults to requiring mention when no override is configured", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
mattermost: {},
|
||||
},
|
||||
};
|
||||
|
||||
const requireMention = resolveMattermostGroupRequireMention({ cfg, accountId: "default" });
|
||||
expect(requireMention).toBe(true);
|
||||
});
|
||||
|
||||
it("respects chatmode-derived account override", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
mattermost: {
|
||||
chatmode: "onmessage",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const requireMention = resolveMattermostGroupRequireMention({ cfg, accountId: "default" });
|
||||
expect(requireMention).toBe(false);
|
||||
});
|
||||
|
||||
it("prefers an explicit runtime override when provided", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
mattermost: {
|
||||
chatmode: "oncall",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const requireMention = resolveMattermostGroupRequireMention({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
requireMentionOverride: false,
|
||||
});
|
||||
expect(requireMention).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,15 +1,22 @@
|
||||
import type { ChannelGroupContext } from "openclaw/plugin-sdk/mattermost";
|
||||
import { resolveChannelGroupRequireMention, type ChannelGroupContext } from "openclaw/plugin-sdk";
|
||||
import { resolveMattermostAccount } from "./mattermost/accounts.js";
|
||||
|
||||
export function resolveMattermostGroupRequireMention(
|
||||
params: ChannelGroupContext,
|
||||
params: ChannelGroupContext & { requireMentionOverride?: boolean },
|
||||
): boolean | undefined {
|
||||
const account = resolveMattermostAccount({
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
if (typeof account.requireMention === "boolean") {
|
||||
return account.requireMention;
|
||||
}
|
||||
return true;
|
||||
const requireMentionOverride =
|
||||
typeof params.requireMentionOverride === "boolean"
|
||||
? params.requireMentionOverride
|
||||
: account.requireMention;
|
||||
return resolveChannelGroupRequireMention({
|
||||
cfg: params.cfg,
|
||||
channel: "mattermost",
|
||||
groupId: params.groupId,
|
||||
accountId: params.accountId,
|
||||
requireMentionOverride,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -798,6 +798,7 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
|
||||
? stripOncharPrefix(rawText, oncharPrefixes)
|
||||
: { triggered: false, stripped: rawText };
|
||||
const oncharTriggered = oncharResult.triggered;
|
||||
const canDetectMention = Boolean(botUsername) || mentionRegexes.length > 0;
|
||||
const mentionDecision = evaluateMattermostMentionGate({
|
||||
kind,
|
||||
cfg,
|
||||
@@ -811,10 +812,9 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
|
||||
commandAuthorized,
|
||||
oncharEnabled,
|
||||
oncharTriggered,
|
||||
canDetectMention: Boolean(botUsername) || mentionRegexes.length > 0,
|
||||
canDetectMention,
|
||||
});
|
||||
const { shouldRequireMention, shouldBypassMention, effectiveWasMentioned } = mentionDecision;
|
||||
const canDetectMention = Boolean(botUsername) || mentionRegexes.length > 0;
|
||||
|
||||
if (mentionDecision.dropReason === "onchar-not-triggered") {
|
||||
logVerboseMessage(
|
||||
|
||||
@@ -398,7 +398,7 @@ export type { ScopeTokenProvider } from "./fetch-auth.js";
|
||||
export { rawDataToString } from "../infra/ws.js";
|
||||
export { isWSLSync, isWSL2Sync, isWSLEnv } from "../infra/wsl.js";
|
||||
export { isTruthyEnvValue } from "../infra/env.js";
|
||||
export { resolveToolsBySender } from "../config/group-policy.js";
|
||||
export { resolveChannelGroupRequireMention, resolveToolsBySender } from "../config/group-policy.js";
|
||||
export {
|
||||
buildPendingHistoryContextFromMap,
|
||||
clearHistoryEntries,
|
||||
|
||||
Reference in New Issue
Block a user