

























@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
66import type { WhatsAppSendResult } from "../inbound/send-result.js";
77import { buildMentionConfig } from "./mentions.js";
88import { applyGroupGating, type GroupHistoryEntry } from "./monitor/group-gating.js";
9+import { formatWhatsAppInboundListeningLog } from "./monitor/listener-log.js";
910import { buildInboundLine, formatReplyContext } from "./monitor/message-line.js";
1011import type { WebInboundMsg } from "./types.js";
1112@@ -59,6 +60,7 @@ async function runGroupGating(params: {
5960const agentId = params.agentId ?? "main";
6061const sessionKey = `agent:${agentId}:whatsapp:group:${conversationId}`;
6162const baseMentionConfig = buildMentionConfig(params.cfg, undefined);
63+const verboseLogs: string[] = [];
6264const result = await applyGroupGating({
6365cfg: params.cfg,
6466msg: params.msg,
@@ -72,10 +74,10 @@ async function runGroupGating(params: {
7274 groupHistories,
7375groupHistoryLimit: 10,
7476groupMemberNames: new Map(),
75-logVerbose: () => {},
77+logVerbose: (message) => verboseLogs.push(message),
7678replyLogger: { debug: () => {} },
7779});
78-return { result, groupHistories };
80+return { result, groupHistories, verboseLogs };
7981}
80828183function createGroupMessage(overrides: Partial<WebInboundMsg> = {}): WebInboundMsg {
@@ -116,6 +118,55 @@ function makeInboundCfg(messagePrefix = "") {
116118} as never;
117119}
118120121+describe("WhatsApp listener diagnostics", () => {
122+it("describes WhatsApp inbound listener scope without implying DM-only routing", () => {
123+expect(
124+formatWhatsAppInboundListeningLog({
125+groupPolicy: "open",
126+hasGroupAllowFrom: false,
127+}),
128+).toBe(
129+"Listening for WhatsApp inbound messages (DM + all groups; no group allowlist configured).",
130+);
131+expect(
132+formatWhatsAppInboundListeningLog({
133+groupPolicy: "disabled",
134+hasGroupAllowFrom: true,
135+}),
136+).toBe("Listening for WhatsApp inbound messages (DM + groups disabled by groupPolicy).");
137+expect(
138+formatWhatsAppInboundListeningLog({
139+groupPolicy: "allowlist",
140+hasGroupAllowFrom: false,
141+}),
142+).toBe(
143+"Listening for WhatsApp inbound messages (DM + group inbound blocked by empty groupPolicy allowlist).",
144+);
145+expect(
146+formatWhatsAppInboundListeningLog({
147+groupPolicy: "allowlist",
148+hasGroupAllowFrom: true,
149+}),
150+).toBe(
151+"Listening for WhatsApp inbound messages (DM + all groups; sender allowlist configured).",
152+);
153+expect(
154+formatWhatsAppInboundListeningLog({
155+groups: { "123@g.us": {}, "*": {} },
156+groupPolicy: "allowlist",
157+hasGroupAllowFrom: true,
158+}),
159+).toBe("Listening for WhatsApp inbound messages (DM + all groups; wildcard configured).");
160+expect(
161+formatWhatsAppInboundListeningLog({
162+groups: { "123@g.us": {}, "456@g.us": {} },
163+groupPolicy: "allowlist",
164+hasGroupAllowFrom: true,
165+}),
166+).toBe("Listening for WhatsApp inbound messages (DM + 2 configured groups).");
167+});
168+});
169+119170describe("applyGroupGating", () => {
120171it("treats reply-to-bot as implicit mention", async () => {
121172const cfg = makeConfig({});
@@ -583,7 +634,7 @@ describe("applyGroupGating", () => {
583634},
584635});
585636586-const { result } = await runGroupGating({
637+const { result, verboseLogs } = await runGroupGating({
587638 cfg,
588639msg: createGroupMessage({
589640body: "@workbot ping",
@@ -593,6 +644,9 @@ describe("applyGroupGating", () => {
593644});
594645595646expect(result.shouldProcess).toBe(false);
647+expect(verboseLogs).toContain(
648+'Dropping message from unregistered WhatsApp group 123@g.us. Add the group JID to channels.whatsapp.groups, or add "*" there to admit all groups. Sender authorization still applies.',
649+);
596650});
597651});
598652此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。