@gakr-gakr/whatsapp 0.1.0
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 +67 -0
- package/auth-presence.ts +80 -0
- package/autobot.plugin.json +23 -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/doctor-contract-api.ts +8 -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/outbound-payload-test-api.ts +1 -0
- package/package.json +76 -0
- package/runtime-api.ts +84 -0
- package/secret-contract-api.ts +4 -0
- package/security-contract-api.ts +4 -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 +17 -0
- package/src/account-types.ts +5 -0
- package/src/accounts.ts +176 -0
- package/src/action-runtime-target-auth.ts +27 -0
- package/src/action-runtime.ts +76 -0
- package/src/active-listener.ts +17 -0
- package/src/agent-tools-login.ts +113 -0
- package/src/approval-auth.ts +27 -0
- package/src/auth-store.runtime.ts +1 -0
- package/src/auth-store.ts +494 -0
- package/src/auto-reply/config.runtime.ts +16 -0
- package/src/auto-reply/constants.ts +1 -0
- package/src/auto-reply/deliver-reply.ts +332 -0
- package/src/auto-reply/loggers.ts +6 -0
- package/src/auto-reply/mentions.ts +131 -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.ts +73 -0
- package/src/auto-reply/monitor/group-gating.runtime.ts +8 -0
- package/src/auto-reply/monitor/group-gating.ts +218 -0
- package/src/auto-reply/monitor/group-members.ts +65 -0
- package/src/auto-reply/monitor/inbound-context.ts +92 -0
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +22 -0
- package/src/auto-reply/monitor/inbound-dispatch.ts +749 -0
- package/src/auto-reply/monitor/last-route.ts +61 -0
- package/src/auto-reply/monitor/listener-log.ts +28 -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.ts +333 -0
- package/src/auto-reply/monitor/peer.ts +17 -0
- package/src/auto-reply/monitor/process-message.ts +584 -0
- package/src/auto-reply/monitor/runtime-api.ts +36 -0
- package/src/auto-reply/monitor/status-reaction.ts +108 -0
- package/src/auto-reply/monitor-state.ts +114 -0
- package/src/auto-reply/monitor.ts +720 -0
- package/src/auto-reply/reply-resolver.runtime.ts +1 -0
- package/src/auto-reply/types.ts +48 -0
- package/src/auto-reply/util.ts +62 -0
- package/src/auto-reply.impl.ts +6 -0
- package/src/auto-reply.ts +1 -0
- package/src/channel-actions.runtime.ts +7 -0
- package/src/channel-actions.ts +85 -0
- package/src/channel-outbound.ts +87 -0
- package/src/channel-react-action.runtime.ts +10 -0
- package/src/channel-react-action.ts +247 -0
- package/src/channel.runtime.ts +117 -0
- package/src/channel.setup.ts +32 -0
- package/src/channel.ts +356 -0
- package/src/command-policy.ts +7 -0
- package/src/config-accessors.ts +22 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +24 -0
- package/src/connection-controller-registry.ts +49 -0
- package/src/connection-controller.ts +680 -0
- package/src/creds-files.ts +19 -0
- package/src/creds-persistence.ts +71 -0
- package/src/directory-config.ts +40 -0
- package/src/doctor-contract.ts +11 -0
- package/src/doctor.ts +56 -0
- package/src/document-filename.ts +17 -0
- package/src/group-intro.ts +15 -0
- package/src/group-policy.ts +40 -0
- package/src/group-session-contract.ts +20 -0
- package/src/group-session-key.ts +42 -0
- package/src/heartbeat.ts +34 -0
- package/src/identity.ts +164 -0
- package/src/inbound/access-control.ts +187 -0
- package/src/inbound/dedupe.ts +132 -0
- package/src/inbound/extract.ts +484 -0
- package/src/inbound/lifecycle.ts +39 -0
- package/src/inbound/media.ts +128 -0
- package/src/inbound/monitor.ts +1042 -0
- package/src/inbound/outbound-mentions.ts +260 -0
- package/src/inbound/runtime-api.ts +7 -0
- package/src/inbound/save-media.runtime.ts +1 -0
- package/src/inbound/send-api.ts +203 -0
- package/src/inbound/send-result.ts +109 -0
- package/src/inbound/types.ts +107 -0
- package/src/inbound-policy.ts +215 -0
- package/src/inbound.ts +9 -0
- package/src/login-qr.ts +542 -0
- package/src/login.ts +83 -0
- package/src/media.ts +10 -0
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +417 -0
- package/src/monitor-inbox.append-upsert.test-support.ts +133 -0
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +418 -0
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +308 -0
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +824 -0
- package/src/normalize-target.ts +148 -0
- package/src/normalize.ts +8 -0
- package/src/outbound-adapter.ts +36 -0
- package/src/outbound-base.ts +256 -0
- package/src/outbound-media-contract.ts +307 -0
- package/src/outbound-media.runtime.ts +41 -0
- package/src/outbound-send-deps.ts +1 -0
- package/src/outbound-test-support.ts +16 -0
- package/src/qa-driver.runtime.ts +189 -0
- package/src/qr-image.ts +1 -0
- package/src/qr-terminal.ts +1 -0
- package/src/quoted-message.ts +184 -0
- package/src/reaction-level.ts +24 -0
- package/src/reconnect.ts +55 -0
- package/src/resolve-outbound-target.ts +58 -0
- package/src/runtime-api.ts +59 -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.ts +342 -0
- package/src/session-contract.ts +43 -0
- package/src/session-errors.ts +125 -0
- package/src/session-route.ts +32 -0
- package/src/session.runtime.ts +8 -0
- package/src/session.ts +327 -0
- package/src/setup-core.ts +52 -0
- package/src/setup-finalize.ts +450 -0
- package/src/setup-surface.ts +71 -0
- package/src/setup-test-helpers.ts +217 -0
- package/src/shared.ts +291 -0
- package/src/socket-timing.ts +38 -0
- package/src/state-migrations.ts +55 -0
- package/src/status-issues.ts +185 -0
- package/src/system-prompt.ts +31 -0
- package/src/targets-runtime.ts +221 -0
- package/src/text-runtime.ts +18 -0
- package/src/vcard.ts +84 -0
- package/targets.ts +5 -0
- package/test-api.ts +2 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { handleWhatsAppAction } from "./src/action-runtime.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { handleWhatsAppAction } from "./src/action-runtime.js";
|
package/api.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export { whatsappPlugin } from "./src/channel.js";
|
|
2
|
+
export { whatsappSetupPlugin } from "./src/channel.setup.js";
|
|
3
|
+
export {
|
|
4
|
+
DEFAULT_WHATSAPP_MEDIA_MAX_MB,
|
|
5
|
+
hasAnyWhatsAppAuth,
|
|
6
|
+
listEnabledWhatsAppAccounts,
|
|
7
|
+
listWhatsAppAccountIds,
|
|
8
|
+
listWhatsAppAuthDirs,
|
|
9
|
+
resolveDefaultWhatsAppAccountId,
|
|
10
|
+
type ResolvedWhatsAppAccount,
|
|
11
|
+
resolveWhatsAppAccount,
|
|
12
|
+
resolveWhatsAppAuthDir,
|
|
13
|
+
resolveWhatsAppMediaMaxBytes,
|
|
14
|
+
} from "./src/accounts.js";
|
|
15
|
+
export { DEFAULT_WEB_MEDIA_BYTES } from "./src/auto-reply/constants.js";
|
|
16
|
+
export { whatsappCommandPolicy } from "./src/command-policy.js";
|
|
17
|
+
export {
|
|
18
|
+
resolveWhatsAppGroupRequireMention,
|
|
19
|
+
resolveWhatsAppGroupToolPolicy,
|
|
20
|
+
} from "./src/group-policy.js";
|
|
21
|
+
export { WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS } from "./src/outbound-send-deps.js";
|
|
22
|
+
export {
|
|
23
|
+
assertWebChannel,
|
|
24
|
+
isSelfChatMode,
|
|
25
|
+
jidToE164,
|
|
26
|
+
markdownToWhatsApp,
|
|
27
|
+
normalizeE164,
|
|
28
|
+
resolveJidToE164,
|
|
29
|
+
resolveUserPath,
|
|
30
|
+
toWhatsappJid,
|
|
31
|
+
toWhatsappJidWithLid,
|
|
32
|
+
type JidToE164Options,
|
|
33
|
+
type WebChannel,
|
|
34
|
+
} from "./src/text-runtime.js";
|
|
35
|
+
export {
|
|
36
|
+
type WebChannelHealthState,
|
|
37
|
+
type WebChannelStatus,
|
|
38
|
+
type WebInboundMsg,
|
|
39
|
+
type WebMonitorTuning,
|
|
40
|
+
} from "./src/auto-reply/types.js";
|
|
41
|
+
export {
|
|
42
|
+
type ActiveWebListener,
|
|
43
|
+
type ActiveWebSendOptions,
|
|
44
|
+
type WebInboundMessage,
|
|
45
|
+
type WebListenerCloseReason,
|
|
46
|
+
type WhatsAppStructuredContactContext,
|
|
47
|
+
} from "./src/inbound/types.js";
|
|
48
|
+
export {
|
|
49
|
+
listWhatsAppDirectoryGroupsFromConfig,
|
|
50
|
+
listWhatsAppDirectoryPeersFromConfig,
|
|
51
|
+
} from "./src/directory-config.js";
|
|
52
|
+
export { resolveWhatsAppOutboundTarget } from "./src/resolve-outbound-target.js";
|
|
53
|
+
export {
|
|
54
|
+
isWhatsAppGroupJid,
|
|
55
|
+
normalizeWhatsAppAllowFromEntries,
|
|
56
|
+
isWhatsAppUserTarget,
|
|
57
|
+
looksLikeWhatsAppTargetId,
|
|
58
|
+
normalizeWhatsAppMessagingTarget,
|
|
59
|
+
normalizeWhatsAppTarget,
|
|
60
|
+
} from "./src/normalize-target.js";
|
|
61
|
+
export { resolveWhatsAppGroupIntroHint } from "./src/runtime-api.js";
|
|
62
|
+
export { testing as whatsappAccessControlTesting } from "./src/inbound/access-control.js";
|
|
63
|
+
export {
|
|
64
|
+
startWhatsAppQaDriverSession,
|
|
65
|
+
type WhatsAppQaDriverObservedMessage,
|
|
66
|
+
type WhatsAppQaDriverSession,
|
|
67
|
+
} from "./src/qa-driver.runtime.js";
|
package/auth-presence.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "autobot/plugin-sdk/account-id";
|
|
4
|
+
import { resolveUserPath } from "autobot/plugin-sdk/account-resolution";
|
|
5
|
+
import type { AutoBotConfig } from "autobot/plugin-sdk/config-contracts";
|
|
6
|
+
import { resolveOAuthDir } from "autobot/plugin-sdk/state-paths";
|
|
7
|
+
import { hasWebCredsSync } from "./src/creds-files.js";
|
|
8
|
+
|
|
9
|
+
type WhatsAppAuthPresenceParams =
|
|
10
|
+
| {
|
|
11
|
+
cfg: AutoBotConfig;
|
|
12
|
+
env?: NodeJS.ProcessEnv;
|
|
13
|
+
}
|
|
14
|
+
| AutoBotConfig;
|
|
15
|
+
|
|
16
|
+
function addAccountAuthDirs(
|
|
17
|
+
authDirs: Set<string>,
|
|
18
|
+
accountId: string,
|
|
19
|
+
authDir: string | undefined,
|
|
20
|
+
accountsRoot: string,
|
|
21
|
+
env: NodeJS.ProcessEnv,
|
|
22
|
+
): void {
|
|
23
|
+
authDirs.add(path.join(accountsRoot, normalizeAccountId(accountId)));
|
|
24
|
+
const configuredAuthDir = authDir?.trim();
|
|
25
|
+
if (configuredAuthDir) {
|
|
26
|
+
authDirs.add(resolveUserPath(configuredAuthDir, env));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function listWhatsAppAuthDirs(
|
|
31
|
+
cfg: AutoBotConfig,
|
|
32
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
33
|
+
): readonly string[] {
|
|
34
|
+
const oauthDir = resolveOAuthDir(env);
|
|
35
|
+
const accountsRoot = path.join(oauthDir, "whatsapp");
|
|
36
|
+
const channel = cfg.channels?.whatsapp;
|
|
37
|
+
const authDirs = new Set<string>([oauthDir, path.join(accountsRoot, DEFAULT_ACCOUNT_ID)]);
|
|
38
|
+
|
|
39
|
+
addAccountAuthDirs(authDirs, DEFAULT_ACCOUNT_ID, undefined, accountsRoot, env);
|
|
40
|
+
|
|
41
|
+
if (channel?.defaultAccount?.trim()) {
|
|
42
|
+
addAccountAuthDirs(
|
|
43
|
+
authDirs,
|
|
44
|
+
channel.defaultAccount,
|
|
45
|
+
channel.accounts?.[channel.defaultAccount]?.authDir,
|
|
46
|
+
accountsRoot,
|
|
47
|
+
env,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const accounts = channel?.accounts;
|
|
52
|
+
if (accounts) {
|
|
53
|
+
for (const [accountId, account] of Object.entries(accounts)) {
|
|
54
|
+
addAccountAuthDirs(authDirs, accountId, account?.authDir, accountsRoot, env);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const entries = fs.readdirSync(accountsRoot, { withFileTypes: true });
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
if (entry.isDirectory()) {
|
|
62
|
+
authDirs.add(path.join(accountsRoot, entry.name));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
// Missing directories mean no auth state.
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return [...authDirs];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function hasAnyWhatsAppAuth(
|
|
73
|
+
params: WhatsAppAuthPresenceParams,
|
|
74
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
75
|
+
): boolean {
|
|
76
|
+
const cfg = params && typeof params === "object" && "cfg" in params ? params.cfg : params;
|
|
77
|
+
const resolvedEnv =
|
|
78
|
+
params && typeof params === "object" && "cfg" in params ? (params.env ?? env) : env;
|
|
79
|
+
return listWhatsAppAuthDirs(cfg, resolvedEnv).some((authDir) => hasWebCredsSync(authDir));
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "whatsapp",
|
|
3
|
+
"activation": {
|
|
4
|
+
"onStartup": false
|
|
5
|
+
},
|
|
6
|
+
"channels": ["whatsapp"],
|
|
7
|
+
"configSchema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"pluginHooks": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"additionalProperties": false,
|
|
14
|
+
"properties": {
|
|
15
|
+
"messageReceived": {
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"description": "Opt in to broadcasting inbound WhatsApp message_received hook payloads to loaded plugins."
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WhatsAppChannelConfigSchema } from "./src/config-schema.js";
|
package/config-api.ts
ADDED
package/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_WEB_MEDIA_BYTES } from "./src/auto-reply/constants.js";
|
package/contract-api.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { whatsappCommandPolicy as whatsappCommandPolicyImpl } from "./src/command-policy.js";
|
|
2
|
+
import { resolveLegacyGroupSessionKey as resolveLegacyGroupSessionKeyImpl } from "./src/group-session-contract.js";
|
|
3
|
+
import { testing as whatsappAccessControlTestingImpl } from "./src/inbound/access-control.js";
|
|
4
|
+
import {
|
|
5
|
+
isWhatsAppGroupJid as isWhatsAppGroupJidImpl,
|
|
6
|
+
normalizeWhatsAppTarget as normalizeWhatsAppTargetImpl,
|
|
7
|
+
} from "./src/normalize-target.js";
|
|
8
|
+
export {
|
|
9
|
+
listWhatsAppDirectoryGroupsFromConfig,
|
|
10
|
+
listWhatsAppDirectoryPeersFromConfig,
|
|
11
|
+
} from "./src/directory-config.js";
|
|
12
|
+
import { resolveWhatsAppRuntimeGroupPolicy as resolveWhatsAppRuntimeGroupPolicyImpl } from "./src/runtime-group-policy.js";
|
|
13
|
+
import {
|
|
14
|
+
canonicalizeLegacySessionKey as canonicalizeLegacySessionKeyImpl,
|
|
15
|
+
isLegacyGroupSessionKey as isLegacyGroupSessionKeyImpl,
|
|
16
|
+
} from "./src/session-contract.js";
|
|
17
|
+
export {
|
|
18
|
+
collectUnsupportedSecretRefConfigCandidates,
|
|
19
|
+
unsupportedSecretRefSurfacePatterns,
|
|
20
|
+
} from "./src/security-contract.js";
|
|
21
|
+
|
|
22
|
+
export const canonicalizeLegacySessionKey = canonicalizeLegacySessionKeyImpl;
|
|
23
|
+
export const isLegacyGroupSessionKey = isLegacyGroupSessionKeyImpl;
|
|
24
|
+
export const isWhatsAppGroupJid = isWhatsAppGroupJidImpl;
|
|
25
|
+
export const normalizeWhatsAppTarget = normalizeWhatsAppTargetImpl;
|
|
26
|
+
export const resolveLegacyGroupSessionKey = resolveLegacyGroupSessionKeyImpl;
|
|
27
|
+
export const resolveWhatsAppRuntimeGroupPolicy = resolveWhatsAppRuntimeGroupPolicyImpl;
|
|
28
|
+
export const whatsappAccessControlTesting = whatsappAccessControlTestingImpl;
|
|
29
|
+
export const whatsappCommandPolicy = whatsappCommandPolicyImpl;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChannelDoctorLegacyConfigRule } from "autobot/plugin-sdk/channel-contract";
|
|
2
|
+
|
|
3
|
+
export { normalizeCompatibilityConfig } from "./src/doctor-contract.js";
|
|
4
|
+
|
|
5
|
+
// WhatsApp currently exposes doctor compatibility fixes without extra legacy
|
|
6
|
+
// rule scans. Keep that empty answer on a lightweight contract surface so
|
|
7
|
+
// config validation stays off the broad contract-api import path.
|
|
8
|
+
export const legacyConfigRules: ChannelDoctorLegacyConfigRule[] = [];
|
package/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineBundledChannelEntry } from "autobot/plugin-sdk/channel-entry-contract";
|
|
2
|
+
|
|
3
|
+
export default defineBundledChannelEntry({
|
|
4
|
+
id: "whatsapp",
|
|
5
|
+
name: "WhatsApp",
|
|
6
|
+
description: "WhatsApp channel plugin",
|
|
7
|
+
importMetaUrl: import.meta.url,
|
|
8
|
+
plugin: {
|
|
9
|
+
specifier: "./channel-plugin-api.js",
|
|
10
|
+
exportName: "whatsappPlugin",
|
|
11
|
+
},
|
|
12
|
+
runtime: {
|
|
13
|
+
specifier: "./runtime-api.js",
|
|
14
|
+
exportName: "setWhatsAppRuntime",
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { detectWhatsAppLegacyStateMigrations } from "./src/state-migrations.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { getActiveWebListener } from "./src/active-listener.js";
|
|
2
|
+
export {
|
|
3
|
+
getWebAuthAgeMs,
|
|
4
|
+
logWebSelfId,
|
|
5
|
+
logoutWeb,
|
|
6
|
+
pickWebChannel,
|
|
7
|
+
readWebSelfId,
|
|
8
|
+
WA_WEB_AUTH_DIR,
|
|
9
|
+
webAuthExists,
|
|
10
|
+
} from "./src/auth-store.js";
|
|
11
|
+
export { createWhatsAppLoginTool } from "./src/agent-tools-login.js";
|
|
12
|
+
export { formatError, getStatusCode } from "./src/session-errors.js";
|
package/login-qr-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { startWebLoginWithQr, waitForWebLogin } from "./login-qr-runtime.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type StartWebLoginWithQr = typeof import("./src/login-qr.js").startWebLoginWithQr;
|
|
2
|
+
type WaitForWebLogin = typeof import("./src/login-qr.js").waitForWebLogin;
|
|
3
|
+
|
|
4
|
+
let loginQrModulePromise: Promise<typeof import("./src/login-qr.js")> | null = null;
|
|
5
|
+
|
|
6
|
+
function loadLoginQrModule() {
|
|
7
|
+
loginQrModulePromise ??= import("./src/login-qr.js");
|
|
8
|
+
return loginQrModulePromise;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function startWebLoginWithQr(
|
|
12
|
+
...args: Parameters<StartWebLoginWithQr>
|
|
13
|
+
): ReturnType<StartWebLoginWithQr> {
|
|
14
|
+
const { startWebLoginWithQr } = await loadLoginQrModule();
|
|
15
|
+
return await startWebLoginWithQr(...args);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function waitForWebLogin(
|
|
19
|
+
...args: Parameters<WaitForWebLogin>
|
|
20
|
+
): ReturnType<WaitForWebLogin> {
|
|
21
|
+
const { waitForWebLogin } = await loadLoginQrModule();
|
|
22
|
+
return await waitForWebLogin(...args);
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { whatsappOutbound } from "./src/outbound-adapter.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gakr-gakr/whatsapp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AutoBot WhatsApp channel plugin",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/autobot/autobot"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"audio-decode": "2.2.3",
|
|
12
|
+
"baileys": "7.0.0-rc11",
|
|
13
|
+
"https-proxy-agent": "9.0.0",
|
|
14
|
+
"jimp": "1.6.1",
|
|
15
|
+
"typebox": "1.1.38"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@gakr-gakr/plugin-sdk": "workspace:*",
|
|
19
|
+
"@gakr-gakr/autobot": "workspace:*",
|
|
20
|
+
"autobot": "workspace:@gakr-gakr/autobot@*"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@gakr-gakr/autobot": ">=0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"@gakr-gakr/autobot": {
|
|
27
|
+
"optional": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"autobot": {
|
|
31
|
+
"extensions": [
|
|
32
|
+
"./index.ts"
|
|
33
|
+
],
|
|
34
|
+
"setupEntry": "./setup-entry.ts",
|
|
35
|
+
"setupFeatures": {
|
|
36
|
+
"legacyStateMigrations": true,
|
|
37
|
+
"legacySessionSurfaces": true
|
|
38
|
+
},
|
|
39
|
+
"channel": {
|
|
40
|
+
"id": "whatsapp",
|
|
41
|
+
"label": "WhatsApp",
|
|
42
|
+
"selectionLabel": "WhatsApp (QR link)",
|
|
43
|
+
"detailLabel": "WhatsApp Web",
|
|
44
|
+
"docsPath": "/channels/whatsapp",
|
|
45
|
+
"docsLabel": "whatsapp",
|
|
46
|
+
"blurb": "works with your own number; recommend a separate phone + eSIM.",
|
|
47
|
+
"systemImage": "message",
|
|
48
|
+
"persistedAuthState": {
|
|
49
|
+
"specifier": "./auth-presence",
|
|
50
|
+
"exportName": "hasAnyWhatsAppAuth"
|
|
51
|
+
},
|
|
52
|
+
"cliAddOptions": [
|
|
53
|
+
{
|
|
54
|
+
"flags": "--auth-dir <path>",
|
|
55
|
+
"description": "WhatsApp auth directory override"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"install": {
|
|
60
|
+
"clawhubSpec": "clawhub:@gakr-gakr/whatsapp",
|
|
61
|
+
"npmSpec": "@gakr-gakr/whatsapp",
|
|
62
|
+
"defaultChoice": "clawhub",
|
|
63
|
+
"minHostVersion": ">=2026.4.25"
|
|
64
|
+
},
|
|
65
|
+
"compat": {
|
|
66
|
+
"pluginApi": ">=2026.5.19"
|
|
67
|
+
},
|
|
68
|
+
"build": {
|
|
69
|
+
"autobotVersion": "2026.5.19"
|
|
70
|
+
},
|
|
71
|
+
"release": {
|
|
72
|
+
"publishToClawHub": true,
|
|
73
|
+
"publishToNpm": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/runtime-api.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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/setup-entry.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineBundledChannelSetupEntry } from "autobot/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
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ACCOUNT_ID,
|
|
3
|
+
mergeAccountConfig,
|
|
4
|
+
resolveAccountEntry,
|
|
5
|
+
resolveMergedAccountConfig,
|
|
6
|
+
type AutoBotConfig,
|
|
7
|
+
} from "autobot/plugin-sdk/account-core";
|
|
8
|
+
import {
|
|
9
|
+
resolveChannelStreamingBlockEnabled,
|
|
10
|
+
resolveChannelStreamingChunkMode,
|
|
11
|
+
} from "autobot/plugin-sdk/channel-streaming";
|
|
12
|
+
import type { WhatsAppAccountConfig } from "./account-types.js";
|
|
13
|
+
|
|
14
|
+
function resolveWhatsAppDefaultAccountSharedConfig(
|
|
15
|
+
cfg: AutoBotConfig,
|
|
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 resolveWhatsAppAccountConfigForTest(
|
|
32
|
+
cfg: AutoBotConfig,
|
|
33
|
+
accountId: string,
|
|
34
|
+
): WhatsAppAccountConfig | undefined {
|
|
35
|
+
return resolveAccountEntry(cfg.channels?.whatsapp?.accounts, accountId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveMergedNamedWhatsAppAccountConfig(params: {
|
|
39
|
+
cfg: AutoBotConfig;
|
|
40
|
+
accountId: string;
|
|
41
|
+
}): WhatsAppAccountConfig {
|
|
42
|
+
const rootCfg = params.cfg.channels?.whatsapp;
|
|
43
|
+
const accountConfig = resolveWhatsAppAccountConfigForTest(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: AutoBotConfig;
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createAccountListHelpers } from "autobot/plugin-sdk/account-core";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
listConfiguredAccountIds,
|
|
5
|
+
listAccountIds,
|
|
6
|
+
resolveDefaultAccountId: resolveDefaultWhatsAppAccountId,
|
|
7
|
+
} = createAccountListHelpers("whatsapp", {
|
|
8
|
+
implicitDefaultAccount: {
|
|
9
|
+
channelKeys: ["authDir"],
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
listConfiguredAccountIds,
|
|
15
|
+
listAccountIds as listWhatsAppAccountIds,
|
|
16
|
+
resolveDefaultWhatsAppAccountId,
|
|
17
|
+
};
|