@lofa199419/waha-v2 2.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/README.md +50 -0
- package/bin/wa +20 -0
- package/bin/wa-adv +9 -0
- package/bin/waha-advanced-entrypoint +12 -0
- package/bin/waha-cli +11 -0
- package/bin/waha_cli.py +549 -0
- package/index.ts +109 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +59 -0
- package/scripts/install-openclaw-extension.mjs +106 -0
- package/skills/waha-v2/SKILL.md +143 -0
- package/skills/waha-v2-onboarding/SKILL.md +146 -0
- package/src/accounts.ts +133 -0
- package/src/channel.ts +823 -0
- package/src/client.ts +585 -0
- package/src/config-schema.ts +342 -0
- package/src/deliver.ts +70 -0
- package/src/gateway.ts +170 -0
- package/src/login.ts +64 -0
- package/src/outbound.ts +84 -0
- package/src/probe.ts +30 -0
- package/src/routes.ts +260 -0
- package/src/runtime.ts +56 -0
- package/src/types.ts +195 -0
- package/src/webhook.ts +841 -0
package/src/accounts.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
+
import {
|
|
3
|
+
WAHA_V2_CHANNEL_ID,
|
|
4
|
+
WAHA_V2_DEFAULT_ACCOUNT_ID,
|
|
5
|
+
type ResolvedWahaV2Account,
|
|
6
|
+
type WahaV2AccountConfig,
|
|
7
|
+
type WahaV2RootConfig,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Config extraction
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
export function readWahaV2Root(cfg: OpenClawConfig): WahaV2RootConfig {
|
|
15
|
+
const channels = (cfg as Record<string, unknown>).channels;
|
|
16
|
+
if (!channels || typeof channels !== "object" || Array.isArray(channels)) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const root = (channels as Record<string, unknown>)[WAHA_V2_CHANNEL_ID];
|
|
20
|
+
if (!root || typeof root !== "object" || Array.isArray(root)) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return root as WahaV2RootConfig;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Account list
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
export function listWahaV2AccountIds(cfg: OpenClawConfig): string[] {
|
|
31
|
+
const root = readWahaV2Root(cfg);
|
|
32
|
+
const ids = Object.keys(root.accounts ?? {}).filter(Boolean);
|
|
33
|
+
// If no named accounts are configured, expose a single implicit "default" account.
|
|
34
|
+
return ids.length > 0 ? ids.toSorted((a, b) => a.localeCompare(b)) : [WAHA_V2_DEFAULT_ACCOUNT_ID];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Account resolution — account-level fields override root-level
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
export function resolveWahaV2Account(
|
|
42
|
+
cfg: OpenClawConfig,
|
|
43
|
+
accountId?: string | null,
|
|
44
|
+
): ResolvedWahaV2Account {
|
|
45
|
+
const resolvedId = accountId?.trim() || WAHA_V2_DEFAULT_ACCOUNT_ID;
|
|
46
|
+
const root = readWahaV2Root(cfg);
|
|
47
|
+
// Merge: root provides defaults; per-account config overrides.
|
|
48
|
+
const account: WahaV2AccountConfig =
|
|
49
|
+
resolvedId === WAHA_V2_DEFAULT_ACCOUNT_ID
|
|
50
|
+
? root
|
|
51
|
+
: { ...root, ...(root.accounts?.[resolvedId] ?? {}) };
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
accountId: resolvedId,
|
|
55
|
+
name: account.name?.trim() || undefined,
|
|
56
|
+
baseUrl: account.baseUrl?.trim() || "http://localhost:3000",
|
|
57
|
+
apiKey: account.apiKey?.trim() || "",
|
|
58
|
+
session: account.session?.trim() || "default",
|
|
59
|
+
webhookUrl: account.webhookUrl?.trim() || undefined,
|
|
60
|
+
enabled: account.enabled !== false,
|
|
61
|
+
dmPolicy: account.dmPolicy,
|
|
62
|
+
groupPolicy: account.groupPolicy,
|
|
63
|
+
debounceMs: account.debounceMs,
|
|
64
|
+
allowFrom: account.allowFrom,
|
|
65
|
+
allowGroups: account.allowGroups,
|
|
66
|
+
pauseOnOwnerMessage: account.pauseOnOwnerMessage === true,
|
|
67
|
+
ownerPauseWords: account.ownerPauseWords?.map((entry) => String(entry).trim()).filter(Boolean),
|
|
68
|
+
ownerResumeWords: account.ownerResumeWords
|
|
69
|
+
?.map((entry) => String(entry).trim())
|
|
70
|
+
.filter(Boolean),
|
|
71
|
+
typing: account.typing,
|
|
72
|
+
labelRouting: account.labelRouting,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Find the account whose session name matches the given WAHA session string. */
|
|
77
|
+
export function resolveWahaV2AccountBySession(
|
|
78
|
+
cfg: OpenClawConfig,
|
|
79
|
+
session: string,
|
|
80
|
+
): ResolvedWahaV2Account | undefined {
|
|
81
|
+
for (const accountId of listWahaV2AccountIds(cfg)) {
|
|
82
|
+
const account = resolveWahaV2Account(cfg, accountId);
|
|
83
|
+
if (account.session === session.trim()) {
|
|
84
|
+
return account;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Config mutation helpers (used by ChannelConfigAdapter)
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
export function setWahaV2ChannelConfig(
|
|
95
|
+
cfg: OpenClawConfig,
|
|
96
|
+
patch: Partial<WahaV2RootConfig>,
|
|
97
|
+
): OpenClawConfig {
|
|
98
|
+
const base = cfg as Record<string, unknown>;
|
|
99
|
+
const channels = { ...((base.channels as Record<string, unknown>) ?? {}) };
|
|
100
|
+
const current = (channels[WAHA_V2_CHANNEL_ID] ?? {}) as Record<string, unknown>;
|
|
101
|
+
channels[WAHA_V2_CHANNEL_ID] = { ...current, ...patch };
|
|
102
|
+
return { ...base, channels } as OpenClawConfig;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function setWahaV2AccountEnabled(
|
|
106
|
+
cfg: OpenClawConfig,
|
|
107
|
+
accountId: string,
|
|
108
|
+
enabled: boolean,
|
|
109
|
+
): OpenClawConfig {
|
|
110
|
+
const root = readWahaV2Root(cfg);
|
|
111
|
+
if (accountId === WAHA_V2_DEFAULT_ACCOUNT_ID && !root.accounts?.[accountId]) {
|
|
112
|
+
// Single-account mode — set enabled on root.
|
|
113
|
+
return setWahaV2ChannelConfig(cfg, { ...root, enabled });
|
|
114
|
+
}
|
|
115
|
+
const accounts = {
|
|
116
|
+
...(root.accounts ?? {}),
|
|
117
|
+
[accountId]: { ...(root.accounts?.[accountId] ?? {}), enabled },
|
|
118
|
+
};
|
|
119
|
+
return setWahaV2ChannelConfig(cfg, { ...root, accounts });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function deleteWahaV2Account(cfg: OpenClawConfig, accountId: string): OpenClawConfig {
|
|
123
|
+
const root = readWahaV2Root(cfg);
|
|
124
|
+
if (!root.accounts?.[accountId]) {
|
|
125
|
+
return cfg;
|
|
126
|
+
}
|
|
127
|
+
const accounts = { ...root.accounts };
|
|
128
|
+
delete accounts[accountId];
|
|
129
|
+
return setWahaV2ChannelConfig(cfg, {
|
|
130
|
+
...root,
|
|
131
|
+
accounts: Object.keys(accounts).length > 0 ? accounts : undefined,
|
|
132
|
+
});
|
|
133
|
+
}
|