























@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
66import { buildMentionConfig } from "./mentions.js";
77import { applyGroupGating, type GroupHistoryEntry } from "./monitor/group-gating.js";
88import { buildInboundLine, formatReplyContext } from "./monitor/message-line.js";
9+import type { WebInboundMsg } from "./types.js";
9101011let sessionDir: string | undefined;
1112let sessionStorePath: string;
@@ -37,10 +38,11 @@ const makeConfig = (overrides: Record<string, unknown>) =>
37383839async function runGroupGating(params: {
3940cfg: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
40-msg: Record<string, unknown>;
41+msg: WebInboundMsg;
4142conversationId?: string;
4243agentId?: string;
4344selfChatMode?: boolean;
45+authDir?: string;
4446}) {
4547const groupHistories = new Map<string, GroupHistoryEntry[]>();
4648const conversationId = params.conversationId ?? "123@g.us";
@@ -49,12 +51,13 @@ async function runGroupGating(params: {
4951const baseMentionConfig = buildMentionConfig(params.cfg, undefined);
5052const result = await applyGroupGating({
5153cfg: params.cfg,
52-msg: params.msg as any,
54+msg: params.msg,
5355 conversationId,
5456groupHistoryKey: `whatsapp:default:group:${conversationId}`,
5557 agentId,
5658 sessionKey,
5759 baseMentionConfig,
60+authDir: params.authDir,
5861selfChatMode: params.selfChatMode,
5962 groupHistories,
6063groupHistoryLimit: 10,
@@ -65,21 +68,22 @@ async function runGroupGating(params: {
6568return { result, groupHistories };
6669}
677068-function createGroupMessage(overrides: Record<string, unknown> = {}) {
71+function createGroupMessage(overrides: Partial<WebInboundMsg> = {}): WebInboundMsg {
6972return {
7073id: "g1",
7174from: "123@g.us",
7275conversationId: "123@g.us",
7376chatId: "123@g.us",
7477chatType: "group",
7578to: "+2",
79+accountId: "default",
7680body: "hello group",
7781senderE164: "+111",
7882senderName: "Alice",
7983selfE164: "+999",
8084sendComposing: async () => {},
81-reply: async () => {},
82-sendMedia: async () => {},
85+reply: async (_text, _options) => {},
86+sendMedia: async (_payload, _options) => {},
8387 ...overrides,
8488};
8589}
@@ -194,6 +198,45 @@ describe("applyGroupGating", () => {
194198expect(result.shouldProcess).toBe(true);
195199});
196200201+it("processes explicit group @mentions when self is in allowFrom (#49317)", async () => {
202+if (!sessionDir) {
203+throw new Error("sessionDir not initialized");
204+}
205+await fs.writeFile(
206+path.join(sessionDir, "lid-mapping-216372600647751_reverse.json"),
207+JSON.stringify("+15551234567"),
208+);
209+const cfg = makeConfig({
210+channels: {
211+whatsapp: {
212+allowFrom: ["+15551234567"],
213+groupPolicy: "open",
214+groups: { "*": { requireMention: true } },
215+},
216+},
217+});
218+const msg = createGroupMessage({
219+id: "g-self-lid-mention",
220+accountId: "default",
221+body: "@216372600647751 can you see this?",
222+mentionedJids: ["216372600647751@lid"],
223+senderE164: "+15550001111",
224+senderName: "Alice",
225+selfE164: "+15551234567",
226+selfJid: "15551234567@s.whatsapp.net",
227+});
228+229+const { result, groupHistories } = await runGroupGating({
230+ cfg,
231+authDir: sessionDir,
232+ msg,
233+});
234+235+expect(result.shouldProcess).toBe(true);
236+expect(msg.wasMentioned).toBe(true);
237+expect(groupHistories.get("whatsapp:default:group:123@g.us")).toBeUndefined();
238+});
239+197240it("honors per-account selfChatMode overrides before suppressing implicit mentions", async () => {
198241const cfg = makeConfig({
199242channels: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。