@openclaw/whatsapp 2026.5.1-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/action-runtime-api.ts +1 -0
- package/action-runtime.runtime.ts +1 -0
- package/api.ts +213 -0
- package/auth-presence.ts +80 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +3 -0
- package/config-api.ts +4 -0
- package/constants.ts +1 -0
- package/contract-api.ts +29 -0
- package/directory-contract-api.ts +4 -0
- package/dist/.boundary-tsc.stamp +1 -0
- package/dist/.boundary-tsc.tsbuildinfo +1 -0
- package/doctor-contract-api.ts +8 -0
- package/index.test.ts +13 -0
- package/index.ts +16 -0
- package/legacy-session-surface-api.ts +6 -0
- package/legacy-state-migrations-api.ts +1 -0
- package/light-runtime-api.ts +12 -0
- package/login-qr-api.ts +1 -0
- package/login-qr-runtime.ts +23 -0
- package/openclaw.plugin.json +742 -0
- package/outbound-payload-test-api.ts +1 -0
- package/package.json +74 -0
- package/runtime-api.ts +86 -0
- package/secret-contract-api.ts +4 -0
- package/security-contract-api.ts +4 -0
- package/setup-entry.test.ts +21 -0
- package/setup-entry.ts +21 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-config.ts +77 -0
- package/src/account-ids.ts +13 -0
- package/src/account-types.ts +5 -0
- package/src/accounts.test.ts +182 -0
- package/src/accounts.ts +176 -0
- package/src/accounts.whatsapp-auth.test.ts +59 -0
- package/src/action-runtime-target-auth.ts +27 -0
- package/src/action-runtime.test.ts +330 -0
- package/src/action-runtime.ts +76 -0
- package/src/active-listener.test.ts +65 -0
- package/src/active-listener.ts +17 -0
- package/src/agent-tools-login.test.ts +81 -0
- package/src/agent-tools-login.ts +113 -0
- package/src/approval-auth.test.ts +24 -0
- package/src/approval-auth.ts +27 -0
- package/src/auth-store.runtime.ts +1 -0
- package/src/auth-store.test.ts +311 -0
- package/src/auth-store.ts +502 -0
- package/src/auto-reply/config.runtime.ts +16 -0
- package/src/auto-reply/constants.ts +1 -0
- package/src/auto-reply/deliver-reply.test.ts +843 -0
- package/src/auto-reply/deliver-reply.ts +279 -0
- package/src/auto-reply/heartbeat-runner.runtime.ts +33 -0
- package/src/auto-reply/heartbeat-runner.test.ts +214 -0
- package/src/auto-reply/heartbeat-runner.ts +330 -0
- package/src/auto-reply/loggers.ts +6 -0
- package/src/auto-reply/mentions.ts +131 -0
- package/src/auto-reply/monitor/ack-reaction.test.ts +170 -0
- package/src/auto-reply/monitor/ack-reaction.ts +99 -0
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +9 -0
- package/src/auto-reply/monitor/broadcast.ts +153 -0
- package/src/auto-reply/monitor/commands.ts +19 -0
- package/src/auto-reply/monitor/echo.ts +64 -0
- package/src/auto-reply/monitor/group-activation.runtime.ts +1 -0
- package/src/auto-reply/monitor/group-activation.test.ts +189 -0
- package/src/auto-reply/monitor/group-activation.ts +73 -0
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +103 -0
- package/src/auto-reply/monitor/group-gating.runtime.ts +8 -0
- package/src/auto-reply/monitor/group-gating.ts +217 -0
- package/src/auto-reply/monitor/group-members.test.ts +56 -0
- package/src/auto-reply/monitor/group-members.ts +65 -0
- package/src/auto-reply/monitor/inbound-context.test.ts +97 -0
- package/src/auto-reply/monitor/inbound-context.ts +92 -0
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +21 -0
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +895 -0
- package/src/auto-reply/monitor/inbound-dispatch.ts +422 -0
- package/src/auto-reply/monitor/last-route.test.ts +37 -0
- package/src/auto-reply/monitor/last-route.ts +61 -0
- package/src/auto-reply/monitor/message-line.runtime.ts +38 -0
- package/src/auto-reply/monitor/message-line.ts +54 -0
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +354 -0
- package/src/auto-reply/monitor/on-message.ts +291 -0
- package/src/auto-reply/monitor/peer.ts +17 -0
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +420 -0
- package/src/auto-reply/monitor/process-message.test.ts +355 -0
- package/src/auto-reply/monitor/process-message.ts +531 -0
- package/src/auto-reply/monitor/runtime-api.ts +30 -0
- package/src/auto-reply/monitor-state.test.ts +64 -0
- package/src/auto-reply/monitor-state.ts +106 -0
- package/src/auto-reply/monitor.ts +600 -0
- package/src/auto-reply/reply-resolver.runtime.ts +1 -0
- package/src/auto-reply/session-snapshot.ts +69 -0
- package/src/auto-reply/types.ts +48 -0
- package/src/auto-reply/util.ts +63 -0
- package/src/auto-reply/web-auto-reply-monitor.test.ts +687 -0
- package/src/auto-reply/web-auto-reply-utils.test.ts +327 -0
- package/src/auto-reply.broadcast-groups.combined.test.ts +246 -0
- package/src/auto-reply.broadcast-groups.test-harness.ts +47 -0
- package/src/auto-reply.impl.ts +7 -0
- package/src/auto-reply.test-harness.ts +421 -0
- package/src/auto-reply.ts +1 -0
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +427 -0
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +908 -0
- package/src/auto-reply.web-auto-reply.last-route.test.ts +184 -0
- package/src/channel-actions.runtime.ts +7 -0
- package/src/channel-actions.test.ts +216 -0
- package/src/channel-actions.ts +84 -0
- package/src/channel-outbound.test.ts +131 -0
- package/src/channel-outbound.ts +36 -0
- package/src/channel-react-action.runtime.ts +7 -0
- package/src/channel-react-action.test.ts +294 -0
- package/src/channel-react-action.ts +84 -0
- package/src/channel.runtime.ts +117 -0
- package/src/channel.setup.test.ts +461 -0
- package/src/channel.setup.ts +28 -0
- package/src/channel.ts +336 -0
- package/src/command-policy.ts +7 -0
- package/src/config-accessors.test.ts +34 -0
- package/src/config-accessors.ts +22 -0
- package/src/config-schema.test.ts +121 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +24 -0
- package/src/connection-controller-registry.test.ts +27 -0
- package/src/connection-controller-registry.ts +49 -0
- package/src/connection-controller.test.ts +282 -0
- package/src/connection-controller.ts +679 -0
- package/src/creds-files.ts +19 -0
- package/src/creds-persistence.ts +102 -0
- package/src/directory-config.test.ts +60 -0
- package/src/directory-config.ts +40 -0
- package/src/directory-contract.test.ts +56 -0
- package/src/doctor-contract.ts +11 -0
- package/src/doctor.test.ts +74 -0
- package/src/doctor.ts +56 -0
- package/src/group-intro.ts +15 -0
- package/src/group-policy.test.ts +36 -0
- package/src/group-policy.ts +40 -0
- package/src/group-session-contract.ts +20 -0
- package/src/group-session-key.test.ts +53 -0
- package/src/group-session-key.ts +41 -0
- package/src/heartbeat-recipients.runtime.ts +6 -0
- package/src/heartbeat-recipients.test.ts +203 -0
- package/src/heartbeat-recipients.ts +104 -0
- package/src/heartbeat.ts +34 -0
- package/src/identity.ts +164 -0
- package/src/inbound/access-control.test-harness.ts +37 -0
- package/src/inbound/access-control.test.ts +375 -0
- package/src/inbound/access-control.ts +237 -0
- package/src/inbound/dedupe.ts +132 -0
- package/src/inbound/extract.test.ts +282 -0
- package/src/inbound/extract.ts +488 -0
- package/src/inbound/lifecycle.ts +39 -0
- package/src/inbound/media.node.test.ts +83 -0
- package/src/inbound/media.ts +102 -0
- package/src/inbound/monitor.ts +890 -0
- package/src/inbound/runtime-api.ts +7 -0
- package/src/inbound/save-media.runtime.ts +1 -0
- package/src/inbound/send-api.test.ts +307 -0
- package/src/inbound/send-api.ts +141 -0
- package/src/inbound/send-result.ts +61 -0
- package/src/inbound/types.ts +106 -0
- package/src/inbound-context.contract.test.ts +32 -0
- package/src/inbound-policy.ts +231 -0
- package/src/inbound.media.test.ts +320 -0
- package/src/inbound.test.ts +290 -0
- package/src/inbound.ts +9 -0
- package/src/login-qr.test.ts +483 -0
- package/src/login-qr.ts +542 -0
- package/src/login.coverage.test.ts +133 -0
- package/src/login.test.ts +89 -0
- package/src/login.ts +70 -0
- package/src/logout.test.ts +162 -0
- package/src/media.test.ts +480 -0
- package/src/media.ts +10 -0
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +400 -0
- package/src/monitor-inbox.append-upsert.test-support.ts +133 -0
- package/src/monitor-inbox.behavior.test.ts +5 -0
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +362 -0
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +306 -0
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +729 -0
- package/src/monitor-inbox.test-harness.ts +304 -0
- package/src/normalize-target.ts +112 -0
- package/src/normalize.ts +6 -0
- package/src/outbound-adapter.poll.test.ts +62 -0
- package/src/outbound-adapter.sendpayload.test.ts +195 -0
- package/src/outbound-adapter.ts +36 -0
- package/src/outbound-base.test.ts +560 -0
- package/src/outbound-base.ts +244 -0
- package/src/outbound-media-contract.ts +278 -0
- package/src/outbound-media.runtime.ts +36 -0
- package/src/outbound-payload.contract.test.ts +61 -0
- package/src/outbound-send-deps.ts +1 -0
- package/src/outbound-test-support.ts +16 -0
- package/src/pairing-security.test-harness.ts +59 -0
- package/src/qr-image.ts +1 -0
- package/src/qr-terminal.ts +1 -0
- package/src/quoted-message.test.ts +83 -0
- package/src/quoted-message.ts +184 -0
- package/src/reaction-level.test.ts +94 -0
- package/src/reaction-level.ts +21 -0
- package/src/reconnect.test.ts +51 -0
- package/src/reconnect.ts +55 -0
- package/src/resolve-outbound-target.test.ts +265 -0
- package/src/resolve-outbound-target.ts +54 -0
- package/src/resolve-target.test.ts +97 -0
- package/src/runtime-api.ts +60 -0
- package/src/runtime-group-policy.ts +16 -0
- package/src/runtime.ts +9 -0
- package/src/security-contract.ts +47 -0
- package/src/security-fix.ts +71 -0
- package/src/send.test.ts +515 -0
- package/src/send.ts +287 -0
- package/src/session-contract.test.ts +31 -0
- package/src/session-contract.ts +43 -0
- package/src/session-errors.ts +125 -0
- package/src/session-route.ts +26 -0
- package/src/session.runtime.ts +8 -0
- package/src/session.test.ts +559 -0
- package/src/session.ts +330 -0
- package/src/setup-core.ts +52 -0
- package/src/setup-finalize.ts +446 -0
- package/src/setup-surface.test.ts +367 -0
- package/src/setup-surface.ts +69 -0
- package/src/setup-test-helpers.ts +216 -0
- package/src/shared.ts +291 -0
- package/src/socket-timing.test.ts +49 -0
- package/src/socket-timing.ts +38 -0
- package/src/state-migrations.ts +54 -0
- package/src/status-issues.test.ts +137 -0
- package/src/status-issues.ts +185 -0
- package/src/system-prompt.test.ts +199 -0
- package/src/system-prompt.ts +31 -0
- package/src/targets-runtime.ts +180 -0
- package/src/test-helpers.ts +690 -0
- package/src/text-runtime.test.ts +162 -0
- package/src/text-runtime.ts +11 -0
- package/src/vcard.ts +84 -0
- package/targets.ts +5 -0
- package/test-api.ts +2 -0
- package/tsconfig.json +16 -0
package/src/shared.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-core";
|
|
2
|
+
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
|
|
3
|
+
import { normalizeE164 } from "openclaw/plugin-sdk/account-resolution";
|
|
4
|
+
import {
|
|
5
|
+
adaptScopedAccountAccessor,
|
|
6
|
+
createScopedChannelConfigAdapter,
|
|
7
|
+
createScopedDmSecurityResolver,
|
|
8
|
+
} from "openclaw/plugin-sdk/channel-config-helpers";
|
|
9
|
+
import {
|
|
10
|
+
collectOpenGroupPolicyRouteAllowlistWarnings,
|
|
11
|
+
createAllowlistProviderGroupPolicyWarningCollector,
|
|
12
|
+
} from "openclaw/plugin-sdk/channel-policy";
|
|
13
|
+
import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
|
|
14
|
+
import { createChannelPluginBase, getChatChannelMeta } from "openclaw/plugin-sdk/core";
|
|
15
|
+
import {
|
|
16
|
+
createDelegatedSetupWizardProxy,
|
|
17
|
+
type ChannelSetupWizard,
|
|
18
|
+
} from "openclaw/plugin-sdk/setup-runtime";
|
|
19
|
+
import {
|
|
20
|
+
hasAnyWhatsAppAuth,
|
|
21
|
+
listWhatsAppAccountIds,
|
|
22
|
+
resolveDefaultWhatsAppAccountId,
|
|
23
|
+
resolveWhatsAppAccount,
|
|
24
|
+
type ResolvedWhatsAppAccount,
|
|
25
|
+
} from "./accounts.js";
|
|
26
|
+
import { formatWhatsAppConfigAllowFromEntries } from "./config-accessors.js";
|
|
27
|
+
import { WhatsAppChannelConfigSchema } from "./config-schema.js";
|
|
28
|
+
import { whatsappDoctor } from "./doctor.js";
|
|
29
|
+
import { resolveLegacyGroupSessionKey } from "./group-session-contract.js";
|
|
30
|
+
import {
|
|
31
|
+
collectUnsupportedSecretRefConfigCandidates,
|
|
32
|
+
unsupportedSecretRefSurfacePatterns,
|
|
33
|
+
} from "./security-contract.js";
|
|
34
|
+
import { applyWhatsAppSecurityConfigFixes } from "./security-fix.js";
|
|
35
|
+
import {
|
|
36
|
+
canonicalizeLegacySessionKey,
|
|
37
|
+
deriveLegacySessionChatType,
|
|
38
|
+
isLegacyGroupSessionKey,
|
|
39
|
+
} from "./session-contract.js";
|
|
40
|
+
|
|
41
|
+
const WHATSAPP_CHANNEL = "whatsapp" as const;
|
|
42
|
+
|
|
43
|
+
const WHATSAPP_GROUP_SCOPE_FIELDS = ["groupPolicy", "groupAllowFrom", "groups"] as const;
|
|
44
|
+
|
|
45
|
+
type WhatsAppGroupScopeField = (typeof WHATSAPP_GROUP_SCOPE_FIELDS)[number];
|
|
46
|
+
|
|
47
|
+
function resolveWhatsAppAccountKey(
|
|
48
|
+
accounts: Record<string, unknown> | undefined,
|
|
49
|
+
accountId: string,
|
|
50
|
+
): string | undefined {
|
|
51
|
+
if (!accounts) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
if (Object.hasOwn(accounts, accountId)) {
|
|
55
|
+
return accountId;
|
|
56
|
+
}
|
|
57
|
+
const normalizedAccountId = accountId.trim().toLowerCase();
|
|
58
|
+
return Object.keys(accounts).find((key) => key.trim().toLowerCase() === normalizedAccountId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveWhatsAppGroupScopeBasePath(params: {
|
|
62
|
+
cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
|
|
63
|
+
accountId?: string | null;
|
|
64
|
+
}): string {
|
|
65
|
+
const accountId =
|
|
66
|
+
typeof params.accountId === "string"
|
|
67
|
+
? params.accountId.trim() || DEFAULT_ACCOUNT_ID
|
|
68
|
+
: DEFAULT_ACCOUNT_ID;
|
|
69
|
+
const accounts = params.cfg.channels?.whatsapp?.accounts;
|
|
70
|
+
const accountKey = resolveWhatsAppAccountKey(accounts, accountId);
|
|
71
|
+
const defaultAccountKey = resolveWhatsAppAccountKey(accounts, DEFAULT_ACCOUNT_ID);
|
|
72
|
+
const accountConfig = accountKey ? accounts?.[accountKey] : undefined;
|
|
73
|
+
const defaultAccountConfig = defaultAccountKey ? accounts?.[defaultAccountKey] : undefined;
|
|
74
|
+
const matchesAnyGroupScopeField = (config: Record<string, unknown> | undefined): boolean =>
|
|
75
|
+
WHATSAPP_GROUP_SCOPE_FIELDS.some((field) => config?.[field] !== undefined);
|
|
76
|
+
if (matchesAnyGroupScopeField(accountConfig)) {
|
|
77
|
+
return `channels.whatsapp.accounts.${accountKey}`;
|
|
78
|
+
}
|
|
79
|
+
if (accountId !== DEFAULT_ACCOUNT_ID && matchesAnyGroupScopeField(defaultAccountConfig)) {
|
|
80
|
+
return `channels.whatsapp.accounts.${defaultAccountKey}`;
|
|
81
|
+
}
|
|
82
|
+
return "channels.whatsapp";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function resolveWhatsAppConfigPath(params: {
|
|
86
|
+
cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
|
|
87
|
+
accountId?: string | null;
|
|
88
|
+
field: WhatsAppGroupScopeField;
|
|
89
|
+
}): string {
|
|
90
|
+
return `${resolveWhatsAppGroupScopeBasePath(params)}.${params.field}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function loadWhatsAppChannelRuntime() {
|
|
94
|
+
return await import("./channel.runtime.js");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function loadWhatsAppSetupSurface() {
|
|
98
|
+
return await import("./setup-surface.js");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const whatsappSetupWizardProxy = createWhatsAppSetupWizardProxy(
|
|
102
|
+
async () => (await loadWhatsAppSetupSurface()).whatsappSetupWizard,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const whatsappConfigAdapter = createScopedChannelConfigAdapter<ResolvedWhatsAppAccount>({
|
|
106
|
+
sectionKey: WHATSAPP_CHANNEL,
|
|
107
|
+
listAccountIds: listWhatsAppAccountIds,
|
|
108
|
+
resolveAccount: adaptScopedAccountAccessor(resolveWhatsAppAccount),
|
|
109
|
+
defaultAccountId: resolveDefaultWhatsAppAccountId,
|
|
110
|
+
clearBaseFields: [],
|
|
111
|
+
allowTopLevel: false,
|
|
112
|
+
resolveAllowFrom: (account) => account.allowFrom,
|
|
113
|
+
formatAllowFrom: (allowFrom) => formatWhatsAppConfigAllowFromEntries(allowFrom),
|
|
114
|
+
resolveDefaultTo: (account) => account.defaultTo,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const whatsappResolveDmPolicy = createScopedDmSecurityResolver<ResolvedWhatsAppAccount>({
|
|
118
|
+
channelKey: WHATSAPP_CHANNEL,
|
|
119
|
+
resolvePolicy: (account) => account.dmPolicy,
|
|
120
|
+
resolveAllowFrom: (account) => account.allowFrom,
|
|
121
|
+
policyPathSuffix: "dmPolicy",
|
|
122
|
+
normalizeEntry: (raw) => normalizeE164(raw),
|
|
123
|
+
inheritSharedDefaultsFromDefaultAccount: true,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
function createWhatsAppSetupWizardProxy(
|
|
127
|
+
loadWizard: () => Promise<ChannelSetupWizard>,
|
|
128
|
+
): ChannelSetupWizard {
|
|
129
|
+
return createDelegatedSetupWizardProxy({
|
|
130
|
+
channel: WHATSAPP_CHANNEL,
|
|
131
|
+
loadWizard,
|
|
132
|
+
status: {
|
|
133
|
+
configuredLabel: "linked",
|
|
134
|
+
unconfiguredLabel: "not linked",
|
|
135
|
+
configuredHint: "linked",
|
|
136
|
+
unconfiguredHint: "not linked",
|
|
137
|
+
configuredScore: 5,
|
|
138
|
+
unconfiguredScore: 4,
|
|
139
|
+
},
|
|
140
|
+
resolveShouldPromptAccountIds: (params) => params.shouldPromptAccountIds,
|
|
141
|
+
credentials: [],
|
|
142
|
+
delegateFinalize: true,
|
|
143
|
+
disable: (cfg) => ({
|
|
144
|
+
...cfg,
|
|
145
|
+
channels: {
|
|
146
|
+
...cfg.channels,
|
|
147
|
+
whatsapp: {
|
|
148
|
+
...cfg.channels?.whatsapp,
|
|
149
|
+
enabled: false,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
onAccountRecorded: (accountId, options) => {
|
|
154
|
+
options?.onAccountId?.(WHATSAPP_CHANNEL, accountId);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function createWhatsAppPluginBase(params: {
|
|
160
|
+
groups: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["groups"]>;
|
|
161
|
+
setupWizard: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["setupWizard"]>;
|
|
162
|
+
setup: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["setup"]>;
|
|
163
|
+
isConfigured: NonNullable<ChannelPlugin<ResolvedWhatsAppAccount>["config"]>["isConfigured"];
|
|
164
|
+
}) {
|
|
165
|
+
const collectWhatsAppSecurityWarnings = createAllowlistProviderGroupPolicyWarningCollector<{
|
|
166
|
+
account: ResolvedWhatsAppAccount;
|
|
167
|
+
cfg: Parameters<typeof resolveWhatsAppAccount>[0]["cfg"];
|
|
168
|
+
accountId?: string | null;
|
|
169
|
+
}>({
|
|
170
|
+
providerConfigPresent: (cfg) => cfg.channels?.whatsapp !== undefined,
|
|
171
|
+
resolveGroupPolicy: ({ account }) => account.groupPolicy,
|
|
172
|
+
collect: ({ account, accountId, cfg, groupPolicy }) =>
|
|
173
|
+
collectOpenGroupPolicyRouteAllowlistWarnings({
|
|
174
|
+
groupPolicy,
|
|
175
|
+
routeAllowlistConfigured:
|
|
176
|
+
Boolean(account.groups) && Object.keys(account.groups ?? {}).length > 0,
|
|
177
|
+
restrictSenders: {
|
|
178
|
+
surface: "WhatsApp groups",
|
|
179
|
+
openScope: "any member in allowed groups",
|
|
180
|
+
groupPolicyPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groupPolicy" }),
|
|
181
|
+
groupAllowFromPath: resolveWhatsAppConfigPath({
|
|
182
|
+
cfg,
|
|
183
|
+
accountId,
|
|
184
|
+
field: "groupAllowFrom",
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
noRouteAllowlist: {
|
|
188
|
+
surface: "WhatsApp groups",
|
|
189
|
+
routeAllowlistPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groups" }),
|
|
190
|
+
routeScope: "group",
|
|
191
|
+
groupPolicyPath: resolveWhatsAppConfigPath({ cfg, accountId, field: "groupPolicy" }),
|
|
192
|
+
groupAllowFromPath: resolveWhatsAppConfigPath({
|
|
193
|
+
cfg,
|
|
194
|
+
accountId,
|
|
195
|
+
field: "groupAllowFrom",
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
const base = createChannelPluginBase({
|
|
201
|
+
id: WHATSAPP_CHANNEL,
|
|
202
|
+
meta: {
|
|
203
|
+
...getChatChannelMeta(WHATSAPP_CHANNEL),
|
|
204
|
+
showConfigured: false,
|
|
205
|
+
quickstartAllowFrom: true,
|
|
206
|
+
forceAccountBinding: true,
|
|
207
|
+
preferSessionLookupForAnnounceTarget: true,
|
|
208
|
+
},
|
|
209
|
+
setupWizard: params.setupWizard,
|
|
210
|
+
capabilities: {
|
|
211
|
+
chatTypes: ["direct", "group"],
|
|
212
|
+
polls: true,
|
|
213
|
+
reactions: true,
|
|
214
|
+
media: true,
|
|
215
|
+
tts: {
|
|
216
|
+
voice: {
|
|
217
|
+
synthesisTarget: "voice-note",
|
|
218
|
+
transcodesAudio: true,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
reload: { configPrefixes: ["web"], noopPrefixes: ["channels.whatsapp"] },
|
|
223
|
+
gatewayMethods: ["web.login.start", "web.login.wait"],
|
|
224
|
+
configSchema: WhatsAppChannelConfigSchema,
|
|
225
|
+
config: {
|
|
226
|
+
...whatsappConfigAdapter,
|
|
227
|
+
isEnabled: (account, cfg) => account.enabled && cfg.web?.enabled !== false,
|
|
228
|
+
disabledReason: () => "disabled",
|
|
229
|
+
isConfigured: params.isConfigured,
|
|
230
|
+
hasPersistedAuthState: ({ cfg }) => hasAnyWhatsAppAuth(cfg),
|
|
231
|
+
unconfiguredReason: () => "not linked",
|
|
232
|
+
describeAccount: (account) =>
|
|
233
|
+
describeAccountSnapshot({
|
|
234
|
+
account,
|
|
235
|
+
configured: Boolean(account.authDir),
|
|
236
|
+
extra: {
|
|
237
|
+
linked: Boolean(account.authDir),
|
|
238
|
+
dmPolicy: account.dmPolicy,
|
|
239
|
+
allowFrom: account.allowFrom,
|
|
240
|
+
},
|
|
241
|
+
}),
|
|
242
|
+
},
|
|
243
|
+
security: {
|
|
244
|
+
applyConfigFixes: applyWhatsAppSecurityConfigFixes,
|
|
245
|
+
resolveDmPolicy: whatsappResolveDmPolicy,
|
|
246
|
+
collectWarnings: collectWhatsAppSecurityWarnings,
|
|
247
|
+
},
|
|
248
|
+
doctor: whatsappDoctor,
|
|
249
|
+
setup: params.setup,
|
|
250
|
+
groups: params.groups,
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
...base,
|
|
254
|
+
setupWizard: base.setupWizard!,
|
|
255
|
+
capabilities: base.capabilities!,
|
|
256
|
+
reload: base.reload!,
|
|
257
|
+
gatewayMethods: base.gatewayMethods!,
|
|
258
|
+
configSchema: base.configSchema!,
|
|
259
|
+
config: base.config!,
|
|
260
|
+
messaging: {
|
|
261
|
+
defaultMarkdownTableMode: "bullets",
|
|
262
|
+
deriveLegacySessionChatType,
|
|
263
|
+
resolveLegacyGroupSessionKey,
|
|
264
|
+
isLegacyGroupSessionKey,
|
|
265
|
+
canonicalizeLegacySessionKey: (params) =>
|
|
266
|
+
canonicalizeLegacySessionKey({ key: params.key, agentId: params.agentId }),
|
|
267
|
+
},
|
|
268
|
+
secrets: {
|
|
269
|
+
unsupportedSecretRefSurfacePatterns,
|
|
270
|
+
collectUnsupportedSecretRefConfigCandidates,
|
|
271
|
+
},
|
|
272
|
+
security: base.security!,
|
|
273
|
+
groups: base.groups!,
|
|
274
|
+
} satisfies Pick<
|
|
275
|
+
ChannelPlugin<ResolvedWhatsAppAccount>,
|
|
276
|
+
| "id"
|
|
277
|
+
| "meta"
|
|
278
|
+
| "setupWizard"
|
|
279
|
+
| "capabilities"
|
|
280
|
+
| "reload"
|
|
281
|
+
| "gatewayMethods"
|
|
282
|
+
| "configSchema"
|
|
283
|
+
| "config"
|
|
284
|
+
| "messaging"
|
|
285
|
+
| "secrets"
|
|
286
|
+
| "security"
|
|
287
|
+
| "doctor"
|
|
288
|
+
| "setup"
|
|
289
|
+
| "groups"
|
|
290
|
+
>;
|
|
291
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { DEFAULT_WHATSAPP_SOCKET_TIMING, resolveWhatsAppSocketTiming } from "./socket-timing.js";
|
|
3
|
+
|
|
4
|
+
describe("resolveWhatsAppSocketTiming", () => {
|
|
5
|
+
it("uses OpenClaw's explicit WhatsApp Web socket defaults", () => {
|
|
6
|
+
expect(resolveWhatsAppSocketTiming({})).toEqual(DEFAULT_WHATSAPP_SOCKET_TIMING);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("reads Baileys timing values from web.whatsapp config", () => {
|
|
10
|
+
expect(
|
|
11
|
+
resolveWhatsAppSocketTiming({
|
|
12
|
+
web: {
|
|
13
|
+
whatsapp: {
|
|
14
|
+
keepAliveIntervalMs: 10_000,
|
|
15
|
+
connectTimeoutMs: 90_000,
|
|
16
|
+
defaultQueryTimeoutMs: 120_000,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
).toEqual({
|
|
21
|
+
keepAliveIntervalMs: 10_000,
|
|
22
|
+
connectTimeoutMs: 90_000,
|
|
23
|
+
defaultQueryTimeoutMs: 120_000,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("lets call-site overrides take precedence over config", () => {
|
|
28
|
+
expect(
|
|
29
|
+
resolveWhatsAppSocketTiming(
|
|
30
|
+
{
|
|
31
|
+
web: {
|
|
32
|
+
whatsapp: {
|
|
33
|
+
keepAliveIntervalMs: 10_000,
|
|
34
|
+
connectTimeoutMs: 90_000,
|
|
35
|
+
defaultQueryTimeoutMs: 120_000,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
keepAliveIntervalMs: 20_000,
|
|
41
|
+
},
|
|
42
|
+
),
|
|
43
|
+
).toEqual({
|
|
44
|
+
keepAliveIntervalMs: 20_000,
|
|
45
|
+
connectTimeoutMs: 90_000,
|
|
46
|
+
defaultQueryTimeoutMs: 120_000,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
+
|
|
3
|
+
export type WhatsAppSocketTimingOptions = {
|
|
4
|
+
keepAliveIntervalMs?: number;
|
|
5
|
+
connectTimeoutMs?: number;
|
|
6
|
+
defaultQueryTimeoutMs?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_WHATSAPP_SOCKET_TIMING: Required<WhatsAppSocketTimingOptions> = {
|
|
10
|
+
keepAliveIntervalMs: 25_000,
|
|
11
|
+
connectTimeoutMs: 60_000,
|
|
12
|
+
defaultQueryTimeoutMs: 60_000,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function positiveInteger(value: number | undefined): number | undefined {
|
|
16
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveWhatsAppSocketTiming(
|
|
20
|
+
cfg: OpenClawConfig,
|
|
21
|
+
overrides?: WhatsAppSocketTimingOptions,
|
|
22
|
+
): Required<WhatsAppSocketTimingOptions> {
|
|
23
|
+
const configured = cfg.web?.whatsapp;
|
|
24
|
+
return {
|
|
25
|
+
keepAliveIntervalMs:
|
|
26
|
+
positiveInteger(overrides?.keepAliveIntervalMs) ??
|
|
27
|
+
positiveInteger(configured?.keepAliveIntervalMs) ??
|
|
28
|
+
DEFAULT_WHATSAPP_SOCKET_TIMING.keepAliveIntervalMs,
|
|
29
|
+
connectTimeoutMs:
|
|
30
|
+
positiveInteger(overrides?.connectTimeoutMs) ??
|
|
31
|
+
positiveInteger(configured?.connectTimeoutMs) ??
|
|
32
|
+
DEFAULT_WHATSAPP_SOCKET_TIMING.connectTimeoutMs,
|
|
33
|
+
defaultQueryTimeoutMs:
|
|
34
|
+
positiveInteger(overrides?.defaultQueryTimeoutMs) ??
|
|
35
|
+
positiveInteger(configured?.defaultQueryTimeoutMs) ??
|
|
36
|
+
DEFAULT_WHATSAPP_SOCKET_TIMING.defaultQueryTimeoutMs,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
4
|
+
import type { ChannelLegacyStateMigrationPlan } from "openclaw/plugin-sdk/channel-contract";
|
|
5
|
+
|
|
6
|
+
function fileExists(pathValue: string): boolean {
|
|
7
|
+
try {
|
|
8
|
+
return fs.existsSync(pathValue) && fs.statSync(pathValue).isFile();
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isLegacyWhatsAppAuthFile(name: string): boolean {
|
|
15
|
+
if (name === "creds.json" || name === "creds.json.bak") {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (!name.endsWith(".json")) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function detectWhatsAppLegacyStateMigrations(params: {
|
|
25
|
+
oauthDir: string;
|
|
26
|
+
}): ChannelLegacyStateMigrationPlan[] {
|
|
27
|
+
const targetDir = path.join(params.oauthDir, "whatsapp", DEFAULT_ACCOUNT_ID);
|
|
28
|
+
const entries = (() => {
|
|
29
|
+
try {
|
|
30
|
+
return fs.readdirSync(params.oauthDir, { withFileTypes: true });
|
|
31
|
+
} catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
return entries.flatMap((entry) => {
|
|
37
|
+
if (!entry.isFile() || entry.name === "oauth.json" || !isLegacyWhatsAppAuthFile(entry.name)) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const sourcePath = path.join(params.oauthDir, entry.name);
|
|
41
|
+
const targetPath = path.join(targetDir, entry.name);
|
|
42
|
+
if (fileExists(targetPath)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
kind: "move" as const,
|
|
48
|
+
label: `WhatsApp auth ${entry.name}`,
|
|
49
|
+
sourcePath,
|
|
50
|
+
targetPath,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { collectWhatsAppStatusIssues } from "./status-issues.js";
|
|
3
|
+
|
|
4
|
+
describe("collectWhatsAppStatusIssues", () => {
|
|
5
|
+
it("reports unlinked enabled accounts", () => {
|
|
6
|
+
const issues = collectWhatsAppStatusIssues([
|
|
7
|
+
{
|
|
8
|
+
accountId: "default",
|
|
9
|
+
enabled: true,
|
|
10
|
+
linked: false,
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
expect(issues).toEqual([
|
|
15
|
+
expect.objectContaining({
|
|
16
|
+
channel: "whatsapp",
|
|
17
|
+
accountId: "default",
|
|
18
|
+
kind: "auth",
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("reports auth reads that are still stabilizing", () => {
|
|
24
|
+
const issues = collectWhatsAppStatusIssues([
|
|
25
|
+
{
|
|
26
|
+
accountId: "default",
|
|
27
|
+
enabled: true,
|
|
28
|
+
statusState: "unstable",
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
expect(issues).toEqual([
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
channel: "whatsapp",
|
|
35
|
+
accountId: "default",
|
|
36
|
+
kind: "auth",
|
|
37
|
+
message: "Auth state is still stabilizing.",
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("reports linked but disconnected runtime state", () => {
|
|
43
|
+
const issues = collectWhatsAppStatusIssues([
|
|
44
|
+
{
|
|
45
|
+
accountId: "work",
|
|
46
|
+
enabled: true,
|
|
47
|
+
linked: true,
|
|
48
|
+
running: true,
|
|
49
|
+
connected: false,
|
|
50
|
+
reconnectAttempts: 2,
|
|
51
|
+
lastError: "socket closed",
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
expect(issues).toEqual([
|
|
56
|
+
expect.objectContaining({
|
|
57
|
+
channel: "whatsapp",
|
|
58
|
+
accountId: "work",
|
|
59
|
+
kind: "runtime",
|
|
60
|
+
message: "Linked but disconnected (reconnectAttempts=2): socket closed",
|
|
61
|
+
}),
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("reports linked but stale runtime state even while connected", () => {
|
|
66
|
+
const issues = collectWhatsAppStatusIssues([
|
|
67
|
+
{
|
|
68
|
+
accountId: "default",
|
|
69
|
+
enabled: true,
|
|
70
|
+
linked: true,
|
|
71
|
+
running: true,
|
|
72
|
+
connected: true,
|
|
73
|
+
healthState: "stale",
|
|
74
|
+
lastInboundAt: Date.now() - 2 * 60_000,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
expect(issues).toEqual([
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
channel: "whatsapp",
|
|
81
|
+
accountId: "default",
|
|
82
|
+
kind: "runtime",
|
|
83
|
+
message: expect.stringContaining("Linked but stale"),
|
|
84
|
+
}),
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("reports recently reconnected accounts even when the socket is currently healthy", () => {
|
|
89
|
+
const issues = collectWhatsAppStatusIssues([
|
|
90
|
+
{
|
|
91
|
+
accountId: "default",
|
|
92
|
+
enabled: true,
|
|
93
|
+
linked: true,
|
|
94
|
+
running: true,
|
|
95
|
+
connected: true,
|
|
96
|
+
reconnectAttempts: 3,
|
|
97
|
+
healthState: "healthy",
|
|
98
|
+
lastDisconnect: {
|
|
99
|
+
at: Date.now() - 2 * 60_000,
|
|
100
|
+
status: 408,
|
|
101
|
+
error: "status=408 Request Time-out Connection was lost",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
expect(issues).toEqual([
|
|
107
|
+
expect.objectContaining({
|
|
108
|
+
channel: "whatsapp",
|
|
109
|
+
accountId: "default",
|
|
110
|
+
kind: "runtime",
|
|
111
|
+
message:
|
|
112
|
+
"Linked but recently reconnected (reconnectAttempts=3): status=408 Request Time-out Connection was lost",
|
|
113
|
+
}),
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("does not report old reconnect history after a stable healthy period", () => {
|
|
118
|
+
const issues = collectWhatsAppStatusIssues([
|
|
119
|
+
{
|
|
120
|
+
accountId: "default",
|
|
121
|
+
enabled: true,
|
|
122
|
+
linked: true,
|
|
123
|
+
running: true,
|
|
124
|
+
connected: true,
|
|
125
|
+
reconnectAttempts: 1,
|
|
126
|
+
healthState: "healthy",
|
|
127
|
+
lastDisconnect: {
|
|
128
|
+
at: Date.now() - 60 * 60_000,
|
|
129
|
+
status: 408,
|
|
130
|
+
error: "old disconnect",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
expect(issues).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
});
|