@openclaw/whatsapp 2026.5.2-beta.2 → 2026.5.3-beta.1
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 -334
- 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 -307
- package/src/inbound/send-api.ts +0 -141
- 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 -112
- package/src/normalize.ts +0 -6
- 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 -265
- package/src/resolve-outbound-target.ts +0 -54
- package/src/resolve-target.test.ts +0 -97
- 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 -515
- package/src/send.ts +0 -287
- 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.ts +0 -26
- 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
package/src/status-issues.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ChannelAccountSnapshot,
|
|
3
|
-
ChannelStatusIssue,
|
|
4
|
-
} from "openclaw/plugin-sdk/channel-contract";
|
|
5
|
-
import { formatCliCommand } from "openclaw/plugin-sdk/cli-runtime";
|
|
6
|
-
import {
|
|
7
|
-
asString,
|
|
8
|
-
collectIssuesForEnabledAccounts,
|
|
9
|
-
isRecord,
|
|
10
|
-
} from "openclaw/plugin-sdk/status-helpers";
|
|
11
|
-
|
|
12
|
-
type WhatsAppAccountStatus = {
|
|
13
|
-
accountId?: unknown;
|
|
14
|
-
statusState?: unknown;
|
|
15
|
-
enabled?: unknown;
|
|
16
|
-
linked?: unknown;
|
|
17
|
-
connected?: unknown;
|
|
18
|
-
running?: unknown;
|
|
19
|
-
reconnectAttempts?: unknown;
|
|
20
|
-
lastDisconnect?: unknown;
|
|
21
|
-
lastInboundAt?: unknown;
|
|
22
|
-
lastError?: unknown;
|
|
23
|
-
healthState?: unknown;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const RECENT_DISCONNECT_WARNING_WINDOW_MS = 15 * 60 * 1000;
|
|
27
|
-
|
|
28
|
-
function readWhatsAppAccountStatus(value: ChannelAccountSnapshot): WhatsAppAccountStatus | null {
|
|
29
|
-
if (!isRecord(value)) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
accountId: value.accountId,
|
|
34
|
-
statusState: value.statusState,
|
|
35
|
-
enabled: value.enabled,
|
|
36
|
-
linked: value.linked,
|
|
37
|
-
connected: value.connected,
|
|
38
|
-
running: value.running,
|
|
39
|
-
reconnectAttempts: value.reconnectAttempts,
|
|
40
|
-
lastDisconnect: value.lastDisconnect,
|
|
41
|
-
lastInboundAt: value.lastInboundAt,
|
|
42
|
-
lastError: value.lastError,
|
|
43
|
-
healthState: value.healthState,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function readLastDisconnect(value: unknown): { at: number | null; error?: string } | null {
|
|
48
|
-
if (typeof value === "string") {
|
|
49
|
-
const error = asString(value);
|
|
50
|
-
return error ? { at: null, error } : null;
|
|
51
|
-
}
|
|
52
|
-
if (!isRecord(value)) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
at: typeof value.at === "number" ? value.at : null,
|
|
57
|
-
error: asString(value.error),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isRecentDisconnect(disconnect: { at: number | null } | null, now = Date.now()): boolean {
|
|
62
|
-
if (disconnect?.at == null) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return now - disconnect.at <= RECENT_DISCONNECT_WARNING_WINDOW_MS;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function collectWhatsAppStatusIssues(
|
|
69
|
-
accounts: ChannelAccountSnapshot[],
|
|
70
|
-
): ChannelStatusIssue[] {
|
|
71
|
-
return collectIssuesForEnabledAccounts({
|
|
72
|
-
accounts,
|
|
73
|
-
readAccount: readWhatsAppAccountStatus,
|
|
74
|
-
collectIssues: ({ account, accountId, issues }) => {
|
|
75
|
-
const linked = account.linked === true;
|
|
76
|
-
const statusState = asString(account.statusState);
|
|
77
|
-
const running = account.running === true;
|
|
78
|
-
const connected = account.connected === true;
|
|
79
|
-
const reconnectAttempts =
|
|
80
|
-
typeof account.reconnectAttempts === "number" ? account.reconnectAttempts : null;
|
|
81
|
-
const lastInboundAt =
|
|
82
|
-
typeof account.lastInboundAt === "number" ? account.lastInboundAt : null;
|
|
83
|
-
const lastDisconnect = readLastDisconnect(account.lastDisconnect);
|
|
84
|
-
const lastError = asString(account.lastError) ?? lastDisconnect?.error;
|
|
85
|
-
const healthState = asString(account.healthState);
|
|
86
|
-
|
|
87
|
-
if (statusState === "unstable") {
|
|
88
|
-
issues.push({
|
|
89
|
-
channel: "whatsapp",
|
|
90
|
-
accountId,
|
|
91
|
-
kind: "auth",
|
|
92
|
-
message: "Auth state is still stabilizing.",
|
|
93
|
-
fix: "Wait a moment for queued credential writes to finish, then retry the command or rerun health.",
|
|
94
|
-
});
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!linked) {
|
|
99
|
-
issues.push({
|
|
100
|
-
channel: "whatsapp",
|
|
101
|
-
accountId,
|
|
102
|
-
kind: "auth",
|
|
103
|
-
message: "Not linked (no WhatsApp Web session).",
|
|
104
|
-
fix: `Run: ${formatCliCommand("openclaw channels login")} (scan QR on the gateway host).`,
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (healthState === "stale") {
|
|
110
|
-
const staleSuffix =
|
|
111
|
-
lastInboundAt != null
|
|
112
|
-
? ` (last inbound ${Math.max(0, Math.floor((Date.now() - lastInboundAt) / 60000))}m ago)`
|
|
113
|
-
: "";
|
|
114
|
-
issues.push({
|
|
115
|
-
channel: "whatsapp",
|
|
116
|
-
accountId,
|
|
117
|
-
kind: "runtime",
|
|
118
|
-
message: `Linked but stale${staleSuffix}${lastError ? `: ${lastError}` : "."}`,
|
|
119
|
-
fix: `Run: ${formatCliCommand("openclaw doctor")} (or restart the gateway). If it persists, relink via channels login and check logs.`,
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
healthState === "reconnecting" ||
|
|
126
|
-
healthState === "conflict" ||
|
|
127
|
-
healthState === "stopped"
|
|
128
|
-
) {
|
|
129
|
-
const stateLabel =
|
|
130
|
-
healthState === "conflict"
|
|
131
|
-
? "session conflict"
|
|
132
|
-
: healthState === "reconnecting"
|
|
133
|
-
? "reconnecting"
|
|
134
|
-
: "stopped";
|
|
135
|
-
issues.push({
|
|
136
|
-
channel: "whatsapp",
|
|
137
|
-
accountId,
|
|
138
|
-
kind: "runtime",
|
|
139
|
-
message: `Linked but ${stateLabel}${reconnectAttempts != null ? ` (reconnectAttempts=${reconnectAttempts})` : ""}${lastError ? `: ${lastError}` : "."}`,
|
|
140
|
-
fix: `Run: ${formatCliCommand("openclaw doctor")} (or restart the gateway). If it persists, relink via channels login and check logs.`,
|
|
141
|
-
});
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (healthState === "logged-out") {
|
|
146
|
-
issues.push({
|
|
147
|
-
channel: "whatsapp",
|
|
148
|
-
accountId,
|
|
149
|
-
kind: "auth",
|
|
150
|
-
message: `Linked session logged out${lastError ? `: ${lastError}` : "."}`,
|
|
151
|
-
fix: `Run: ${formatCliCommand("openclaw channels login")} (scan QR on the gateway host).`,
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
linked &&
|
|
158
|
-
running &&
|
|
159
|
-
connected &&
|
|
160
|
-
reconnectAttempts != null &&
|
|
161
|
-
reconnectAttempts > 0 &&
|
|
162
|
-
isRecentDisconnect(lastDisconnect)
|
|
163
|
-
) {
|
|
164
|
-
issues.push({
|
|
165
|
-
channel: "whatsapp",
|
|
166
|
-
accountId,
|
|
167
|
-
kind: "runtime",
|
|
168
|
-
message: `Linked but recently reconnected (reconnectAttempts=${reconnectAttempts})${lastError ? `: ${lastError}` : "."}`,
|
|
169
|
-
fix: `Watch: ${formatCliCommand("openclaw logs --follow")} and run ${formatCliCommand("openclaw channels status --probe")} if disconnects continue. If it keeps flapping, restart the gateway or relink via channels login.`,
|
|
170
|
-
});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (running && !connected) {
|
|
175
|
-
issues.push({
|
|
176
|
-
channel: "whatsapp",
|
|
177
|
-
accountId,
|
|
178
|
-
kind: "runtime",
|
|
179
|
-
message: `Linked but disconnected${reconnectAttempts != null ? ` (reconnectAttempts=${reconnectAttempts})` : ""}${lastError ? `: ${lastError}` : "."}`,
|
|
180
|
-
fix: `Run: ${formatCliCommand("openclaw doctor")} (or restart the gateway). If it persists, relink via channels login and check logs.`,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
resolveWhatsAppDirectSystemPrompt,
|
|
4
|
-
resolveWhatsAppGroupSystemPrompt,
|
|
5
|
-
} from "./system-prompt.js";
|
|
6
|
-
|
|
7
|
-
describe("resolveWhatsAppGroupSystemPrompt", () => {
|
|
8
|
-
it("returns undefined when groupId is absent", () => {
|
|
9
|
-
expect(resolveWhatsAppGroupSystemPrompt({ groupId: null })).toBeUndefined();
|
|
10
|
-
expect(resolveWhatsAppGroupSystemPrompt({ groupId: undefined })).toBeUndefined();
|
|
11
|
-
expect(resolveWhatsAppGroupSystemPrompt({})).toBeUndefined();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("returns undefined when accountConfig is absent", () => {
|
|
15
|
-
expect(
|
|
16
|
-
resolveWhatsAppGroupSystemPrompt({ groupId: "g1", accountConfig: null }),
|
|
17
|
-
).toBeUndefined();
|
|
18
|
-
expect(
|
|
19
|
-
resolveWhatsAppGroupSystemPrompt({ groupId: "g1", accountConfig: undefined }),
|
|
20
|
-
).toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("returns the group-specific systemPrompt when defined", () => {
|
|
24
|
-
expect(
|
|
25
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
26
|
-
groupId: "g1",
|
|
27
|
-
accountConfig: { groups: { g1: { systemPrompt: "group prompt" } } },
|
|
28
|
-
}),
|
|
29
|
-
).toBe("group prompt");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("falls back to wildcard when specific group entry is absent", () => {
|
|
33
|
-
expect(
|
|
34
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
35
|
-
groupId: "g1",
|
|
36
|
-
accountConfig: {
|
|
37
|
-
groups: { "*": { systemPrompt: "wildcard prompt" } },
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
).toBe("wildcard prompt");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("suppresses wildcard when specific group entry sets systemPrompt to empty string", () => {
|
|
44
|
-
expect(
|
|
45
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
46
|
-
groupId: "g1",
|
|
47
|
-
accountConfig: {
|
|
48
|
-
groups: {
|
|
49
|
-
g1: { systemPrompt: "" },
|
|
50
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
}),
|
|
54
|
-
).toBeUndefined();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("suppresses wildcard when specific group entry sets systemPrompt to whitespace-only string", () => {
|
|
58
|
-
expect(
|
|
59
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
60
|
-
groupId: "g1",
|
|
61
|
-
accountConfig: {
|
|
62
|
-
groups: {
|
|
63
|
-
g1: { systemPrompt: " " },
|
|
64
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
).toBeUndefined();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("trims whitespace from specific group systemPrompt", () => {
|
|
72
|
-
expect(
|
|
73
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
74
|
-
groupId: "g1",
|
|
75
|
-
accountConfig: { groups: { g1: { systemPrompt: " trimmed " } } },
|
|
76
|
-
}),
|
|
77
|
-
).toBe("trimmed");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("returns undefined when specific group entry has no systemPrompt key and no wildcard", () => {
|
|
81
|
-
expect(
|
|
82
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
83
|
-
groupId: "g1",
|
|
84
|
-
accountConfig: { groups: { g1: {} } },
|
|
85
|
-
}),
|
|
86
|
-
).toBeUndefined();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("falls back to wildcard when specific group entry has no systemPrompt key", () => {
|
|
90
|
-
expect(
|
|
91
|
-
resolveWhatsAppGroupSystemPrompt({
|
|
92
|
-
groupId: "g1",
|
|
93
|
-
accountConfig: {
|
|
94
|
-
groups: {
|
|
95
|
-
g1: {},
|
|
96
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
).toBe("wildcard prompt");
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("resolveWhatsAppDirectSystemPrompt", () => {
|
|
105
|
-
it("returns undefined when peerId is absent", () => {
|
|
106
|
-
expect(resolveWhatsAppDirectSystemPrompt({ peerId: null })).toBeUndefined();
|
|
107
|
-
expect(resolveWhatsAppDirectSystemPrompt({ peerId: undefined })).toBeUndefined();
|
|
108
|
-
expect(resolveWhatsAppDirectSystemPrompt({})).toBeUndefined();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("returns undefined when accountConfig is absent", () => {
|
|
112
|
-
expect(
|
|
113
|
-
resolveWhatsAppDirectSystemPrompt({ peerId: "p1", accountConfig: null }),
|
|
114
|
-
).toBeUndefined();
|
|
115
|
-
expect(
|
|
116
|
-
resolveWhatsAppDirectSystemPrompt({ peerId: "p1", accountConfig: undefined }),
|
|
117
|
-
).toBeUndefined();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("returns the peer-specific systemPrompt when defined", () => {
|
|
121
|
-
expect(
|
|
122
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
123
|
-
peerId: "p1",
|
|
124
|
-
accountConfig: { direct: { p1: { systemPrompt: "direct prompt" } } },
|
|
125
|
-
}),
|
|
126
|
-
).toBe("direct prompt");
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("falls back to wildcard when specific peer entry is absent", () => {
|
|
130
|
-
expect(
|
|
131
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
132
|
-
peerId: "p1",
|
|
133
|
-
accountConfig: {
|
|
134
|
-
direct: { "*": { systemPrompt: "wildcard prompt" } },
|
|
135
|
-
},
|
|
136
|
-
}),
|
|
137
|
-
).toBe("wildcard prompt");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("suppresses wildcard when specific peer entry sets systemPrompt to empty string", () => {
|
|
141
|
-
expect(
|
|
142
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
143
|
-
peerId: "p1",
|
|
144
|
-
accountConfig: {
|
|
145
|
-
direct: {
|
|
146
|
-
p1: { systemPrompt: "" },
|
|
147
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
}),
|
|
151
|
-
).toBeUndefined();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("suppresses wildcard when specific peer entry sets systemPrompt to whitespace-only string", () => {
|
|
155
|
-
expect(
|
|
156
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
157
|
-
peerId: "p1",
|
|
158
|
-
accountConfig: {
|
|
159
|
-
direct: {
|
|
160
|
-
p1: { systemPrompt: " " },
|
|
161
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
}),
|
|
165
|
-
).toBeUndefined();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("trims whitespace from specific peer systemPrompt", () => {
|
|
169
|
-
expect(
|
|
170
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
171
|
-
peerId: "p1",
|
|
172
|
-
accountConfig: { direct: { p1: { systemPrompt: " trimmed " } } },
|
|
173
|
-
}),
|
|
174
|
-
).toBe("trimmed");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("returns undefined when specific peer entry has no systemPrompt key and no wildcard", () => {
|
|
178
|
-
expect(
|
|
179
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
180
|
-
peerId: "p1",
|
|
181
|
-
accountConfig: { direct: { p1: {} } },
|
|
182
|
-
}),
|
|
183
|
-
).toBeUndefined();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("falls back to wildcard when specific peer entry has no systemPrompt key", () => {
|
|
187
|
-
expect(
|
|
188
|
-
resolveWhatsAppDirectSystemPrompt({
|
|
189
|
-
peerId: "p1",
|
|
190
|
-
accountConfig: {
|
|
191
|
-
direct: {
|
|
192
|
-
p1: {},
|
|
193
|
-
"*": { systemPrompt: "wildcard prompt" },
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
}),
|
|
197
|
-
).toBe("wildcard prompt");
|
|
198
|
-
});
|
|
199
|
-
});
|
package/src/system-prompt.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function resolveWhatsAppGroupSystemPrompt(params: {
|
|
2
|
-
accountConfig?: { groups?: Record<string, { systemPrompt?: string | null }> } | null;
|
|
3
|
-
groupId?: string | null;
|
|
4
|
-
}): string | undefined {
|
|
5
|
-
if (!params.groupId) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const groups = params.accountConfig?.groups;
|
|
9
|
-
const specific = groups?.[params.groupId];
|
|
10
|
-
if (specific != null && specific.systemPrompt != null) {
|
|
11
|
-
return specific.systemPrompt.trim() || undefined;
|
|
12
|
-
}
|
|
13
|
-
const wildcard = groups?.["*"]?.systemPrompt;
|
|
14
|
-
return wildcard != null ? wildcard.trim() || undefined : undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function resolveWhatsAppDirectSystemPrompt(params: {
|
|
18
|
-
accountConfig?: { direct?: Record<string, { systemPrompt?: string | null }> } | null;
|
|
19
|
-
peerId?: string | null;
|
|
20
|
-
}): string | undefined {
|
|
21
|
-
if (!params.peerId) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
const direct = params.accountConfig?.direct;
|
|
25
|
-
const specific = direct?.[params.peerId];
|
|
26
|
-
if (specific != null && specific.systemPrompt != null) {
|
|
27
|
-
return specific.systemPrompt.trim() || undefined;
|
|
28
|
-
}
|
|
29
|
-
const wildcard = direct?.["*"]?.systemPrompt;
|
|
30
|
-
return wildcard != null ? wildcard.trim() || undefined : undefined;
|
|
31
|
-
}
|
package/src/targets-runtime.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { normalizeE164 } from "openclaw/plugin-sdk/account-resolution";
|
|
4
|
-
import { logVerbose, shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
|
|
5
|
-
import { escapeRegExp } from "openclaw/plugin-sdk/text-runtime";
|
|
6
|
-
import { CONFIG_DIR, resolveUserPath } from "openclaw/plugin-sdk/text-runtime";
|
|
7
|
-
|
|
8
|
-
const WHATSAPP_FENCE_PLACEHOLDER = "\x00FENCE";
|
|
9
|
-
const WHATSAPP_INLINE_CODE_PLACEHOLDER = "\x00CODE";
|
|
10
|
-
|
|
11
|
-
export type WebChannel = "web";
|
|
12
|
-
|
|
13
|
-
export function assertWebChannel(input: string): asserts input is WebChannel {
|
|
14
|
-
if (input !== "web") {
|
|
15
|
-
throw new Error("Web channel must be 'web'");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isSelfChatMode(
|
|
20
|
-
selfE164: string | null | undefined,
|
|
21
|
-
allowFrom?: Array<string | number> | null,
|
|
22
|
-
): boolean {
|
|
23
|
-
if (!selfE164) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (!Array.isArray(allowFrom) || allowFrom.length === 0) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const normalizedSelf = normalizeE164(selfE164);
|
|
30
|
-
return allowFrom.some((n) => {
|
|
31
|
-
if (n === "*") {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
return normalizeE164(String(n)) === normalizedSelf;
|
|
36
|
-
} catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function toWhatsappJid(number: string): string {
|
|
43
|
-
const withoutPrefix = number.replace(/^whatsapp:/i, "").trim();
|
|
44
|
-
if (withoutPrefix.includes("@")) {
|
|
45
|
-
return withoutPrefix;
|
|
46
|
-
}
|
|
47
|
-
const e164 = normalizeE164(withoutPrefix);
|
|
48
|
-
const digits = e164.replace(/\D/g, "");
|
|
49
|
-
return `${digits}@s.whatsapp.net`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type JidToE164Options = {
|
|
53
|
-
authDir?: string;
|
|
54
|
-
lidMappingDirs?: string[];
|
|
55
|
-
logMissing?: boolean;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
type LidLookup = {
|
|
59
|
-
getPNForLID?: (jid: string) => Promise<string | null>;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function resolveLidMappingDirs(params: { opts?: JidToE164Options }): string[] {
|
|
63
|
-
const dirs = new Set<string>();
|
|
64
|
-
const addDir = (dir?: string | null) => {
|
|
65
|
-
if (!dir) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
dirs.add(resolveUserPath(dir));
|
|
69
|
-
};
|
|
70
|
-
addDir(params.opts?.authDir);
|
|
71
|
-
for (const dir of params.opts?.lidMappingDirs ?? []) {
|
|
72
|
-
addDir(dir);
|
|
73
|
-
}
|
|
74
|
-
addDir(CONFIG_DIR);
|
|
75
|
-
addDir(path.join(CONFIG_DIR, "credentials"));
|
|
76
|
-
return [...dirs];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function readLidReverseMapping(params: { lid: string; opts?: JidToE164Options }): string | null {
|
|
80
|
-
const mappingFilename = `lid-mapping-${params.lid}_reverse.json`;
|
|
81
|
-
const mappingDirs = resolveLidMappingDirs({ opts: params.opts });
|
|
82
|
-
for (const dir of mappingDirs) {
|
|
83
|
-
const mappingPath = path.join(dir, mappingFilename);
|
|
84
|
-
try {
|
|
85
|
-
const data = fs.readFileSync(mappingPath, "utf8");
|
|
86
|
-
const phone = JSON.parse(data) as string | number | null;
|
|
87
|
-
if (phone === null || phone === undefined) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
return normalizeE164(String(phone));
|
|
91
|
-
} catch {
|
|
92
|
-
// next location
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function jidToE164(jid: string, opts?: JidToE164Options): string | null {
|
|
99
|
-
const match = jid.match(/^(\d+)(?::\d+)?@(s\.whatsapp\.net|hosted)$/);
|
|
100
|
-
if (match) {
|
|
101
|
-
return `+${match[1]}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const lidMatch = jid.match(/^(\d+)(?::\d+)?@(lid|hosted\.lid)$/);
|
|
105
|
-
if (!lidMatch) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
const phone = readLidReverseMapping({
|
|
109
|
-
lid: lidMatch[1],
|
|
110
|
-
opts,
|
|
111
|
-
});
|
|
112
|
-
if (phone) {
|
|
113
|
-
return phone;
|
|
114
|
-
}
|
|
115
|
-
const shouldLog = opts?.logMissing ?? shouldLogVerbose();
|
|
116
|
-
if (shouldLog) {
|
|
117
|
-
logVerbose(`LID mapping not found for ${lidMatch[1]}; skipping inbound message`);
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export async function resolveJidToE164(
|
|
123
|
-
jid: string | null | undefined,
|
|
124
|
-
opts?: JidToE164Options & { lidLookup?: LidLookup },
|
|
125
|
-
): Promise<string | null> {
|
|
126
|
-
if (!jid) {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
const direct = jidToE164(jid, opts);
|
|
130
|
-
if (direct) {
|
|
131
|
-
return direct;
|
|
132
|
-
}
|
|
133
|
-
if (!/(@lid|@hosted\.lid)$/.test(jid) || !opts?.lidLookup?.getPNForLID) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const pnJid = await opts.lidLookup.getPNForLID(jid);
|
|
138
|
-
if (!pnJid) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
return jidToE164(pnJid, opts);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
if (shouldLogVerbose()) {
|
|
144
|
-
logVerbose(`LID mapping lookup failed for ${jid}: ${String(err)}`);
|
|
145
|
-
}
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function markdownToWhatsApp(text: string): string {
|
|
151
|
-
if (!text) {
|
|
152
|
-
return text;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const fences: string[] = [];
|
|
156
|
-
let result = text.replace(/```[\s\S]*?```/g, (match) => {
|
|
157
|
-
fences.push(match);
|
|
158
|
-
return `${WHATSAPP_FENCE_PLACEHOLDER}${fences.length - 1}`;
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const inlineCodes: string[] = [];
|
|
162
|
-
result = result.replace(/`[^`\n]+`/g, (match) => {
|
|
163
|
-
inlineCodes.push(match);
|
|
164
|
-
return `${WHATSAPP_INLINE_CODE_PLACEHOLDER}${inlineCodes.length - 1}`;
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
result = result.replace(/\*\*(.+?)\*\*/g, "*$1*");
|
|
168
|
-
result = result.replace(/__(.+?)__/g, "*$1*");
|
|
169
|
-
result = result.replace(/~~(.+?)~~/g, "~$1~");
|
|
170
|
-
|
|
171
|
-
result = result.replace(
|
|
172
|
-
new RegExp(`${escapeRegExp(WHATSAPP_INLINE_CODE_PLACEHOLDER)}(\\d+)`, "g"),
|
|
173
|
-
(_, idx) => inlineCodes[Number(idx)] ?? "",
|
|
174
|
-
);
|
|
175
|
-
result = result.replace(
|
|
176
|
-
new RegExp(`${escapeRegExp(WHATSAPP_FENCE_PLACEHOLDER)}(\\d+)`, "g"),
|
|
177
|
-
(_, idx) => fences[Number(idx)] ?? "",
|
|
178
|
-
);
|
|
179
|
-
return result;
|
|
180
|
-
}
|