@openclaw/whatsapp 2026.5.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 -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/runtime-api.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
getActiveWebListener,
|
|
3
|
-
resolveWebAccountId,
|
|
4
|
-
type ActiveWebListener,
|
|
5
|
-
type ActiveWebSendOptions,
|
|
6
|
-
} from "./src/active-listener.js";
|
|
7
|
-
export { handleWhatsAppAction, whatsAppActionRuntime } from "./src/action-runtime.js";
|
|
8
|
-
export { createWhatsAppLoginTool } from "./src/agent-tools-login.js";
|
|
9
|
-
export {
|
|
10
|
-
formatWhatsAppWebAuthStatusState,
|
|
11
|
-
getWebAuthAgeMs,
|
|
12
|
-
hasWebCredsSync,
|
|
13
|
-
logWebSelfId,
|
|
14
|
-
logoutWeb,
|
|
15
|
-
pickWebChannel,
|
|
16
|
-
readCredsJsonRaw,
|
|
17
|
-
readWebAuthExistsBestEffort,
|
|
18
|
-
readWebAuthExistsForDecision,
|
|
19
|
-
readWebAuthSnapshot,
|
|
20
|
-
readWebAuthSnapshotBestEffort,
|
|
21
|
-
readWebAuthState,
|
|
22
|
-
readWebSelfId,
|
|
23
|
-
readWebSelfIdentity,
|
|
24
|
-
readWebSelfIdentityForDecision,
|
|
25
|
-
resolveDefaultWebAuthDir,
|
|
26
|
-
resolveWebCredsBackupPath,
|
|
27
|
-
resolveWebCredsPath,
|
|
28
|
-
restoreCredsFromBackupIfNeeded,
|
|
29
|
-
WA_WEB_AUTH_DIR,
|
|
30
|
-
webAuthExists,
|
|
31
|
-
WHATSAPP_AUTH_UNSTABLE_CODE,
|
|
32
|
-
WhatsAppAuthUnstableError,
|
|
33
|
-
type WhatsAppWebAuthState,
|
|
34
|
-
} from "./src/auth-store.js";
|
|
35
|
-
export {
|
|
36
|
-
DEFAULT_WEB_MEDIA_BYTES,
|
|
37
|
-
HEARTBEAT_PROMPT,
|
|
38
|
-
HEARTBEAT_TOKEN,
|
|
39
|
-
monitorWebChannel,
|
|
40
|
-
SILENT_REPLY_TOKEN,
|
|
41
|
-
stripHeartbeatToken,
|
|
42
|
-
type WebChannelStatus,
|
|
43
|
-
type WebMonitorTuning,
|
|
44
|
-
} from "./src/auto-reply.js";
|
|
45
|
-
export {
|
|
46
|
-
extractContactContext,
|
|
47
|
-
extractLocationData,
|
|
48
|
-
extractMediaPlaceholder,
|
|
49
|
-
extractText,
|
|
50
|
-
monitorWebInbox,
|
|
51
|
-
resetWebInboundDedupe,
|
|
52
|
-
type WebInboundMessage,
|
|
53
|
-
type WebListenerCloseReason,
|
|
54
|
-
} from "./src/inbound.js";
|
|
55
|
-
export { loginWeb } from "./src/login.js";
|
|
56
|
-
export {
|
|
57
|
-
getDefaultLocalRoots,
|
|
58
|
-
loadWebMedia,
|
|
59
|
-
loadWebMediaRaw,
|
|
60
|
-
LocalMediaAccessError,
|
|
61
|
-
optimizeImageToJpeg,
|
|
62
|
-
optimizeImageToPng,
|
|
63
|
-
type LocalMediaAccessErrorCode,
|
|
64
|
-
type WebMediaResult,
|
|
65
|
-
} from "./src/media.js";
|
|
66
|
-
export {
|
|
67
|
-
sendMessageWhatsApp,
|
|
68
|
-
sendPollWhatsApp,
|
|
69
|
-
sendReactionWhatsApp,
|
|
70
|
-
sendTypingWhatsApp,
|
|
71
|
-
} from "./src/send.js";
|
|
72
|
-
export {
|
|
73
|
-
createWaSocket,
|
|
74
|
-
formatError,
|
|
75
|
-
getStatusCode,
|
|
76
|
-
newConnectionId,
|
|
77
|
-
waitForCredsSaveQueue,
|
|
78
|
-
waitForCredsSaveQueueWithTimeout,
|
|
79
|
-
waitForWaConnection,
|
|
80
|
-
writeCredsJsonAtomically,
|
|
81
|
-
type CredsQueueWaitResult,
|
|
82
|
-
} from "./src/session.js";
|
|
83
|
-
export { setWhatsAppRuntime } from "./src/runtime.js";
|
|
84
|
-
export { startWebLoginWithQr, waitForWebLogin } from "./login-qr-runtime.js";
|
package/secret-contract-api.ts
DELETED
package/security-contract-api.ts
DELETED
package/setup-entry.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
vi.mock("@whiskeysockets/baileys", () => {
|
|
4
|
-
throw new Error("setup plugin load must not load Baileys");
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
describe("whatsapp setup entry", () => {
|
|
8
|
-
it("loads the setup plugin without installing or importing runtime dependencies", async () => {
|
|
9
|
-
const { default: setupEntry } = await import("./setup-entry.js");
|
|
10
|
-
const { whatsappSetupPlugin } = await import("./setup-plugin-api.js");
|
|
11
|
-
|
|
12
|
-
expect(setupEntry.kind).toBe("bundled-channel-setup-entry");
|
|
13
|
-
expect(whatsappSetupPlugin.id).toBe("whatsapp");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("loads the delegated setup wizard without importing runtime dependencies", async () => {
|
|
17
|
-
const { whatsappSetupWizard } = await import("./src/setup-surface.js");
|
|
18
|
-
|
|
19
|
-
expect(whatsappSetupWizard.channel).toBe("whatsapp");
|
|
20
|
-
});
|
|
21
|
-
});
|
package/setup-entry.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defineBundledChannelSetupEntry } from "openclaw/plugin-sdk/channel-entry-contract";
|
|
2
|
-
|
|
3
|
-
export default defineBundledChannelSetupEntry({
|
|
4
|
-
importMetaUrl: import.meta.url,
|
|
5
|
-
features: {
|
|
6
|
-
legacyStateMigrations: true,
|
|
7
|
-
legacySessionSurfaces: true,
|
|
8
|
-
},
|
|
9
|
-
plugin: {
|
|
10
|
-
specifier: "./setup-plugin-api.js",
|
|
11
|
-
exportName: "whatsappSetupPlugin",
|
|
12
|
-
},
|
|
13
|
-
legacyStateMigrations: {
|
|
14
|
-
specifier: "./legacy-state-migrations-api.js",
|
|
15
|
-
exportName: "detectWhatsAppLegacyStateMigrations",
|
|
16
|
-
},
|
|
17
|
-
legacySessionSurface: {
|
|
18
|
-
specifier: "./legacy-session-surface-api.js",
|
|
19
|
-
exportName: "whatsappLegacySessionSurface",
|
|
20
|
-
},
|
|
21
|
-
});
|
package/setup-plugin-api.ts
DELETED
package/src/account-config.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_ACCOUNT_ID,
|
|
3
|
-
mergeAccountConfig,
|
|
4
|
-
resolveAccountEntry,
|
|
5
|
-
resolveMergedAccountConfig,
|
|
6
|
-
type OpenClawConfig,
|
|
7
|
-
} from "openclaw/plugin-sdk/account-core";
|
|
8
|
-
import {
|
|
9
|
-
resolveChannelStreamingBlockEnabled,
|
|
10
|
-
resolveChannelStreamingChunkMode,
|
|
11
|
-
} from "openclaw/plugin-sdk/channel-streaming";
|
|
12
|
-
import type { WhatsAppAccountConfig } from "./account-types.js";
|
|
13
|
-
|
|
14
|
-
function resolveWhatsAppDefaultAccountSharedConfig(
|
|
15
|
-
cfg: OpenClawConfig,
|
|
16
|
-
): Partial<WhatsAppAccountConfig> | undefined {
|
|
17
|
-
const defaultAccount = resolveAccountEntry(cfg.channels?.whatsapp?.accounts, DEFAULT_ACCOUNT_ID);
|
|
18
|
-
if (!defaultAccount) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
const {
|
|
22
|
-
enabled: _ignoredEnabled,
|
|
23
|
-
name: _ignoredName,
|
|
24
|
-
authDir: _ignoredAuthDir,
|
|
25
|
-
selfChatMode: _ignoredSelfChatMode,
|
|
26
|
-
...sharedDefaults
|
|
27
|
-
} = defaultAccount;
|
|
28
|
-
return sharedDefaults;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _resolveWhatsAppAccountConfig(
|
|
32
|
-
cfg: OpenClawConfig,
|
|
33
|
-
accountId: string,
|
|
34
|
-
): WhatsAppAccountConfig | undefined {
|
|
35
|
-
return resolveAccountEntry(cfg.channels?.whatsapp?.accounts, accountId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function resolveMergedNamedWhatsAppAccountConfig(params: {
|
|
39
|
-
cfg: OpenClawConfig;
|
|
40
|
-
accountId: string;
|
|
41
|
-
}): WhatsAppAccountConfig {
|
|
42
|
-
const rootCfg = params.cfg.channels?.whatsapp;
|
|
43
|
-
const accountConfig = _resolveWhatsAppAccountConfig(params.cfg, params.accountId);
|
|
44
|
-
return {
|
|
45
|
-
...mergeAccountConfig<WhatsAppAccountConfig>({
|
|
46
|
-
channelConfig: rootCfg as WhatsAppAccountConfig | undefined,
|
|
47
|
-
accountConfig: undefined,
|
|
48
|
-
omitKeys: ["defaultAccount"],
|
|
49
|
-
}),
|
|
50
|
-
...resolveWhatsAppDefaultAccountSharedConfig(params.cfg),
|
|
51
|
-
...accountConfig,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function resolveMergedWhatsAppAccountConfig(params: {
|
|
56
|
-
cfg: OpenClawConfig;
|
|
57
|
-
accountId?: string | null;
|
|
58
|
-
}): WhatsAppAccountConfig & { accountId: string } {
|
|
59
|
-
const rootCfg = params.cfg.channels?.whatsapp;
|
|
60
|
-
const accountId = params.accountId?.trim() || rootCfg?.defaultAccount || DEFAULT_ACCOUNT_ID;
|
|
61
|
-
const base = resolveMergedAccountConfig<WhatsAppAccountConfig>({
|
|
62
|
-
channelConfig: rootCfg as WhatsAppAccountConfig | undefined,
|
|
63
|
-
accounts: rootCfg?.accounts as Record<string, Partial<WhatsAppAccountConfig>> | undefined,
|
|
64
|
-
accountId,
|
|
65
|
-
omitKeys: ["defaultAccount"],
|
|
66
|
-
});
|
|
67
|
-
const merged =
|
|
68
|
-
accountId === DEFAULT_ACCOUNT_ID
|
|
69
|
-
? base
|
|
70
|
-
: resolveMergedNamedWhatsAppAccountConfig({ cfg: params.cfg, accountId });
|
|
71
|
-
return {
|
|
72
|
-
accountId,
|
|
73
|
-
...merged,
|
|
74
|
-
chunkMode: resolveChannelStreamingChunkMode(merged) ?? merged.chunkMode,
|
|
75
|
-
blockStreaming: resolveChannelStreamingBlockEnabled(merged) ?? merged.blockStreaming,
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/account-ids.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createAccountListHelpers } from "openclaw/plugin-sdk/account-core";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
listConfiguredAccountIds,
|
|
5
|
-
listAccountIds,
|
|
6
|
-
resolveDefaultAccountId: resolveDefaultWhatsAppAccountId,
|
|
7
|
-
} = createAccountListHelpers("whatsapp");
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
listConfiguredAccountIds,
|
|
11
|
-
listAccountIds as listWhatsAppAccountIds,
|
|
12
|
-
resolveDefaultWhatsAppAccountId,
|
|
13
|
-
};
|
package/src/account-types.ts
DELETED
package/src/accounts.test.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { resolveWhatsAppAccount, resolveWhatsAppAuthDir } from "./accounts.js";
|
|
4
|
-
|
|
5
|
-
describe("resolveWhatsAppAuthDir", () => {
|
|
6
|
-
const stubCfg = { channels: { whatsapp: { accounts: {} } } } as Parameters<
|
|
7
|
-
typeof resolveWhatsAppAuthDir
|
|
8
|
-
>[0]["cfg"];
|
|
9
|
-
|
|
10
|
-
it("sanitizes path traversal sequences in accountId", () => {
|
|
11
|
-
const { authDir } = resolveWhatsAppAuthDir({
|
|
12
|
-
cfg: stubCfg,
|
|
13
|
-
accountId: "../../../etc/passwd",
|
|
14
|
-
});
|
|
15
|
-
// Sanitized accountId must not escape the whatsapp auth directory.
|
|
16
|
-
expect(authDir).not.toContain("..");
|
|
17
|
-
expect(path.basename(authDir)).not.toContain("/");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("sanitizes special characters in accountId", () => {
|
|
21
|
-
const { authDir } = resolveWhatsAppAuthDir({
|
|
22
|
-
cfg: stubCfg,
|
|
23
|
-
accountId: "foo/bar\\baz",
|
|
24
|
-
});
|
|
25
|
-
// Sprawdzaj sanityzacje na segmencie accountId, nie na calej sciezce
|
|
26
|
-
// (Windows uzywa backslash jako separator katalogow).
|
|
27
|
-
const segment = path.basename(authDir);
|
|
28
|
-
expect(segment).not.toContain("/");
|
|
29
|
-
expect(segment).not.toContain("\\");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("returns default directory for empty accountId", () => {
|
|
33
|
-
const { authDir } = resolveWhatsAppAuthDir({
|
|
34
|
-
cfg: stubCfg,
|
|
35
|
-
accountId: "",
|
|
36
|
-
});
|
|
37
|
-
expect(authDir).toMatch(/whatsapp[/\\]default$/);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("preserves valid accountId unchanged", () => {
|
|
41
|
-
const { authDir } = resolveWhatsAppAuthDir({
|
|
42
|
-
cfg: stubCfg,
|
|
43
|
-
accountId: "my-account-1",
|
|
44
|
-
});
|
|
45
|
-
expect(authDir).toMatch(/whatsapp[/\\]my-account-1$/);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("merges top-level and account-specific config through shared helpers", () => {
|
|
49
|
-
const resolved = resolveWhatsAppAccount({
|
|
50
|
-
cfg: {
|
|
51
|
-
messages: {
|
|
52
|
-
messagePrefix: "[global]",
|
|
53
|
-
},
|
|
54
|
-
channels: {
|
|
55
|
-
whatsapp: {
|
|
56
|
-
sendReadReceipts: false,
|
|
57
|
-
messagePrefix: "[root]",
|
|
58
|
-
debounceMs: 100,
|
|
59
|
-
accounts: {
|
|
60
|
-
work: {
|
|
61
|
-
debounceMs: 250,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
} as Parameters<typeof resolveWhatsAppAccount>[0]["cfg"],
|
|
67
|
-
accountId: "work",
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(resolved.sendReadReceipts).toBe(false);
|
|
71
|
-
expect(resolved.messagePrefix).toBe("[root]");
|
|
72
|
-
expect(resolved.debounceMs).toBe(250);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("inherits shared defaults from accounts.default for named accounts", () => {
|
|
76
|
-
const resolved = resolveWhatsAppAccount({
|
|
77
|
-
cfg: {
|
|
78
|
-
channels: {
|
|
79
|
-
whatsapp: {
|
|
80
|
-
accounts: {
|
|
81
|
-
default: {
|
|
82
|
-
dmPolicy: "allowlist",
|
|
83
|
-
allowFrom: ["+15550001111"],
|
|
84
|
-
groupPolicy: "open",
|
|
85
|
-
groupAllowFrom: ["+15550002222"],
|
|
86
|
-
defaultTo: "+15550003333",
|
|
87
|
-
reactionLevel: "extensive",
|
|
88
|
-
historyLimit: 42,
|
|
89
|
-
mediaMaxMb: 12,
|
|
90
|
-
},
|
|
91
|
-
work: {
|
|
92
|
-
authDir: "/tmp/work",
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
} as Parameters<typeof resolveWhatsAppAccount>[0]["cfg"],
|
|
98
|
-
accountId: "work",
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(resolved.dmPolicy).toBe("allowlist");
|
|
102
|
-
expect(resolved.allowFrom).toEqual(["+15550001111"]);
|
|
103
|
-
expect(resolved.groupPolicy).toBe("open");
|
|
104
|
-
expect(resolved.groupAllowFrom).toEqual(["+15550002222"]);
|
|
105
|
-
expect(resolved.defaultTo).toBe("+15550003333");
|
|
106
|
-
expect(resolved.reactionLevel).toBe("extensive");
|
|
107
|
-
expect(resolved.historyLimit).toBe(42);
|
|
108
|
-
expect(resolved.mediaMaxMb).toBe(12);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("prefers account overrides and accounts.default over root defaults", () => {
|
|
112
|
-
const resolved = resolveWhatsAppAccount({
|
|
113
|
-
cfg: {
|
|
114
|
-
channels: {
|
|
115
|
-
whatsapp: {
|
|
116
|
-
dmPolicy: "open",
|
|
117
|
-
allowFrom: ["*"],
|
|
118
|
-
groupPolicy: "disabled",
|
|
119
|
-
accounts: {
|
|
120
|
-
default: {
|
|
121
|
-
dmPolicy: "allowlist",
|
|
122
|
-
allowFrom: ["+15550001111"],
|
|
123
|
-
groupPolicy: "open",
|
|
124
|
-
},
|
|
125
|
-
work: {
|
|
126
|
-
authDir: "/tmp/work",
|
|
127
|
-
dmPolicy: "pairing",
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
} as Parameters<typeof resolveWhatsAppAccount>[0]["cfg"],
|
|
133
|
-
accountId: "work",
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
expect(resolved.dmPolicy).toBe("pairing");
|
|
137
|
-
expect(resolved.allowFrom).toEqual(["+15550001111"]);
|
|
138
|
-
expect(resolved.groupPolicy).toBe("open");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("does not inherit default-account authDir for named accounts", () => {
|
|
142
|
-
const resolved = resolveWhatsAppAccount({
|
|
143
|
-
cfg: {
|
|
144
|
-
channels: {
|
|
145
|
-
whatsapp: {
|
|
146
|
-
accounts: {
|
|
147
|
-
default: {
|
|
148
|
-
authDir: "/tmp/default-auth",
|
|
149
|
-
name: "Personal",
|
|
150
|
-
},
|
|
151
|
-
work: {},
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
} as Parameters<typeof resolveWhatsAppAccount>[0]["cfg"],
|
|
156
|
-
accountId: "work",
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(resolved.authDir).toMatch(/whatsapp[/\\]work$/);
|
|
160
|
-
expect(resolved.name).toBeUndefined();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("does not inherit default-account selfChatMode for named accounts", () => {
|
|
164
|
-
const resolved = resolveWhatsAppAccount({
|
|
165
|
-
cfg: {
|
|
166
|
-
channels: {
|
|
167
|
-
whatsapp: {
|
|
168
|
-
accounts: {
|
|
169
|
-
default: {
|
|
170
|
-
selfChatMode: true,
|
|
171
|
-
},
|
|
172
|
-
work: {},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
} as Parameters<typeof resolveWhatsAppAccount>[0]["cfg"],
|
|
177
|
-
accountId: "work",
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
expect(resolved.selfChatMode).toBeUndefined();
|
|
181
|
-
});
|
|
182
|
-
});
|
package/src/accounts.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_ACCOUNT_ID,
|
|
5
|
-
normalizeAccountId,
|
|
6
|
-
resolveUserPath,
|
|
7
|
-
type OpenClawConfig,
|
|
8
|
-
} from "openclaw/plugin-sdk/account-core";
|
|
9
|
-
import type { DmPolicy, GroupPolicy, ReplyToMode } from "openclaw/plugin-sdk/config-types";
|
|
10
|
-
import { resolveOAuthDir } from "openclaw/plugin-sdk/state-paths";
|
|
11
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
12
|
-
import { resolveMergedWhatsAppAccountConfig } from "./account-config.js";
|
|
13
|
-
import {
|
|
14
|
-
listConfiguredAccountIds,
|
|
15
|
-
listWhatsAppAccountIds,
|
|
16
|
-
resolveDefaultWhatsAppAccountId,
|
|
17
|
-
} from "./account-ids.js";
|
|
18
|
-
import type { WhatsAppAccountConfig } from "./account-types.js";
|
|
19
|
-
import { hasWebCredsSync } from "./creds-files.js";
|
|
20
|
-
|
|
21
|
-
export { listWhatsAppAccountIds, resolveDefaultWhatsAppAccountId } from "./account-ids.js";
|
|
22
|
-
|
|
23
|
-
export type ResolvedWhatsAppAccount = {
|
|
24
|
-
accountId: string;
|
|
25
|
-
name?: string;
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
sendReadReceipts: boolean;
|
|
28
|
-
messagePrefix?: string;
|
|
29
|
-
defaultTo?: string;
|
|
30
|
-
authDir: string;
|
|
31
|
-
isLegacyAuthDir: boolean;
|
|
32
|
-
selfChatMode?: boolean;
|
|
33
|
-
allowFrom?: string[];
|
|
34
|
-
groupAllowFrom?: string[];
|
|
35
|
-
groupPolicy?: GroupPolicy;
|
|
36
|
-
dmPolicy?: DmPolicy;
|
|
37
|
-
historyLimit?: number;
|
|
38
|
-
textChunkLimit?: number;
|
|
39
|
-
chunkMode?: "length" | "newline";
|
|
40
|
-
mediaMaxMb?: number;
|
|
41
|
-
blockStreaming?: boolean;
|
|
42
|
-
ackReaction?: WhatsAppAccountConfig["ackReaction"];
|
|
43
|
-
reactionLevel?: WhatsAppAccountConfig["reactionLevel"];
|
|
44
|
-
groups?: WhatsAppAccountConfig["groups"];
|
|
45
|
-
direct?: WhatsAppAccountConfig["direct"];
|
|
46
|
-
debounceMs?: number;
|
|
47
|
-
replyToMode?: ReplyToMode;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const DEFAULT_WHATSAPP_MEDIA_MAX_MB = 50;
|
|
51
|
-
|
|
52
|
-
export function listWhatsAppAuthDirs(cfg: OpenClawConfig): string[] {
|
|
53
|
-
const oauthDir = resolveOAuthDir();
|
|
54
|
-
const whatsappDir = path.join(oauthDir, "whatsapp");
|
|
55
|
-
const authDirs = new Set<string>([oauthDir, path.join(whatsappDir, DEFAULT_ACCOUNT_ID)]);
|
|
56
|
-
|
|
57
|
-
const accountIds = listConfiguredAccountIds(cfg);
|
|
58
|
-
for (const accountId of accountIds) {
|
|
59
|
-
authDirs.add(resolveWhatsAppAuthDir({ cfg, accountId }).authDir);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const entries = fs.readdirSync(whatsappDir, { withFileTypes: true });
|
|
64
|
-
for (const entry of entries) {
|
|
65
|
-
if (!entry.isDirectory()) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
authDirs.add(path.join(whatsappDir, entry.name));
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
// ignore missing dirs
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return Array.from(authDirs);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function hasAnyWhatsAppAuth(cfg: OpenClawConfig): boolean {
|
|
78
|
-
return listWhatsAppAuthDirs(cfg).some((authDir) => hasWebCredsSync(authDir));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function resolveDefaultAuthDir(accountId: string): string {
|
|
82
|
-
return path.join(resolveOAuthDir(), "whatsapp", normalizeAccountId(accountId));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function resolveLegacyAuthDir(): string {
|
|
86
|
-
// Legacy Baileys creds lived in the same directory as OAuth tokens.
|
|
87
|
-
return resolveOAuthDir();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function legacyAuthExists(authDir: string): boolean {
|
|
91
|
-
try {
|
|
92
|
-
return fs.existsSync(path.join(authDir, "creds.json"));
|
|
93
|
-
} catch {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function resolveWhatsAppAuthDir(params: { cfg: OpenClawConfig; accountId: string }): {
|
|
99
|
-
authDir: string;
|
|
100
|
-
isLegacy: boolean;
|
|
101
|
-
} {
|
|
102
|
-
const accountId = params.accountId.trim() || DEFAULT_ACCOUNT_ID;
|
|
103
|
-
const account = resolveMergedWhatsAppAccountConfig({ cfg: params.cfg, accountId });
|
|
104
|
-
const configured = account?.authDir?.trim();
|
|
105
|
-
if (configured) {
|
|
106
|
-
return { authDir: resolveUserPath(configured), isLegacy: false };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const defaultDir = resolveDefaultAuthDir(accountId);
|
|
110
|
-
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
111
|
-
const legacyDir = resolveLegacyAuthDir();
|
|
112
|
-
if (legacyAuthExists(legacyDir) && !legacyAuthExists(defaultDir)) {
|
|
113
|
-
return { authDir: legacyDir, isLegacy: true };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return { authDir: defaultDir, isLegacy: false };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function resolveWhatsAppAccount(params: {
|
|
121
|
-
cfg: OpenClawConfig;
|
|
122
|
-
accountId?: string | null;
|
|
123
|
-
}): ResolvedWhatsAppAccount {
|
|
124
|
-
const merged = resolveMergedWhatsAppAccountConfig({
|
|
125
|
-
cfg: params.cfg,
|
|
126
|
-
accountId: params.accountId?.trim() || resolveDefaultWhatsAppAccountId(params.cfg),
|
|
127
|
-
});
|
|
128
|
-
const accountId = merged.accountId;
|
|
129
|
-
const enabled = merged.enabled !== false;
|
|
130
|
-
const { authDir, isLegacy } = resolveWhatsAppAuthDir({
|
|
131
|
-
cfg: params.cfg,
|
|
132
|
-
accountId,
|
|
133
|
-
});
|
|
134
|
-
return {
|
|
135
|
-
accountId,
|
|
136
|
-
name: normalizeOptionalString(merged.name),
|
|
137
|
-
enabled,
|
|
138
|
-
sendReadReceipts: merged.sendReadReceipts ?? true,
|
|
139
|
-
messagePrefix: merged.messagePrefix ?? params.cfg.messages?.messagePrefix,
|
|
140
|
-
defaultTo: merged.defaultTo,
|
|
141
|
-
authDir,
|
|
142
|
-
isLegacyAuthDir: isLegacy,
|
|
143
|
-
selfChatMode: merged.selfChatMode,
|
|
144
|
-
dmPolicy: merged.dmPolicy,
|
|
145
|
-
allowFrom: merged.allowFrom,
|
|
146
|
-
groupAllowFrom: merged.groupAllowFrom,
|
|
147
|
-
groupPolicy: merged.groupPolicy,
|
|
148
|
-
historyLimit: merged.historyLimit,
|
|
149
|
-
textChunkLimit: merged.textChunkLimit,
|
|
150
|
-
chunkMode: merged.chunkMode,
|
|
151
|
-
mediaMaxMb: merged.mediaMaxMb,
|
|
152
|
-
blockStreaming: merged.blockStreaming,
|
|
153
|
-
ackReaction: merged.ackReaction,
|
|
154
|
-
reactionLevel: merged.reactionLevel,
|
|
155
|
-
groups: merged.groups,
|
|
156
|
-
direct: merged.direct,
|
|
157
|
-
debounceMs: merged.debounceMs,
|
|
158
|
-
replyToMode: merged.replyToMode,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function resolveWhatsAppMediaMaxBytes(
|
|
163
|
-
account: Pick<ResolvedWhatsAppAccount, "mediaMaxMb">,
|
|
164
|
-
): number {
|
|
165
|
-
const mediaMaxMb =
|
|
166
|
-
typeof account.mediaMaxMb === "number" && account.mediaMaxMb > 0
|
|
167
|
-
? account.mediaMaxMb
|
|
168
|
-
: DEFAULT_WHATSAPP_MEDIA_MAX_MB;
|
|
169
|
-
return mediaMaxMb * 1024 * 1024;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function listEnabledWhatsAppAccounts(cfg: OpenClawConfig): ResolvedWhatsAppAccount[] {
|
|
173
|
-
return listWhatsAppAccountIds(cfg)
|
|
174
|
-
.map((accountId) => resolveWhatsAppAccount({ cfg, accountId }))
|
|
175
|
-
.filter((account) => account.enabled);
|
|
176
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { captureEnv } from "openclaw/plugin-sdk/test-env";
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import { hasAnyWhatsAppAuth, listWhatsAppAuthDirs } from "./accounts.js";
|
|
7
|
-
|
|
8
|
-
describe("hasAnyWhatsAppAuth", () => {
|
|
9
|
-
let envSnapshot: ReturnType<typeof captureEnv>;
|
|
10
|
-
let tempOauthDir: string | undefined;
|
|
11
|
-
|
|
12
|
-
const writeCreds = (dir: string) => {
|
|
13
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
14
|
-
fs.writeFileSync(path.join(dir, "creds.json"), JSON.stringify({ me: {} }));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
envSnapshot = captureEnv(["OPENCLAW_OAUTH_DIR"]);
|
|
19
|
-
tempOauthDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-oauth-"));
|
|
20
|
-
process.env.OPENCLAW_OAUTH_DIR = tempOauthDir;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
envSnapshot.restore();
|
|
25
|
-
if (tempOauthDir) {
|
|
26
|
-
fs.rmSync(tempOauthDir, { recursive: true, force: true });
|
|
27
|
-
tempOauthDir = undefined;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("returns false when no auth exists", () => {
|
|
32
|
-
expect(hasAnyWhatsAppAuth({})).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("returns true when legacy auth exists", () => {
|
|
36
|
-
fs.writeFileSync(path.join(tempOauthDir ?? "", "creds.json"), JSON.stringify({ me: {} }));
|
|
37
|
-
expect(hasAnyWhatsAppAuth({})).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("returns true when non-default auth exists", () => {
|
|
41
|
-
writeCreds(path.join(tempOauthDir ?? "", "whatsapp", "work"));
|
|
42
|
-
expect(hasAnyWhatsAppAuth({})).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("includes authDir overrides", () => {
|
|
46
|
-
const customDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-wa-auth-"));
|
|
47
|
-
try {
|
|
48
|
-
writeCreds(customDir);
|
|
49
|
-
const cfg = {
|
|
50
|
-
channels: { whatsapp: { accounts: { work: { authDir: customDir } } } },
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
expect(listWhatsAppAuthDirs(cfg)).toContain(customDir);
|
|
54
|
-
expect(hasAnyWhatsAppAuth(cfg)).toBe(true);
|
|
55
|
-
} finally {
|
|
56
|
-
fs.rmSync(customDir, { recursive: true, force: true });
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ToolAuthorizationError } from "openclaw/plugin-sdk/channel-actions";
|
|
2
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
3
|
-
import { resolveWhatsAppAccount } from "./accounts.js";
|
|
4
|
-
import { resolveWhatsAppOutboundTarget } from "./resolve-outbound-target.js";
|
|
5
|
-
|
|
6
|
-
export function resolveAuthorizedWhatsAppOutboundTarget(params: {
|
|
7
|
-
cfg: OpenClawConfig;
|
|
8
|
-
chatJid: string;
|
|
9
|
-
accountId?: string;
|
|
10
|
-
actionLabel: string;
|
|
11
|
-
}): { to: string; accountId: string } {
|
|
12
|
-
const account = resolveWhatsAppAccount({
|
|
13
|
-
cfg: params.cfg,
|
|
14
|
-
accountId: params.accountId,
|
|
15
|
-
});
|
|
16
|
-
const resolution = resolveWhatsAppOutboundTarget({
|
|
17
|
-
to: params.chatJid,
|
|
18
|
-
allowFrom: account.allowFrom ?? [],
|
|
19
|
-
mode: "implicit",
|
|
20
|
-
});
|
|
21
|
-
if (!resolution.ok) {
|
|
22
|
-
throw new ToolAuthorizationError(
|
|
23
|
-
`WhatsApp ${params.actionLabel} blocked: chatJid "${params.chatJid}" is not in the configured allowFrom list for account "${account.accountId}".`,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
return { to: resolution.to, accountId: account.accountId };
|
|
27
|
-
}
|