@openclaw/whatsapp 2026.5.2 → 2026.5.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-control-BQ3tCkH8.js +288 -0
- package/dist/account-config-CNQ33oav.js +47 -0
- package/dist/account-ids-DG18xddX.js +5 -0
- package/dist/accounts-BDqgpFEB.js +116 -0
- package/dist/action-runtime-DTGNgG-i.js +74 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/action-runtime.runtime.js +2 -0
- package/dist/active-listener-N7GFKsuN.js +11 -0
- package/dist/agent-tools-login-DpRxLNRB.js +89 -0
- package/dist/api.js +148 -0
- package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
- package/dist/auth-presence.js +32 -0
- package/dist/auth-store-BjCb50Ry.js +381 -0
- package/dist/channel-DQ-5Xoj9.js +542 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel-react-action-Df20qAy9.js +42 -0
- package/dist/channel.runtime-DKXRnA8x.js +55 -0
- package/dist/channel.setup-DOHR2BGp.js +20 -0
- package/dist/command-policy-O8sRnqUV.js +8 -0
- package/dist/config-schema-Dmo66Ubb.js +27 -0
- package/dist/connection-controller-BiHAsTM8.js +596 -0
- package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
- package/dist/constants-DLGCIbfl.js +4 -0
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +19 -0
- package/dist/creds-files-_2V8jzQa.js +19 -0
- package/dist/directory-config-DVs4ffXu.js +37 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/doctor-A9tXm9Om.js +48 -0
- package/dist/doctor-contract-api.js +10 -0
- package/dist/group-session-contract-B8QBn0I2.js +15 -0
- package/dist/identity-QHAlV7Fu.js +75 -0
- package/dist/index.js +18 -0
- package/dist/legacy-session-surface-api.js +8 -0
- package/dist/legacy-state-migrations-api.js +2 -0
- package/dist/light-runtime-api.js +5 -0
- package/dist/login-DymdrKca.js +52 -0
- package/dist/login-qr-DIS0Iv-7.js +378 -0
- package/dist/login-qr-api.js +2 -0
- package/dist/login-qr-runtime.js +16 -0
- package/dist/monitor-C4Fhg_lD.js +3349 -0
- package/dist/normalize-CWYiGkXw.js +2 -0
- package/dist/normalize-target-BPVHNsM5.js +74 -0
- package/dist/outbound-adapter-BssVnZdz.js +29 -0
- package/dist/outbound-base-Bq1UYEK5.js +119 -0
- package/dist/outbound-media-contract-CGss_QHy.js +163 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/quoted-message-TENQzyxV.js +108 -0
- package/dist/reaction-level-CRVEVAfi.js +16 -0
- package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
- package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
- package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
- package/dist/runtime-6fZ67abR.js +8 -0
- package/dist/runtime-api.js +15 -0
- package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-contract-DqH8JDX6.js +26 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-CIyLFxdZ.js +234 -0
- package/dist/session-contract-B0efQf9P.js +27 -0
- package/dist/session-errors-CSuKZPub.js +63 -0
- package/dist/session.runtime-C1eSE_KK.js +13 -0
- package/dist/setup-core-DZKvpzbH.js +46 -0
- package/dist/setup-entry.js +23 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-ieFnIW4g.js +344 -0
- package/dist/shared-D_wzSVar.js +307 -0
- package/dist/state-migrations-DnCdvoYD.js +39 -0
- package/dist/targets.js +2 -0
- package/dist/test-api.js +3 -0
- package/dist/text-runtime-C1zNiZeO.js +116 -0
- package/package.json +14 -6
- package/action-runtime-api.ts +0 -1
- package/action-runtime.runtime.ts +0 -1
- package/api.ts +0 -213
- package/auth-presence.ts +0 -80
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/constants.ts +0 -1
- package/contract-api.ts +0 -29
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -8
- package/index.test.ts +0 -13
- package/index.ts +0 -16
- package/legacy-session-surface-api.ts +0 -6
- package/legacy-state-migrations-api.ts +0 -1
- package/light-runtime-api.ts +0 -12
- package/login-qr-api.ts +0 -1
- package/login-qr-runtime.ts +0 -23
- package/outbound-payload-test-api.ts +0 -1
- package/runtime-api.ts +0 -84
- package/secret-contract-api.ts +0 -4
- package/security-contract-api.ts +0 -4
- package/setup-entry.test.ts +0 -21
- package/setup-entry.ts +0 -21
- package/setup-plugin-api.ts +0 -3
- package/src/account-config.ts +0 -77
- package/src/account-ids.ts +0 -13
- package/src/account-types.ts +0 -5
- package/src/accounts.test.ts +0 -182
- package/src/accounts.ts +0 -176
- package/src/accounts.whatsapp-auth.test.ts +0 -59
- package/src/action-runtime-target-auth.ts +0 -27
- package/src/action-runtime.test.ts +0 -330
- package/src/action-runtime.ts +0 -76
- package/src/active-listener.test.ts +0 -65
- package/src/active-listener.ts +0 -17
- package/src/agent-tools-login.test.ts +0 -81
- package/src/agent-tools-login.ts +0 -113
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -27
- package/src/auth-store.runtime.ts +0 -1
- package/src/auth-store.test.ts +0 -311
- package/src/auth-store.ts +0 -502
- package/src/auto-reply/config.runtime.ts +0 -16
- package/src/auto-reply/constants.ts +0 -1
- package/src/auto-reply/deliver-reply.test.ts +0 -843
- package/src/auto-reply/deliver-reply.ts +0 -279
- package/src/auto-reply/loggers.ts +0 -6
- package/src/auto-reply/mentions.ts +0 -131
- package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
- package/src/auto-reply/monitor/ack-reaction.ts +0 -99
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
- package/src/auto-reply/monitor/broadcast.ts +0 -153
- package/src/auto-reply/monitor/commands.ts +0 -19
- package/src/auto-reply/monitor/echo.ts +0 -64
- package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
- package/src/auto-reply/monitor/group-activation.test.ts +0 -189
- package/src/auto-reply/monitor/group-activation.ts +0 -73
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
- package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
- package/src/auto-reply/monitor/group-gating.ts +0 -217
- package/src/auto-reply/monitor/group-members.test.ts +0 -56
- package/src/auto-reply/monitor/group-members.ts +0 -65
- package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
- package/src/auto-reply/monitor/inbound-context.ts +0 -92
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
- package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
- package/src/auto-reply/monitor/last-route.test.ts +0 -37
- package/src/auto-reply/monitor/last-route.ts +0 -61
- package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
- package/src/auto-reply/monitor/message-line.ts +0 -54
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
- package/src/auto-reply/monitor/on-message.ts +0 -291
- package/src/auto-reply/monitor/peer.ts +0 -17
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
- package/src/auto-reply/monitor/process-message.test.ts +0 -355
- package/src/auto-reply/monitor/process-message.ts +0 -531
- package/src/auto-reply/monitor/runtime-api.ts +0 -30
- package/src/auto-reply/monitor-state.test.ts +0 -64
- package/src/auto-reply/monitor-state.ts +0 -106
- package/src/auto-reply/monitor.ts +0 -600
- package/src/auto-reply/reply-resolver.runtime.ts +0 -1
- package/src/auto-reply/types.ts +0 -48
- package/src/auto-reply/util.ts +0 -63
- package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
- package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
- package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
- package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
- package/src/auto-reply.impl.ts +0 -6
- package/src/auto-reply.test-harness.ts +0 -421
- package/src/auto-reply.ts +0 -1
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
- package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
- package/src/channel-actions.runtime.ts +0 -7
- package/src/channel-actions.test.ts +0 -216
- package/src/channel-actions.ts +0 -84
- package/src/channel-outbound.test.ts +0 -131
- package/src/channel-outbound.ts +0 -36
- package/src/channel-react-action.runtime.ts +0 -7
- package/src/channel-react-action.test.ts +0 -294
- package/src/channel-react-action.ts +0 -84
- package/src/channel.runtime.ts +0 -117
- package/src/channel.setup.test.ts +0 -461
- package/src/channel.setup.ts +0 -28
- package/src/channel.ts +0 -339
- package/src/command-policy.ts +0 -7
- package/src/config-accessors.test.ts +0 -34
- package/src/config-accessors.ts +0 -22
- package/src/config-schema.test.ts +0 -121
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -24
- package/src/connection-controller-registry.test.ts +0 -27
- package/src/connection-controller-registry.ts +0 -49
- package/src/connection-controller.test.ts +0 -282
- package/src/connection-controller.ts +0 -679
- package/src/creds-files.ts +0 -19
- package/src/creds-persistence.ts +0 -102
- package/src/directory-config.test.ts +0 -60
- package/src/directory-config.ts +0 -40
- package/src/directory-contract.test.ts +0 -56
- package/src/doctor-contract.ts +0 -11
- package/src/doctor.test.ts +0 -74
- package/src/doctor.ts +0 -56
- package/src/group-intro.ts +0 -15
- package/src/group-policy.test.ts +0 -36
- package/src/group-policy.ts +0 -40
- package/src/group-session-contract.ts +0 -20
- package/src/group-session-key.test.ts +0 -53
- package/src/group-session-key.ts +0 -41
- package/src/heartbeat.ts +0 -34
- package/src/identity.ts +0 -164
- package/src/inbound/access-control.test-harness.ts +0 -37
- package/src/inbound/access-control.test.ts +0 -375
- package/src/inbound/access-control.ts +0 -237
- package/src/inbound/dedupe.ts +0 -132
- package/src/inbound/extract.test.ts +0 -282
- package/src/inbound/extract.ts +0 -488
- package/src/inbound/lifecycle.ts +0 -39
- package/src/inbound/media.node.test.ts +0 -83
- package/src/inbound/media.ts +0 -102
- package/src/inbound/monitor.ts +0 -890
- package/src/inbound/runtime-api.ts +0 -7
- package/src/inbound/save-media.runtime.ts +0 -1
- package/src/inbound/send-api.test.ts +0 -319
- package/src/inbound/send-api.ts +0 -145
- package/src/inbound/send-result.ts +0 -61
- package/src/inbound/types.ts +0 -106
- package/src/inbound-context.contract.test.ts +0 -32
- package/src/inbound-policy.ts +0 -231
- package/src/inbound.media.test.ts +0 -320
- package/src/inbound.test.ts +0 -290
- package/src/inbound.ts +0 -9
- package/src/login-qr.test.ts +0 -483
- package/src/login-qr.ts +0 -542
- package/src/login.coverage.test.ts +0 -133
- package/src/login.test.ts +0 -89
- package/src/login.ts +0 -70
- package/src/logout.test.ts +0 -162
- package/src/media.test.ts +0 -480
- package/src/media.ts +0 -10
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
- package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
- package/src/monitor-inbox.behavior.test.ts +0 -5
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
- package/src/monitor-inbox.test-harness.ts +0 -304
- package/src/normalize-target.ts +0 -123
- package/src/normalize.ts +0 -7
- package/src/outbound-adapter.poll.test.ts +0 -62
- package/src/outbound-adapter.sendpayload.test.ts +0 -195
- package/src/outbound-adapter.ts +0 -36
- package/src/outbound-base.test.ts +0 -560
- package/src/outbound-base.ts +0 -244
- package/src/outbound-media-contract.ts +0 -278
- package/src/outbound-media.runtime.ts +0 -36
- package/src/outbound-payload.contract.test.ts +0 -61
- package/src/outbound-send-deps.ts +0 -1
- package/src/outbound-test-support.ts +0 -16
- package/src/pairing-security.test-harness.ts +0 -59
- package/src/qr-image.ts +0 -1
- package/src/qr-terminal.ts +0 -1
- package/src/quoted-message.test.ts +0 -83
- package/src/quoted-message.ts +0 -184
- package/src/reaction-level.test.ts +0 -94
- package/src/reaction-level.ts +0 -21
- package/src/reconnect.test.ts +0 -51
- package/src/reconnect.ts +0 -55
- package/src/resolve-outbound-target.test.ts +0 -288
- package/src/resolve-outbound-target.ts +0 -58
- package/src/resolve-target.test.ts +0 -120
- package/src/runtime-api.ts +0 -59
- package/src/runtime-group-policy.ts +0 -16
- package/src/runtime.ts +0 -9
- package/src/security-contract.ts +0 -47
- package/src/security-fix.ts +0 -71
- package/src/send.test.ts +0 -534
- package/src/send.ts +0 -292
- package/src/session-contract.test.ts +0 -31
- package/src/session-contract.ts +0 -43
- package/src/session-errors.ts +0 -125
- package/src/session-route.test.ts +0 -41
- package/src/session-route.ts +0 -32
- package/src/session.runtime.ts +0 -8
- package/src/session.test.ts +0 -559
- package/src/session.ts +0 -330
- package/src/setup-core.ts +0 -52
- package/src/setup-finalize.ts +0 -446
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -69
- package/src/setup-test-helpers.ts +0 -216
- package/src/shared.ts +0 -291
- package/src/socket-timing.test.ts +0 -49
- package/src/socket-timing.ts +0 -38
- package/src/state-migrations.ts +0 -54
- package/src/status-issues.test.ts +0 -137
- package/src/status-issues.ts +0 -185
- package/src/system-prompt.test.ts +0 -199
- package/src/system-prompt.ts +0 -31
- package/src/targets-runtime.ts +0 -180
- package/src/test-helpers.ts +0 -690
- package/src/text-runtime.test.ts +0 -162
- package/src/text-runtime.ts +0 -11
- package/src/vcard.ts +0 -84
- package/targets.ts +0 -5
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
4
|
-
import { normalizeMainKey } from "openclaw/plugin-sdk/routing";
|
|
5
|
-
import { saveSessionStore } from "openclaw/plugin-sdk/session-store-runtime";
|
|
6
|
-
import { withTempDir } from "openclaw/plugin-sdk/test-env";
|
|
7
|
-
import { describe, expect, it, vi } from "vitest";
|
|
8
|
-
import type { WhatsAppSendResult } from "../inbound/send-result.js";
|
|
9
|
-
import {
|
|
10
|
-
evaluateSessionFreshness,
|
|
11
|
-
loadSessionStore,
|
|
12
|
-
resolveChannelResetConfig,
|
|
13
|
-
resolveSessionKey,
|
|
14
|
-
resolveSessionResetPolicy,
|
|
15
|
-
resolveSessionResetType,
|
|
16
|
-
resolveStorePath,
|
|
17
|
-
resolveThreadFlag,
|
|
18
|
-
} from "./config.runtime.js";
|
|
19
|
-
import {
|
|
20
|
-
debugMention,
|
|
21
|
-
isBotMentionedFromTargets,
|
|
22
|
-
resolveMentionTargets,
|
|
23
|
-
resolveOwnerList,
|
|
24
|
-
} from "./mentions.js";
|
|
25
|
-
import type { WebInboundMsg } from "./types.js";
|
|
26
|
-
import { elide, isLikelyWhatsAppCryptoError } from "./util.js";
|
|
27
|
-
|
|
28
|
-
function acceptedSendResult(kind: "media" | "text", id: string): WhatsAppSendResult {
|
|
29
|
-
return {
|
|
30
|
-
kind,
|
|
31
|
-
messageId: id,
|
|
32
|
-
messageIds: [id],
|
|
33
|
-
keys: [{ id }],
|
|
34
|
-
providerAccepted: true,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const makeMsg = (overrides: Partial<WebInboundMsg>): WebInboundMsg =>
|
|
39
|
-
({
|
|
40
|
-
id: "m1",
|
|
41
|
-
from: "120363401234567890@g.us",
|
|
42
|
-
conversationId: "120363401234567890@g.us",
|
|
43
|
-
to: "15551234567@s.whatsapp.net",
|
|
44
|
-
accountId: "default",
|
|
45
|
-
body: "",
|
|
46
|
-
chatType: "group",
|
|
47
|
-
chatId: "120363401234567890@g.us",
|
|
48
|
-
sendComposing: async () => {},
|
|
49
|
-
reply: async () => acceptedSendResult("text", "r1"),
|
|
50
|
-
sendMedia: async () => acceptedSendResult("media", "m1"),
|
|
51
|
-
...overrides,
|
|
52
|
-
}) as WebInboundMsg;
|
|
53
|
-
|
|
54
|
-
function getSessionSnapshotForTest(
|
|
55
|
-
cfg: OpenClawConfig,
|
|
56
|
-
from: string,
|
|
57
|
-
ctx?: {
|
|
58
|
-
sessionKey?: string | null;
|
|
59
|
-
isGroup?: boolean;
|
|
60
|
-
messageThreadId?: string | number | null;
|
|
61
|
-
threadLabel?: string | null;
|
|
62
|
-
threadStarterBody?: string | null;
|
|
63
|
-
parentSessionKey?: string | null;
|
|
64
|
-
},
|
|
65
|
-
) {
|
|
66
|
-
const sessionCfg = cfg.session;
|
|
67
|
-
const scope = sessionCfg?.scope ?? "per-sender";
|
|
68
|
-
const key =
|
|
69
|
-
ctx?.sessionKey?.trim() ??
|
|
70
|
-
resolveSessionKey(
|
|
71
|
-
scope,
|
|
72
|
-
{ From: from, To: "", Body: "" },
|
|
73
|
-
normalizeMainKey(sessionCfg?.mainKey),
|
|
74
|
-
);
|
|
75
|
-
const store = loadSessionStore(resolveStorePath(sessionCfg?.store));
|
|
76
|
-
const entry = store[key];
|
|
77
|
-
const isThread = resolveThreadFlag({
|
|
78
|
-
sessionKey: key,
|
|
79
|
-
messageThreadId: ctx?.messageThreadId ?? null,
|
|
80
|
-
threadLabel: ctx?.threadLabel ?? null,
|
|
81
|
-
threadStarterBody: ctx?.threadStarterBody ?? null,
|
|
82
|
-
parentSessionKey: ctx?.parentSessionKey ?? null,
|
|
83
|
-
});
|
|
84
|
-
const resetType = resolveSessionResetType({ sessionKey: key, isGroup: ctx?.isGroup, isThread });
|
|
85
|
-
const resetPolicy = resolveSessionResetPolicy({
|
|
86
|
-
sessionCfg,
|
|
87
|
-
resetType,
|
|
88
|
-
resetOverride: resolveChannelResetConfig({
|
|
89
|
-
sessionCfg,
|
|
90
|
-
channel: entry?.lastChannel ?? entry?.channel,
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
93
|
-
const freshness = entry
|
|
94
|
-
? evaluateSessionFreshness({ updatedAt: entry.updatedAt, now: Date.now(), policy: resetPolicy })
|
|
95
|
-
: { fresh: false };
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
key,
|
|
99
|
-
entry,
|
|
100
|
-
fresh: freshness.fresh,
|
|
101
|
-
resetPolicy,
|
|
102
|
-
resetType,
|
|
103
|
-
dailyResetAt: freshness.dailyResetAt,
|
|
104
|
-
idleExpiresAt: freshness.idleExpiresAt,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
describe("isBotMentionedFromTargets", () => {
|
|
109
|
-
const mentionCfg = { mentionRegexes: [/\bopenclaw\b/i] };
|
|
110
|
-
|
|
111
|
-
function expectMentioned(
|
|
112
|
-
msg: WebInboundMsg,
|
|
113
|
-
cfg: { mentionRegexes: RegExp[]; allowFrom?: Array<string | number>; isSelfChat?: boolean },
|
|
114
|
-
expected: boolean,
|
|
115
|
-
) {
|
|
116
|
-
const targets = resolveMentionTargets(msg);
|
|
117
|
-
expect(isBotMentionedFromTargets(msg, cfg, targets)).toBe(expected);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
it("ignores regex matches when other mentions are present", () => {
|
|
121
|
-
const msg = makeMsg({
|
|
122
|
-
body: "@OpenClaw please help",
|
|
123
|
-
mentionedJids: ["19998887777@s.whatsapp.net"],
|
|
124
|
-
selfE164: "+15551234567",
|
|
125
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
126
|
-
});
|
|
127
|
-
expectMentioned(msg, mentionCfg, false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("matches explicit self mentions", () => {
|
|
131
|
-
const msg = makeMsg({
|
|
132
|
-
body: "hey",
|
|
133
|
-
mentionedJids: ["15551234567@s.whatsapp.net"],
|
|
134
|
-
selfE164: "+15551234567",
|
|
135
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
136
|
-
});
|
|
137
|
-
expectMentioned(msg, mentionCfg, true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("falls back to regex when no mentions are present", () => {
|
|
141
|
-
const msg = makeMsg({
|
|
142
|
-
body: "openclaw can you help?",
|
|
143
|
-
selfE164: "+15551234567",
|
|
144
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
145
|
-
});
|
|
146
|
-
expectMentioned(msg, mentionCfg, true);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("ignores JID mentions in a true 1:1 self-chat (not a group)", () => {
|
|
150
|
-
const cfg = { mentionRegexes: [/\bopenclaw\b/i], allowFrom: ["+999"] };
|
|
151
|
-
const msg = makeMsg({
|
|
152
|
-
// Direct chat with self, not a group — the original "ignore mentions
|
|
153
|
-
// in self-chat" suppression still applies here so that mentioning the
|
|
154
|
-
// owner in their own DM does not falsely trigger the bot.
|
|
155
|
-
from: "999@s.whatsapp.net",
|
|
156
|
-
conversationId: "999@s.whatsapp.net",
|
|
157
|
-
chatType: "direct",
|
|
158
|
-
body: "@owner ping",
|
|
159
|
-
mentionedJids: ["999@s.whatsapp.net"],
|
|
160
|
-
selfE164: "+999",
|
|
161
|
-
selfJid: "999@s.whatsapp.net",
|
|
162
|
-
});
|
|
163
|
-
expectMentioned(msg, cfg, false);
|
|
164
|
-
|
|
165
|
-
const msgTextMention = makeMsg({
|
|
166
|
-
from: "999@s.whatsapp.net",
|
|
167
|
-
conversationId: "999@s.whatsapp.net",
|
|
168
|
-
chatType: "direct",
|
|
169
|
-
body: "openclaw ping",
|
|
170
|
-
selfE164: "+999",
|
|
171
|
-
selfJid: "999@s.whatsapp.net",
|
|
172
|
-
});
|
|
173
|
-
expectMentioned(msgTextMention, cfg, true);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("detects an explicit group @mention even when self is in allowFrom (#49317)", () => {
|
|
177
|
-
// Operator config commonly puts their own E.164 in allowFrom so they can
|
|
178
|
-
// run owner-only commands in groups; previously, that flipped the gate
|
|
179
|
-
// to "self-chat mode" and silently dropped mention detection in groups,
|
|
180
|
-
// including LID-style WhatsApp mentions that resolve to the bot's own
|
|
181
|
-
// E.164. After the fix, group conversations honor the identity-overlap
|
|
182
|
-
// check regardless of allowFrom.
|
|
183
|
-
const cfg = { mentionRegexes: [/\bopenclaw\b/i], allowFrom: ["+15551234567"] };
|
|
184
|
-
const msg = makeMsg({
|
|
185
|
-
// Default `from` is the @g.us group JID from `makeMsg`.
|
|
186
|
-
body: "@216372600647751 can you see this?",
|
|
187
|
-
mentionedJids: ["216372600647751@lid"],
|
|
188
|
-
selfE164: "+15551234567",
|
|
189
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
190
|
-
selfLid: "216372600647751@lid",
|
|
191
|
-
});
|
|
192
|
-
expectMentioned(msg, cfg, true);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("honors explicit self-chat overrides without recomputing from allowFrom", () => {
|
|
196
|
-
const cfg = {
|
|
197
|
-
mentionRegexes: [/\bopenclaw\b/i],
|
|
198
|
-
allowFrom: ["+15551230000"],
|
|
199
|
-
isSelfChat: true,
|
|
200
|
-
};
|
|
201
|
-
const msg = makeMsg({
|
|
202
|
-
body: "@owner ping",
|
|
203
|
-
mentionedJids: ["999@s.whatsapp.net"],
|
|
204
|
-
selfE164: "+999",
|
|
205
|
-
selfJid: "999@s.whatsapp.net",
|
|
206
|
-
});
|
|
207
|
-
expectMentioned(msg, cfg, false);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it("matches fallback number mentions when regexes do not match", () => {
|
|
211
|
-
const msg = makeMsg({
|
|
212
|
-
body: "please check +1 555 123 4567",
|
|
213
|
-
selfE164: "+15551234567",
|
|
214
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
215
|
-
});
|
|
216
|
-
expectMentioned(msg, { mentionRegexes: [] }, true);
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe("resolveMentionTargets with @lid mapping", () => {
|
|
221
|
-
it("uses @lid reverse mapping for mentions and self identity", async () => {
|
|
222
|
-
await withTempDir("openclaw-lid-mapping-", async (authDir) => {
|
|
223
|
-
await fs.writeFile(
|
|
224
|
-
path.join(authDir, "lid-mapping-777_reverse.json"),
|
|
225
|
-
JSON.stringify("+1777"),
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
const mentionTargets = resolveMentionTargets(
|
|
229
|
-
makeMsg({
|
|
230
|
-
body: "ping",
|
|
231
|
-
mentionedJids: ["777@lid"],
|
|
232
|
-
selfE164: "+15551234567",
|
|
233
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
234
|
-
}),
|
|
235
|
-
authDir,
|
|
236
|
-
);
|
|
237
|
-
expect(mentionTargets.normalizedMentions).toEqual([
|
|
238
|
-
expect.objectContaining({
|
|
239
|
-
jid: null,
|
|
240
|
-
lid: "777@lid",
|
|
241
|
-
e164: "+1777",
|
|
242
|
-
}),
|
|
243
|
-
]);
|
|
244
|
-
|
|
245
|
-
const selfTargets = resolveMentionTargets(
|
|
246
|
-
makeMsg({
|
|
247
|
-
body: "ping",
|
|
248
|
-
selfJid: "777@lid",
|
|
249
|
-
}),
|
|
250
|
-
authDir,
|
|
251
|
-
);
|
|
252
|
-
expect(selfTargets.self.e164).toBe("+1777");
|
|
253
|
-
expect(selfTargets.self.lid).toBe("777@lid");
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
describe("getSessionSnapshot", () => {
|
|
259
|
-
it("uses channel reset overrides when configured", async () => {
|
|
260
|
-
vi.useFakeTimers();
|
|
261
|
-
vi.setSystemTime(new Date(2026, 0, 18, 5, 0, 0));
|
|
262
|
-
try {
|
|
263
|
-
await withTempDir("openclaw-snapshot-", async (root) => {
|
|
264
|
-
const storePath = path.join(root, "sessions.json");
|
|
265
|
-
const sessionKey = "agent:main:whatsapp:dm:s1";
|
|
266
|
-
|
|
267
|
-
await saveSessionStore(storePath, {
|
|
268
|
-
[sessionKey]: {
|
|
269
|
-
sessionId: "snapshot-session",
|
|
270
|
-
updatedAt: new Date(2026, 0, 18, 3, 30, 0).getTime(),
|
|
271
|
-
lastChannel: "whatsapp",
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
const cfg = {
|
|
276
|
-
session: {
|
|
277
|
-
store: storePath,
|
|
278
|
-
reset: { mode: "daily", atHour: 4, idleMinutes: 240 },
|
|
279
|
-
resetByChannel: {
|
|
280
|
-
whatsapp: { mode: "idle", idleMinutes: 360 },
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
} as OpenClawConfig;
|
|
284
|
-
|
|
285
|
-
const snapshot = getSessionSnapshotForTest(cfg, "whatsapp:+15550001111", {
|
|
286
|
-
sessionKey,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(snapshot.resetPolicy.mode).toBe("idle");
|
|
290
|
-
expect(snapshot.resetPolicy.idleMinutes).toBe(360);
|
|
291
|
-
expect(snapshot.fresh).toBe(true);
|
|
292
|
-
expect(snapshot.dailyResetAt).toBeUndefined();
|
|
293
|
-
});
|
|
294
|
-
} finally {
|
|
295
|
-
vi.useRealTimers();
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe("web auto-reply util", () => {
|
|
301
|
-
describe("mentions diagnostics", () => {
|
|
302
|
-
it("returns normalized debug fields and mention outcome", () => {
|
|
303
|
-
const msg = makeMsg({
|
|
304
|
-
from: "777@lid",
|
|
305
|
-
body: "openclaw ping",
|
|
306
|
-
selfE164: "+15551234567",
|
|
307
|
-
selfJid: "15551234567@s.whatsapp.net",
|
|
308
|
-
});
|
|
309
|
-
const result = debugMention(msg, { mentionRegexes: [/\bopenclaw\b/i] });
|
|
310
|
-
expect(result.wasMentioned).toBe(true);
|
|
311
|
-
expect(result.details.bodyClean).toBe("openclaw ping");
|
|
312
|
-
expect(result.details.normalizedMentionedJids).toBeNull();
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("resolves owner list from allowFrom or falls back to self", () => {
|
|
316
|
-
expect(
|
|
317
|
-
resolveOwnerList(
|
|
318
|
-
{
|
|
319
|
-
mentionRegexes: [],
|
|
320
|
-
allowFrom: ["*", " +1 555 000 1111 "],
|
|
321
|
-
},
|
|
322
|
-
null,
|
|
323
|
-
),
|
|
324
|
-
).toEqual(["+15550001111"]);
|
|
325
|
-
expect(resolveOwnerList({ mentionRegexes: [] }, "+1 555 000 2222")).toEqual(["+15550002222"]);
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
describe("elide", () => {
|
|
330
|
-
it("returns undefined for undefined input", () => {
|
|
331
|
-
expect(elide(undefined)).toBe(undefined);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("returns input when under limit", () => {
|
|
335
|
-
expect(elide("hi", 10)).toBe("hi");
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it("truncates and annotates when over limit", () => {
|
|
339
|
-
expect(elide("abcdef", 3)).toBe("abc… (truncated 3 chars)");
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
describe("isLikelyWhatsAppCryptoError", () => {
|
|
344
|
-
it("matches known Baileys crypto auth errors (Error)", () => {
|
|
345
|
-
const err = new Error("bad mac");
|
|
346
|
-
err.stack = "at something\nat @whiskeysockets/baileys/noise-handler\n";
|
|
347
|
-
expect(isLikelyWhatsAppCryptoError(err)).toBe(true);
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it("does not throw on circular objects", () => {
|
|
351
|
-
const circular: Record<string, unknown> = {};
|
|
352
|
-
circular.self = circular;
|
|
353
|
-
expect(isLikelyWhatsAppCryptoError(circular)).toBe(false);
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
const cases: Array<{ name: string; value: unknown; expected: boolean }> = [
|
|
357
|
-
{ name: "returns false for non-matching Error", value: new Error("boom"), expected: false },
|
|
358
|
-
{ name: "returns false for non-matching string", value: "boom", expected: false },
|
|
359
|
-
{
|
|
360
|
-
name: "returns false for bad-mac object without whatsapp/baileys markers",
|
|
361
|
-
value: { message: "bad mac" },
|
|
362
|
-
expected: false,
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
name: "matches known Baileys crypto auth errors (string, unsupported state)",
|
|
366
|
-
value: "baileys: unsupported state or unable to authenticate data (noise-handler)",
|
|
367
|
-
expected: true,
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
name: "matches known Baileys crypto auth errors (string, bad mac)",
|
|
371
|
-
value: "bad mac in aesDecryptGCM (baileys)",
|
|
372
|
-
expected: true,
|
|
373
|
-
},
|
|
374
|
-
{ name: "handles null reason without throwing", value: null, expected: false },
|
|
375
|
-
{ name: "handles number reason without throwing", value: 123, expected: false },
|
|
376
|
-
{ name: "handles boolean reason without throwing", value: true, expected: false },
|
|
377
|
-
{ name: "handles bigint reason without throwing", value: 123n, expected: false },
|
|
378
|
-
{ name: "handles symbol reason without throwing", value: Symbol("bad mac"), expected: false },
|
|
379
|
-
{
|
|
380
|
-
name: "handles function reason without throwing",
|
|
381
|
-
value: function namedFn() {},
|
|
382
|
-
expected: false,
|
|
383
|
-
},
|
|
384
|
-
];
|
|
385
|
-
|
|
386
|
-
for (const testCase of cases) {
|
|
387
|
-
it(testCase.name, () => {
|
|
388
|
-
expect(isLikelyWhatsAppCryptoError(testCase.value)).toBe(testCase.expected);
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
});
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import "./test-helpers.js";
|
|
2
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
3
|
-
import { describe, expect, it, vi } from "vitest";
|
|
4
|
-
import {
|
|
5
|
-
monitorWebChannelWithCapture,
|
|
6
|
-
sendWebDirectInboundAndCollectSessionKeys,
|
|
7
|
-
} from "./auto-reply.broadcast-groups.test-harness.js";
|
|
8
|
-
import {
|
|
9
|
-
createAcceptedWhatsAppSendResult,
|
|
10
|
-
installWebAutoReplyTestHomeHooks,
|
|
11
|
-
installWebAutoReplyUnitTestHooks,
|
|
12
|
-
resetLoadConfigMock,
|
|
13
|
-
sendWebGroupInboundMessage,
|
|
14
|
-
setLoadConfigMock,
|
|
15
|
-
} from "./auto-reply.test-harness.js";
|
|
16
|
-
|
|
17
|
-
installWebAutoReplyTestHomeHooks();
|
|
18
|
-
|
|
19
|
-
describe("broadcast groups", () => {
|
|
20
|
-
installWebAutoReplyUnitTestHooks();
|
|
21
|
-
|
|
22
|
-
it("skips unknown broadcast agent ids when agents.list is present", async () => {
|
|
23
|
-
setLoadConfigMock({
|
|
24
|
-
channels: { whatsapp: { allowFrom: ["*"] } },
|
|
25
|
-
agents: {
|
|
26
|
-
defaults: { maxConcurrent: 10 },
|
|
27
|
-
list: [{ id: "alfred" }],
|
|
28
|
-
},
|
|
29
|
-
broadcast: {
|
|
30
|
-
"+1000": ["alfred", "missing"],
|
|
31
|
-
},
|
|
32
|
-
} satisfies OpenClawConfig);
|
|
33
|
-
|
|
34
|
-
const { seen, resolver } = await sendWebDirectInboundAndCollectSessionKeys();
|
|
35
|
-
|
|
36
|
-
expect(resolver).toHaveBeenCalledTimes(1);
|
|
37
|
-
expect(seen[0]).toContain("agent:alfred:");
|
|
38
|
-
resetLoadConfigMock();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("broadcasts sequentially in configured order", async () => {
|
|
42
|
-
setLoadConfigMock({
|
|
43
|
-
channels: { whatsapp: { allowFrom: ["*"] } },
|
|
44
|
-
agents: {
|
|
45
|
-
defaults: { maxConcurrent: 10 },
|
|
46
|
-
list: [{ id: "alfred" }, { id: "baerbel" }],
|
|
47
|
-
},
|
|
48
|
-
broadcast: {
|
|
49
|
-
strategy: "sequential",
|
|
50
|
-
"+1000": ["alfred", "baerbel"],
|
|
51
|
-
},
|
|
52
|
-
} satisfies OpenClawConfig);
|
|
53
|
-
|
|
54
|
-
const { seen, resolver } = await sendWebDirectInboundAndCollectSessionKeys();
|
|
55
|
-
|
|
56
|
-
expect(resolver).toHaveBeenCalledTimes(2);
|
|
57
|
-
expect(seen[0]).toContain("agent:alfred:");
|
|
58
|
-
expect(seen[1]).toContain("agent:baerbel:");
|
|
59
|
-
resetLoadConfigMock();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("shares group history across broadcast agents and clears after replying", async () => {
|
|
63
|
-
setLoadConfigMock({
|
|
64
|
-
channels: { whatsapp: { allowFrom: ["*"] } },
|
|
65
|
-
agents: {
|
|
66
|
-
defaults: { maxConcurrent: 10 },
|
|
67
|
-
list: [{ id: "alfred" }, { id: "baerbel" }],
|
|
68
|
-
},
|
|
69
|
-
broadcast: {
|
|
70
|
-
strategy: "sequential",
|
|
71
|
-
"123@g.us": ["alfred", "baerbel"],
|
|
72
|
-
},
|
|
73
|
-
} satisfies OpenClawConfig);
|
|
74
|
-
|
|
75
|
-
const resolver = vi.fn().mockResolvedValue({ text: "ok" });
|
|
76
|
-
|
|
77
|
-
const { spies, onMessage } = await monitorWebChannelWithCapture(resolver);
|
|
78
|
-
|
|
79
|
-
await sendWebGroupInboundMessage({
|
|
80
|
-
onMessage,
|
|
81
|
-
spies,
|
|
82
|
-
body: "hello group",
|
|
83
|
-
id: "g1",
|
|
84
|
-
senderE164: "+111",
|
|
85
|
-
senderName: "Alice",
|
|
86
|
-
selfE164: "+999",
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(resolver).not.toHaveBeenCalled();
|
|
90
|
-
|
|
91
|
-
await sendWebGroupInboundMessage({
|
|
92
|
-
onMessage,
|
|
93
|
-
spies,
|
|
94
|
-
body: "@bot ping",
|
|
95
|
-
id: "g2",
|
|
96
|
-
senderE164: "+222",
|
|
97
|
-
senderName: "Bob",
|
|
98
|
-
mentionedJids: ["999@s.whatsapp.net"],
|
|
99
|
-
selfE164: "+999",
|
|
100
|
-
selfJid: "999@s.whatsapp.net",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
expect(resolver).toHaveBeenCalledTimes(2);
|
|
104
|
-
for (const call of resolver.mock.calls.slice(0, 2)) {
|
|
105
|
-
const payload = call[0] as {
|
|
106
|
-
Body: string;
|
|
107
|
-
SenderName?: string;
|
|
108
|
-
SenderE164?: string;
|
|
109
|
-
SenderId?: string;
|
|
110
|
-
};
|
|
111
|
-
expect(payload.Body).toContain("Chat messages since your last reply");
|
|
112
|
-
expect(payload.Body).toContain("Alice (+111): hello group");
|
|
113
|
-
expect(payload.Body).not.toContain("[message_id:");
|
|
114
|
-
expect(payload.Body).toContain("@bot ping");
|
|
115
|
-
expect(payload.SenderName).toBe("Bob");
|
|
116
|
-
expect(payload.SenderE164).toBe("+222");
|
|
117
|
-
expect(payload.SenderId).toBe("+222");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
await sendWebGroupInboundMessage({
|
|
121
|
-
onMessage,
|
|
122
|
-
spies,
|
|
123
|
-
body: "@bot ping 2",
|
|
124
|
-
id: "g3",
|
|
125
|
-
senderE164: "+333",
|
|
126
|
-
senderName: "Clara",
|
|
127
|
-
mentionedJids: ["999@s.whatsapp.net"],
|
|
128
|
-
selfE164: "+999",
|
|
129
|
-
selfJid: "999@s.whatsapp.net",
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
expect(resolver).toHaveBeenCalledTimes(4);
|
|
133
|
-
for (const call of resolver.mock.calls.slice(2, 4)) {
|
|
134
|
-
const payload = call[0] as { Body: string };
|
|
135
|
-
expect(payload.Body).not.toContain("Alice (+111): hello group");
|
|
136
|
-
expect(payload.Body).not.toContain("Chat messages since your last reply");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
resetLoadConfigMock();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("keeps named-account group broadcast routes on the scoped session key", async () => {
|
|
143
|
-
setLoadConfigMock({
|
|
144
|
-
channels: {
|
|
145
|
-
whatsapp: {
|
|
146
|
-
allowFrom: ["*"],
|
|
147
|
-
accounts: {
|
|
148
|
-
work: {
|
|
149
|
-
allowFrom: ["*"],
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
agents: {
|
|
155
|
-
defaults: { maxConcurrent: 10 },
|
|
156
|
-
list: [{ id: "alfred" }, { id: "baerbel" }],
|
|
157
|
-
},
|
|
158
|
-
broadcast: {
|
|
159
|
-
strategy: "sequential",
|
|
160
|
-
"123@g.us": ["alfred", "baerbel"],
|
|
161
|
-
},
|
|
162
|
-
} satisfies OpenClawConfig);
|
|
163
|
-
|
|
164
|
-
const seen: string[] = [];
|
|
165
|
-
const resolver = vi.fn(async (ctx: { SessionKey?: unknown }) => {
|
|
166
|
-
seen.push(String(ctx.SessionKey));
|
|
167
|
-
return { text: "ok" };
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const { spies, onMessage } = await monitorWebChannelWithCapture(resolver);
|
|
171
|
-
|
|
172
|
-
await sendWebGroupInboundMessage({
|
|
173
|
-
onMessage,
|
|
174
|
-
spies,
|
|
175
|
-
body: "@bot ping",
|
|
176
|
-
id: "g-work-1",
|
|
177
|
-
senderE164: "+111",
|
|
178
|
-
senderName: "Alice",
|
|
179
|
-
mentionedJids: ["999@s.whatsapp.net"],
|
|
180
|
-
selfE164: "+999",
|
|
181
|
-
selfJid: "999@s.whatsapp.net",
|
|
182
|
-
accountId: "work",
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
expect(resolver).toHaveBeenCalledTimes(2);
|
|
186
|
-
expect(seen).toEqual([
|
|
187
|
-
"agent:alfred:whatsapp:group:123@g.us:thread:whatsapp-account-work",
|
|
188
|
-
"agent:baerbel:whatsapp:group:123@g.us:thread:whatsapp-account-work",
|
|
189
|
-
]);
|
|
190
|
-
resetLoadConfigMock();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("broadcasts in parallel by default", async () => {
|
|
194
|
-
setLoadConfigMock({
|
|
195
|
-
channels: { whatsapp: { allowFrom: ["*"] } },
|
|
196
|
-
agents: {
|
|
197
|
-
defaults: { maxConcurrent: 10 },
|
|
198
|
-
list: [{ id: "alfred" }, { id: "baerbel" }],
|
|
199
|
-
},
|
|
200
|
-
broadcast: {
|
|
201
|
-
strategy: "parallel",
|
|
202
|
-
"+1000": ["alfred", "baerbel"],
|
|
203
|
-
},
|
|
204
|
-
} satisfies OpenClawConfig);
|
|
205
|
-
|
|
206
|
-
const sendMedia = vi.fn().mockResolvedValue(createAcceptedWhatsAppSendResult("media", "m1"));
|
|
207
|
-
const reply = vi.fn().mockResolvedValue(createAcceptedWhatsAppSendResult("text", "r1"));
|
|
208
|
-
const sendComposing = vi.fn();
|
|
209
|
-
|
|
210
|
-
let started = 0;
|
|
211
|
-
let release: (() => void) | undefined;
|
|
212
|
-
const gate = new Promise<void>((resolve) => {
|
|
213
|
-
release = resolve;
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const resolver = vi.fn(async () => {
|
|
217
|
-
started += 1;
|
|
218
|
-
if (started < 2) {
|
|
219
|
-
await gate;
|
|
220
|
-
} else {
|
|
221
|
-
release?.();
|
|
222
|
-
}
|
|
223
|
-
return { text: "ok" };
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const { onMessage: capturedOnMessage } = await monitorWebChannelWithCapture(resolver);
|
|
227
|
-
|
|
228
|
-
await capturedOnMessage({
|
|
229
|
-
id: "m1",
|
|
230
|
-
from: "+1000",
|
|
231
|
-
conversationId: "+1000",
|
|
232
|
-
to: "+2000",
|
|
233
|
-
accountId: "default",
|
|
234
|
-
body: "hello",
|
|
235
|
-
timestamp: Date.now(),
|
|
236
|
-
chatType: "direct",
|
|
237
|
-
chatId: "direct:+1000",
|
|
238
|
-
sendComposing,
|
|
239
|
-
reply,
|
|
240
|
-
sendMedia,
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
expect(resolver).toHaveBeenCalledTimes(2);
|
|
244
|
-
resetLoadConfigMock();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createWebInboundDeliverySpies,
|
|
4
|
-
createWebListenerFactoryCapture,
|
|
5
|
-
sendWebDirectInboundMessage,
|
|
6
|
-
} from "./auto-reply.test-harness.js";
|
|
7
|
-
import { monitorWebChannel } from "./auto-reply/monitor.js";
|
|
8
|
-
import type { WebInboundMessage } from "./inbound.js";
|
|
9
|
-
|
|
10
|
-
export async function monitorWebChannelWithCapture(resolver: unknown): Promise<{
|
|
11
|
-
spies: ReturnType<typeof createWebInboundDeliverySpies>;
|
|
12
|
-
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
|
13
|
-
}> {
|
|
14
|
-
const spies = createWebInboundDeliverySpies();
|
|
15
|
-
const { listenerFactory, getOnMessage } = createWebListenerFactoryCapture();
|
|
16
|
-
|
|
17
|
-
await monitorWebChannel(false, listenerFactory, false, resolver as never);
|
|
18
|
-
const onMessage = getOnMessage();
|
|
19
|
-
if (!onMessage) {
|
|
20
|
-
throw new Error("Missing onMessage handler");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return { spies, onMessage };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function sendWebDirectInboundAndCollectSessionKeys(): Promise<{
|
|
27
|
-
seen: string[];
|
|
28
|
-
resolver: ReturnType<typeof vi.fn>;
|
|
29
|
-
}> {
|
|
30
|
-
const seen: string[] = [];
|
|
31
|
-
const resolver = vi.fn(async (ctx: { SessionKey?: unknown }) => {
|
|
32
|
-
seen.push(String(ctx.SessionKey));
|
|
33
|
-
return { text: "ok" };
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const { spies, onMessage } = await monitorWebChannelWithCapture(resolver);
|
|
37
|
-
await sendWebDirectInboundMessage({
|
|
38
|
-
onMessage,
|
|
39
|
-
spies,
|
|
40
|
-
id: "m1",
|
|
41
|
-
from: "+1000",
|
|
42
|
-
to: "+2000",
|
|
43
|
-
body: "hello",
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return { seen, resolver };
|
|
47
|
-
}
|
package/src/auto-reply.impl.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { HEARTBEAT_PROMPT, stripHeartbeatToken } from "openclaw/plugin-sdk/reply-runtime";
|
|
2
|
-
export { HEARTBEAT_TOKEN, SILENT_REPLY_TOKEN } from "openclaw/plugin-sdk/reply-runtime";
|
|
3
|
-
|
|
4
|
-
export { DEFAULT_WEB_MEDIA_BYTES } from "./auto-reply/constants.js";
|
|
5
|
-
export { monitorWebChannel } from "./auto-reply/monitor.js";
|
|
6
|
-
export type { WebChannelStatus, WebMonitorTuning } from "./auto-reply/types.js";
|