@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
package/src/channel.ts
DELETED
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
2
|
-
import { buildDmGroupAccountAllowlistAdapter } from "openclaw/plugin-sdk/allowlist-config-edit";
|
|
3
|
-
import { createChatChannelPlugin, type ChannelPlugin } from "openclaw/plugin-sdk/channel-core";
|
|
4
|
-
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
5
|
-
import {
|
|
6
|
-
createAsyncComputedAccountStatusAdapter,
|
|
7
|
-
createDefaultChannelRuntimeState,
|
|
8
|
-
} from "openclaw/plugin-sdk/status-helpers";
|
|
9
|
-
import { resolveWhatsAppAccount, type ResolvedWhatsAppAccount } from "./accounts.js";
|
|
10
|
-
import { createWhatsAppLoginTool } from "./agent-tools-login.js";
|
|
11
|
-
import { whatsappApprovalAuth } from "./approval-auth.js";
|
|
12
|
-
import type { WebChannelStatus } from "./auto-reply/types.js";
|
|
13
|
-
import {
|
|
14
|
-
describeWhatsAppMessageActions,
|
|
15
|
-
resolveWhatsAppAgentReactionGuidance,
|
|
16
|
-
} from "./channel-actions.js";
|
|
17
|
-
import { whatsappChannelOutbound } from "./channel-outbound.js";
|
|
18
|
-
import { whatsappCommandPolicy } from "./command-policy.js";
|
|
19
|
-
import { formatWhatsAppConfigAllowFromEntries } from "./config-accessors.js";
|
|
20
|
-
import {
|
|
21
|
-
resolveWhatsAppGroupIntroHint,
|
|
22
|
-
resolveWhatsAppMentionStripRegexes,
|
|
23
|
-
} from "./group-intro.js";
|
|
24
|
-
import {
|
|
25
|
-
resolveWhatsAppGroupRequireMention,
|
|
26
|
-
resolveWhatsAppGroupToolPolicy,
|
|
27
|
-
} from "./group-policy.js";
|
|
28
|
-
import { checkWhatsAppHeartbeatReady } from "./heartbeat.js";
|
|
29
|
-
import {
|
|
30
|
-
isWhatsAppGroupJid,
|
|
31
|
-
isWhatsAppNewsletterJid,
|
|
32
|
-
looksLikeWhatsAppTargetId,
|
|
33
|
-
normalizeWhatsAppMessagingTarget,
|
|
34
|
-
normalizeWhatsAppTarget,
|
|
35
|
-
} from "./normalize.js";
|
|
36
|
-
import { getWhatsAppRuntime } from "./runtime.js";
|
|
37
|
-
import { sendTypingWhatsApp } from "./send.js";
|
|
38
|
-
import { resolveWhatsAppOutboundSessionRoute } from "./session-route.js";
|
|
39
|
-
import { whatsappSetupAdapter } from "./setup-core.js";
|
|
40
|
-
import {
|
|
41
|
-
createWhatsAppPluginBase,
|
|
42
|
-
loadWhatsAppChannelRuntime,
|
|
43
|
-
whatsappSetupWizardProxy,
|
|
44
|
-
} from "./shared.js";
|
|
45
|
-
import { detectWhatsAppLegacyStateMigrations } from "./state-migrations.js";
|
|
46
|
-
import { collectWhatsAppStatusIssues } from "./status-issues.js";
|
|
47
|
-
|
|
48
|
-
const loadWhatsAppDirectoryConfig = createLazyRuntimeModule(() => import("./directory-config.js"));
|
|
49
|
-
const loadWhatsAppChannelReactAction = createLazyRuntimeModule(
|
|
50
|
-
() => import("./channel-react-action.js"),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
function parseWhatsAppExplicitTarget(raw: string) {
|
|
54
|
-
const normalized = normalizeWhatsAppTarget(raw);
|
|
55
|
-
if (!normalized) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
to: normalized,
|
|
60
|
-
chatType: isWhatsAppGroupJid(normalized)
|
|
61
|
-
? ("group" as const)
|
|
62
|
-
: isWhatsAppNewsletterJid(normalized)
|
|
63
|
-
? ("channel" as const)
|
|
64
|
-
: ("direct" as const),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const whatsappPlugin: ChannelPlugin<ResolvedWhatsAppAccount> =
|
|
69
|
-
createChatChannelPlugin<ResolvedWhatsAppAccount>({
|
|
70
|
-
pairing: {
|
|
71
|
-
idLabel: "whatsappSenderId",
|
|
72
|
-
},
|
|
73
|
-
outbound: whatsappChannelOutbound,
|
|
74
|
-
threading: {
|
|
75
|
-
scopedAccountReplyToMode: {
|
|
76
|
-
resolveAccount: (cfg, accountId) => resolveWhatsAppAccount({ cfg, accountId }),
|
|
77
|
-
resolveReplyToMode: (account) => account.replyToMode,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
base: {
|
|
81
|
-
...createWhatsAppPluginBase({
|
|
82
|
-
groups: {
|
|
83
|
-
resolveRequireMention: resolveWhatsAppGroupRequireMention,
|
|
84
|
-
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
|
|
85
|
-
resolveGroupIntroHint: resolveWhatsAppGroupIntroHint,
|
|
86
|
-
},
|
|
87
|
-
setupWizard: whatsappSetupWizardProxy,
|
|
88
|
-
setup: whatsappSetupAdapter,
|
|
89
|
-
isConfigured: async (account) => {
|
|
90
|
-
const channelRuntime = await loadWhatsAppChannelRuntime();
|
|
91
|
-
return (await channelRuntime.readWebAuthState(account.authDir)) === "linked";
|
|
92
|
-
},
|
|
93
|
-
}),
|
|
94
|
-
agentTools: () => [createWhatsAppLoginTool()],
|
|
95
|
-
allowlist: buildDmGroupAccountAllowlistAdapter({
|
|
96
|
-
channelId: "whatsapp",
|
|
97
|
-
resolveAccount: resolveWhatsAppAccount,
|
|
98
|
-
normalize: ({ values }) => formatWhatsAppConfigAllowFromEntries(values),
|
|
99
|
-
resolveDmAllowFrom: (account) => account.allowFrom,
|
|
100
|
-
resolveGroupAllowFrom: (account) => account.groupAllowFrom,
|
|
101
|
-
resolveDmPolicy: (account) => account.dmPolicy,
|
|
102
|
-
resolveGroupPolicy: (account) => account.groupPolicy,
|
|
103
|
-
}),
|
|
104
|
-
mentions: {
|
|
105
|
-
stripRegexes: ({ ctx }) => resolveWhatsAppMentionStripRegexes(ctx),
|
|
106
|
-
},
|
|
107
|
-
commands: whatsappCommandPolicy,
|
|
108
|
-
agentPrompt: {
|
|
109
|
-
reactionGuidance: ({ cfg, accountId }) => {
|
|
110
|
-
const level = resolveWhatsAppAgentReactionGuidance({
|
|
111
|
-
cfg,
|
|
112
|
-
accountId: accountId ?? undefined,
|
|
113
|
-
});
|
|
114
|
-
return level ? { level, channelLabel: "WhatsApp" } : undefined;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
messaging: {
|
|
118
|
-
targetPrefixes: ["whatsapp"],
|
|
119
|
-
normalizeTarget: normalizeWhatsAppMessagingTarget,
|
|
120
|
-
resolveOutboundSessionRoute: (params) => resolveWhatsAppOutboundSessionRoute(params),
|
|
121
|
-
parseExplicitTarget: ({ raw }) => parseWhatsAppExplicitTarget(raw),
|
|
122
|
-
inferTargetChatType: ({ to }) => parseWhatsAppExplicitTarget(to)?.chatType,
|
|
123
|
-
targetResolver: {
|
|
124
|
-
looksLikeId: looksLikeWhatsAppTargetId,
|
|
125
|
-
hint: "<E.164|group JID|newsletter JID>",
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
directory: {
|
|
129
|
-
self: async ({ cfg, accountId }) => {
|
|
130
|
-
const account = resolveWhatsAppAccount({ cfg, accountId });
|
|
131
|
-
const { e164, jid } = (await loadWhatsAppChannelRuntime()).readWebSelfId(account.authDir);
|
|
132
|
-
const id = e164 ?? jid;
|
|
133
|
-
if (!id) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
kind: "user",
|
|
138
|
-
id,
|
|
139
|
-
name: account.name,
|
|
140
|
-
raw: { e164, jid },
|
|
141
|
-
};
|
|
142
|
-
},
|
|
143
|
-
listPeers: async (params) =>
|
|
144
|
-
(await loadWhatsAppDirectoryConfig()).listWhatsAppDirectoryPeersFromConfig(params),
|
|
145
|
-
listGroups: async (params) =>
|
|
146
|
-
(await loadWhatsAppDirectoryConfig()).listWhatsAppDirectoryGroupsFromConfig(params),
|
|
147
|
-
},
|
|
148
|
-
actions: {
|
|
149
|
-
describeMessageTool: ({ cfg, accountId }) =>
|
|
150
|
-
describeWhatsAppMessageActions({ cfg, accountId }),
|
|
151
|
-
supportsAction: ({ action }) => action === "react",
|
|
152
|
-
resolveExecutionMode: ({ action }) => (action === "react" ? "gateway" : "local"),
|
|
153
|
-
handleAction: async ({ action, params, cfg, accountId, requesterSenderId, toolContext }) =>
|
|
154
|
-
await (
|
|
155
|
-
await loadWhatsAppChannelReactAction()
|
|
156
|
-
).handleWhatsAppReactAction({
|
|
157
|
-
action,
|
|
158
|
-
params,
|
|
159
|
-
cfg,
|
|
160
|
-
accountId,
|
|
161
|
-
requesterSenderId,
|
|
162
|
-
toolContext,
|
|
163
|
-
}),
|
|
164
|
-
},
|
|
165
|
-
approvalCapability: whatsappApprovalAuth,
|
|
166
|
-
auth: {
|
|
167
|
-
login: async ({ cfg, accountId, runtime, verbose }) => {
|
|
168
|
-
const resolvedAccountId =
|
|
169
|
-
accountId?.trim() ||
|
|
170
|
-
whatsappPlugin.config.defaultAccountId?.(cfg) ||
|
|
171
|
-
DEFAULT_ACCOUNT_ID;
|
|
172
|
-
await (
|
|
173
|
-
await loadWhatsAppChannelRuntime()
|
|
174
|
-
).loginWeb(Boolean(verbose), undefined, runtime, resolvedAccountId);
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
lifecycle: {
|
|
178
|
-
detectLegacyStateMigrations: ({ oauthDir }) =>
|
|
179
|
-
detectWhatsAppLegacyStateMigrations({ oauthDir }),
|
|
180
|
-
},
|
|
181
|
-
heartbeat: {
|
|
182
|
-
checkReady: async ({ cfg, accountId, deps }) =>
|
|
183
|
-
await checkWhatsAppHeartbeatReady({ cfg, accountId: accountId ?? undefined, deps }),
|
|
184
|
-
sendTyping: async ({ cfg, to, accountId }) => {
|
|
185
|
-
await sendTypingWhatsApp(to, {
|
|
186
|
-
cfg,
|
|
187
|
-
...(accountId ? { accountId } : {}),
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
status: createAsyncComputedAccountStatusAdapter<ResolvedWhatsAppAccount>({
|
|
192
|
-
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, {
|
|
193
|
-
connected: false,
|
|
194
|
-
reconnectAttempts: 0,
|
|
195
|
-
lastConnectedAt: null,
|
|
196
|
-
lastDisconnect: null,
|
|
197
|
-
lastInboundAt: null,
|
|
198
|
-
lastMessageAt: null,
|
|
199
|
-
lastEventAt: null,
|
|
200
|
-
healthState: "stopped",
|
|
201
|
-
}),
|
|
202
|
-
collectStatusIssues: collectWhatsAppStatusIssues,
|
|
203
|
-
buildChannelSummary: async ({ account, snapshot }) => {
|
|
204
|
-
const channelRuntime = await loadWhatsAppChannelRuntime();
|
|
205
|
-
const authDir = account.authDir;
|
|
206
|
-
const auth = authDir
|
|
207
|
-
? await channelRuntime.readWebAuthSnapshot(authDir)
|
|
208
|
-
: {
|
|
209
|
-
state: "not-linked" as const,
|
|
210
|
-
authAgeMs: null,
|
|
211
|
-
selfId: { e164: null, jid: null, lid: null },
|
|
212
|
-
};
|
|
213
|
-
const linked =
|
|
214
|
-
typeof snapshot.linked === "boolean"
|
|
215
|
-
? snapshot.linked
|
|
216
|
-
: auth.state === "unstable"
|
|
217
|
-
? undefined
|
|
218
|
-
: auth.state === "linked";
|
|
219
|
-
const summaryAuthState =
|
|
220
|
-
auth.state === "unstable"
|
|
221
|
-
? auth.state
|
|
222
|
-
: linked === true
|
|
223
|
-
? "linked"
|
|
224
|
-
: linked === false
|
|
225
|
-
? "not-linked"
|
|
226
|
-
: undefined;
|
|
227
|
-
const statusState = summaryAuthState === undefined ? undefined : summaryAuthState;
|
|
228
|
-
const configured =
|
|
229
|
-
auth.state === "unstable"
|
|
230
|
-
? typeof snapshot.configured === "boolean"
|
|
231
|
-
? snapshot.configured
|
|
232
|
-
: true
|
|
233
|
-
: typeof linked === "boolean"
|
|
234
|
-
? linked
|
|
235
|
-
: auth.state === "linked";
|
|
236
|
-
const authAgeMs = typeof linked === "boolean" && linked ? auth.authAgeMs : null;
|
|
237
|
-
const self =
|
|
238
|
-
typeof linked === "boolean" && linked
|
|
239
|
-
? auth.selfId
|
|
240
|
-
: { e164: null, jid: null, lid: null };
|
|
241
|
-
return {
|
|
242
|
-
configured,
|
|
243
|
-
...(statusState ? { statusState } : {}),
|
|
244
|
-
...(typeof linked === "boolean" ? { linked } : {}),
|
|
245
|
-
authAgeMs,
|
|
246
|
-
self,
|
|
247
|
-
running: snapshot.running ?? false,
|
|
248
|
-
connected: snapshot.connected ?? false,
|
|
249
|
-
lastConnectedAt: snapshot.lastConnectedAt ?? null,
|
|
250
|
-
lastDisconnect: snapshot.lastDisconnect ?? null,
|
|
251
|
-
reconnectAttempts: snapshot.reconnectAttempts,
|
|
252
|
-
lastInboundAt: snapshot.lastInboundAt ?? snapshot.lastMessageAt ?? null,
|
|
253
|
-
lastMessageAt: snapshot.lastMessageAt ?? null,
|
|
254
|
-
lastEventAt: snapshot.lastEventAt ?? null,
|
|
255
|
-
lastError: snapshot.lastError ?? null,
|
|
256
|
-
healthState: snapshot.healthState ?? undefined,
|
|
257
|
-
};
|
|
258
|
-
},
|
|
259
|
-
resolveAccountSnapshot: async ({ account, runtime }) => {
|
|
260
|
-
const channelRuntime = await loadWhatsAppChannelRuntime();
|
|
261
|
-
const authState = await channelRuntime.readWebAuthState(account.authDir);
|
|
262
|
-
return {
|
|
263
|
-
accountId: account.accountId,
|
|
264
|
-
name: account.name,
|
|
265
|
-
enabled: account.enabled,
|
|
266
|
-
configured: true,
|
|
267
|
-
extra: {
|
|
268
|
-
statusState: authState,
|
|
269
|
-
...(authState === "linked"
|
|
270
|
-
? { linked: true }
|
|
271
|
-
: authState === "not-linked"
|
|
272
|
-
? { linked: false }
|
|
273
|
-
: {}),
|
|
274
|
-
connected: runtime?.connected ?? false,
|
|
275
|
-
reconnectAttempts: runtime?.reconnectAttempts,
|
|
276
|
-
lastConnectedAt: runtime?.lastConnectedAt ?? null,
|
|
277
|
-
lastDisconnect: runtime?.lastDisconnect ?? null,
|
|
278
|
-
lastInboundAt: runtime?.lastInboundAt ?? runtime?.lastMessageAt ?? null,
|
|
279
|
-
lastMessageAt: runtime?.lastMessageAt ?? null,
|
|
280
|
-
lastEventAt: runtime?.lastEventAt ?? null,
|
|
281
|
-
healthState: runtime?.healthState ?? undefined,
|
|
282
|
-
dmPolicy: account.dmPolicy,
|
|
283
|
-
allowFrom: account.allowFrom,
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
},
|
|
287
|
-
resolveAccountState: ({ configured }) => (configured ? "linked" : "not linked"),
|
|
288
|
-
logSelfId: ({ account, runtime, includeChannelPrefix }) => {
|
|
289
|
-
void loadWhatsAppChannelRuntime().then((runtimeExports) =>
|
|
290
|
-
runtimeExports.logWebSelfId(account.authDir, runtime, includeChannelPrefix),
|
|
291
|
-
);
|
|
292
|
-
},
|
|
293
|
-
}),
|
|
294
|
-
gateway: {
|
|
295
|
-
startAccount: async (ctx) => {
|
|
296
|
-
const account = ctx.account;
|
|
297
|
-
const { e164, jid } = (await loadWhatsAppChannelRuntime()).readWebSelfId(account.authDir);
|
|
298
|
-
const identity = e164 ? e164 : jid ? `jid ${jid}` : "unknown";
|
|
299
|
-
ctx.log?.info(`[${account.accountId}] starting provider (${identity})`);
|
|
300
|
-
return (await loadWhatsAppChannelRuntime()).monitorWebChannel(
|
|
301
|
-
getWhatsAppRuntime().logging.shouldLogVerbose(),
|
|
302
|
-
undefined,
|
|
303
|
-
true,
|
|
304
|
-
undefined,
|
|
305
|
-
ctx.runtime,
|
|
306
|
-
ctx.abortSignal,
|
|
307
|
-
{
|
|
308
|
-
statusSink: (next: WebChannelStatus) =>
|
|
309
|
-
ctx.setStatus({ accountId: ctx.accountId, ...next }),
|
|
310
|
-
accountId: account.accountId,
|
|
311
|
-
},
|
|
312
|
-
);
|
|
313
|
-
},
|
|
314
|
-
loginWithQrStart: async ({ accountId, force, timeoutMs, verbose }) =>
|
|
315
|
-
await (
|
|
316
|
-
await loadWhatsAppChannelRuntime()
|
|
317
|
-
).startWebLoginWithQr({
|
|
318
|
-
accountId,
|
|
319
|
-
force,
|
|
320
|
-
timeoutMs,
|
|
321
|
-
verbose,
|
|
322
|
-
}),
|
|
323
|
-
loginWithQrWait: async ({ accountId, timeoutMs, currentQrDataUrl }) =>
|
|
324
|
-
await (
|
|
325
|
-
await loadWhatsAppChannelRuntime()
|
|
326
|
-
).waitForWebLogin({ accountId, timeoutMs, currentQrDataUrl }),
|
|
327
|
-
logoutAccount: async ({ account, runtime }) => {
|
|
328
|
-
const cleared = await (
|
|
329
|
-
await loadWhatsAppChannelRuntime()
|
|
330
|
-
).logoutWeb({
|
|
331
|
-
authDir: account.authDir,
|
|
332
|
-
isLegacyAuthDir: account.isLegacyAuthDir,
|
|
333
|
-
runtime,
|
|
334
|
-
});
|
|
335
|
-
return { cleared, loggedOut: cleared };
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
});
|
package/src/command-policy.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
formatWhatsAppConfigAllowFromEntries,
|
|
4
|
-
resolveWhatsAppConfigAllowFrom,
|
|
5
|
-
resolveWhatsAppConfigDefaultTo,
|
|
6
|
-
} from "./config-accessors.js";
|
|
7
|
-
|
|
8
|
-
describe("whatsapp config accessors", () => {
|
|
9
|
-
it("reads merged allowFrom/defaultTo from resolved account config", () => {
|
|
10
|
-
const cfg = {
|
|
11
|
-
channels: {
|
|
12
|
-
whatsapp: {
|
|
13
|
-
defaultTo: " root:chat ",
|
|
14
|
-
allowFrom: ["+49111"],
|
|
15
|
-
accounts: {
|
|
16
|
-
alt: {
|
|
17
|
-
defaultTo: " alt:chat ",
|
|
18
|
-
allowFrom: ["+49222", "+49333"],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
expect(resolveWhatsAppConfigAllowFrom({ cfg, accountId: "alt" })).toEqual(["+49222", "+49333"]);
|
|
26
|
-
expect(resolveWhatsAppConfigDefaultTo({ cfg, accountId: "alt" })).toBe("alt:chat");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("normalizes allowFrom entries like the channel plugin", () => {
|
|
30
|
-
expect(
|
|
31
|
-
formatWhatsAppConfigAllowFromEntries([" whatsapp:+49123 ", "*", "49124@s.whatsapp.net"]),
|
|
32
|
-
).toEqual(["+49123", "*", "+49124"]);
|
|
33
|
-
});
|
|
34
|
-
});
|
package/src/config-accessors.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
import { resolveWhatsAppAccount } from "./accounts.js";
|
|
3
|
-
import { normalizeWhatsAppAllowFromEntries } from "./normalize-target.js";
|
|
4
|
-
|
|
5
|
-
export function resolveWhatsAppConfigAllowFrom(params: {
|
|
6
|
-
cfg: OpenClawConfig;
|
|
7
|
-
accountId?: string | null;
|
|
8
|
-
}): string[] {
|
|
9
|
-
return [...(resolveWhatsAppAccount(params).allowFrom ?? [])];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function formatWhatsAppConfigAllowFromEntries(allowFrom: Array<string | number>): string[] {
|
|
13
|
-
return normalizeWhatsAppAllowFromEntries(allowFrom);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function resolveWhatsAppConfigDefaultTo(params: {
|
|
17
|
-
cfg: OpenClawConfig;
|
|
18
|
-
accountId?: string | null;
|
|
19
|
-
}): string | undefined {
|
|
20
|
-
const defaultTo = resolveWhatsAppAccount(params).defaultTo?.trim();
|
|
21
|
-
return defaultTo || undefined;
|
|
22
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { WhatsAppConfigSchema } from "../config-api.js";
|
|
3
|
-
|
|
4
|
-
function expectWhatsAppConfigValid(config: unknown) {
|
|
5
|
-
const res = WhatsAppConfigSchema.safeParse(config);
|
|
6
|
-
expect(res.success).toBe(true);
|
|
7
|
-
return res;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe("whatsapp config schema", () => {
|
|
11
|
-
it('rejects dmPolicy="open" without allowFrom "*"', () => {
|
|
12
|
-
const res = WhatsAppConfigSchema.safeParse({
|
|
13
|
-
dmPolicy: "open",
|
|
14
|
-
allowFrom: ["+15555550123"],
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
expect(res.success).toBe(false);
|
|
18
|
-
if (!res.success) {
|
|
19
|
-
expect(res.error.issues[0]?.path.join(".")).toBe("allowFrom");
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('accepts dmPolicy="open" with allowFrom "*"', () => {
|
|
24
|
-
const res = WhatsAppConfigSchema.safeParse({ dmPolicy: "open", allowFrom: ["*"] });
|
|
25
|
-
|
|
26
|
-
expect(res.success).toBe(true);
|
|
27
|
-
if (res.success) {
|
|
28
|
-
expect(res.data.dmPolicy).toBe("open");
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("defaults dm/group policy", () => {
|
|
33
|
-
const res = WhatsAppConfigSchema.safeParse({});
|
|
34
|
-
|
|
35
|
-
expect(res.success).toBe(true);
|
|
36
|
-
if (res.success) {
|
|
37
|
-
expect(res.data.dmPolicy).toBe("pairing");
|
|
38
|
-
expect(res.data.groupPolicy).toBe("allowlist");
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("accepts historyLimit overrides per account", () => {
|
|
43
|
-
const res = WhatsAppConfigSchema.safeParse({
|
|
44
|
-
historyLimit: 9,
|
|
45
|
-
accounts: { work: { historyLimit: 4 } },
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(res.success).toBe(true);
|
|
49
|
-
if (res.success) {
|
|
50
|
-
expect(res.data.historyLimit).toBe(9);
|
|
51
|
-
expect(res.data.accounts?.work?.historyLimit).toBe(4);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("accepts textChunkLimit", () => {
|
|
56
|
-
const res = expectWhatsAppConfigValid({
|
|
57
|
-
allowFrom: ["+15555550123"],
|
|
58
|
-
textChunkLimit: 4444,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (res.success) {
|
|
62
|
-
expect(res.data.textChunkLimit).toBe(4444);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("accepts enabled", () => {
|
|
67
|
-
expectWhatsAppConfigValid({
|
|
68
|
-
enabled: true,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("keeps inherited account defaults unset at account scope", () => {
|
|
73
|
-
const res = expectWhatsAppConfigValid({
|
|
74
|
-
dmPolicy: "allowlist",
|
|
75
|
-
groupPolicy: "open",
|
|
76
|
-
debounceMs: 250,
|
|
77
|
-
allowFrom: ["+15550001111"],
|
|
78
|
-
accounts: {
|
|
79
|
-
work: {
|
|
80
|
-
allowFrom: ["+15550002222"],
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (!res.success) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
expect(res.data.dmPolicy).toBe("allowlist");
|
|
89
|
-
expect(res.data.groupPolicy).toBe("open");
|
|
90
|
-
expect(res.data.debounceMs).toBe(250);
|
|
91
|
-
expect(res.data.accounts?.work?.dmPolicy).toBeUndefined();
|
|
92
|
-
expect(res.data.accounts?.work?.groupPolicy).toBeUndefined();
|
|
93
|
-
expect(res.data.accounts?.work?.debounceMs).toBeUndefined();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("accepts allowlist accounts inheriting allowFrom from accounts.default", () => {
|
|
97
|
-
expectWhatsAppConfigValid({
|
|
98
|
-
accounts: {
|
|
99
|
-
default: {
|
|
100
|
-
allowFrom: ["+15550001111"],
|
|
101
|
-
},
|
|
102
|
-
work: {
|
|
103
|
-
dmPolicy: "allowlist",
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("accepts allowlist accounts inheriting allowFrom from mixed-case accounts.Default", () => {
|
|
110
|
-
expectWhatsAppConfigValid({
|
|
111
|
-
accounts: {
|
|
112
|
-
Default: {
|
|
113
|
-
allowFrom: ["+15550001111"],
|
|
114
|
-
},
|
|
115
|
-
work: {
|
|
116
|
-
dmPolicy: "allowlist",
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
package/src/config-schema.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { buildChannelConfigSchema, WhatsAppConfigSchema } from "../config-api.js";
|
|
2
|
-
import { whatsAppChannelConfigUiHints } from "./config-ui-hints.js";
|
|
3
|
-
|
|
4
|
-
export const WhatsAppChannelConfigSchema = buildChannelConfigSchema(WhatsAppConfigSchema, {
|
|
5
|
-
uiHints: whatsAppChannelConfigUiHints,
|
|
6
|
-
});
|
package/src/config-ui-hints.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ChannelConfigUiHint } from "openclaw/plugin-sdk/core";
|
|
2
|
-
|
|
3
|
-
export const whatsAppChannelConfigUiHints = {
|
|
4
|
-
"": {
|
|
5
|
-
label: "WhatsApp",
|
|
6
|
-
help: "WhatsApp channel provider configuration for access policy and message batching behavior. Use this section to tune responsiveness and direct-message routing safety for WhatsApp chats.",
|
|
7
|
-
},
|
|
8
|
-
dmPolicy: {
|
|
9
|
-
label: "WhatsApp DM Policy",
|
|
10
|
-
help: 'Direct message access control ("pairing" recommended). "open" requires channels.whatsapp.allowFrom=["*"].',
|
|
11
|
-
},
|
|
12
|
-
selfChatMode: {
|
|
13
|
-
label: "WhatsApp Self-Phone Mode",
|
|
14
|
-
help: "Same-phone setup (bot uses your personal WhatsApp number).",
|
|
15
|
-
},
|
|
16
|
-
debounceMs: {
|
|
17
|
-
label: "WhatsApp Message Debounce (ms)",
|
|
18
|
-
help: "Debounce window (ms) for batching rapid consecutive messages from the same sender (0 to disable).",
|
|
19
|
-
},
|
|
20
|
-
configWrites: {
|
|
21
|
-
label: "WhatsApp Config Writes",
|
|
22
|
-
help: "Allow WhatsApp to write config in response to channel events/commands (default: true).",
|
|
23
|
-
},
|
|
24
|
-
} satisfies Record<string, ChannelConfigUiHint>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
type RegistryModule = typeof import("./connection-controller-registry.js");
|
|
4
|
-
|
|
5
|
-
const registryModuleUrl = new URL("./connection-controller-registry.ts", import.meta.url).href;
|
|
6
|
-
|
|
7
|
-
async function importRegistryModule(cacheBust: string): Promise<RegistryModule> {
|
|
8
|
-
return (await import(`${registryModuleUrl}?t=${cacheBust}`)) as RegistryModule;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe("WhatsApp connection controller registry", () => {
|
|
12
|
-
it("shares registered controllers across duplicate module instances", async () => {
|
|
13
|
-
const first = await importRegistryModule(`first-${Date.now()}`);
|
|
14
|
-
const second = await importRegistryModule(`second-${Date.now()}`);
|
|
15
|
-
const controller = {
|
|
16
|
-
getActiveListener: vi.fn(() => null),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
first.registerWhatsAppConnectionController("work", controller);
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
expect(second.getRegisteredWhatsAppConnectionController("work")).toBe(controller);
|
|
23
|
-
} finally {
|
|
24
|
-
first.unregisterWhatsAppConnectionController("work", controller);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ActiveWebListener } from "./inbound/types.js";
|
|
2
|
-
|
|
3
|
-
type WhatsAppConnectionControllerHandle = {
|
|
4
|
-
getActiveListener(): ActiveWebListener | null;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
type ConnectionRegistryState = {
|
|
8
|
-
controllers: Map<string, WhatsAppConnectionControllerHandle>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const CONNECTION_REGISTRY_KEY = Symbol.for("openclaw.whatsapp.connectionControllerRegistry");
|
|
12
|
-
|
|
13
|
-
function getConnectionRegistryState(): ConnectionRegistryState {
|
|
14
|
-
const globalState = globalThis as typeof globalThis & {
|
|
15
|
-
[CONNECTION_REGISTRY_KEY]?: ConnectionRegistryState;
|
|
16
|
-
};
|
|
17
|
-
const existing = globalState[CONNECTION_REGISTRY_KEY];
|
|
18
|
-
if (existing) {
|
|
19
|
-
return existing;
|
|
20
|
-
}
|
|
21
|
-
const created: ConnectionRegistryState = {
|
|
22
|
-
controllers: new Map<string, WhatsAppConnectionControllerHandle>(),
|
|
23
|
-
};
|
|
24
|
-
globalState[CONNECTION_REGISTRY_KEY] = created;
|
|
25
|
-
return created;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function getRegisteredWhatsAppConnectionController(
|
|
29
|
-
accountId: string,
|
|
30
|
-
): WhatsAppConnectionControllerHandle | null {
|
|
31
|
-
return getConnectionRegistryState().controllers.get(accountId) ?? null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function registerWhatsAppConnectionController(
|
|
35
|
-
accountId: string,
|
|
36
|
-
controller: WhatsAppConnectionControllerHandle,
|
|
37
|
-
): void {
|
|
38
|
-
getConnectionRegistryState().controllers.set(accountId, controller);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function unregisterWhatsAppConnectionController(
|
|
42
|
-
accountId: string,
|
|
43
|
-
controller: WhatsAppConnectionControllerHandle,
|
|
44
|
-
): void {
|
|
45
|
-
const controllers = getConnectionRegistryState().controllers;
|
|
46
|
-
if (controllers.get(accountId) === controller) {
|
|
47
|
-
controllers.delete(accountId);
|
|
48
|
-
}
|
|
49
|
-
}
|