@openclaw/zalouser 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/accounts-C00IMUgd.js +63 -0
- package/dist/accounts.runtime-uG7S8cXT.js +2 -0
- package/dist/api-BRwdUWuS.js +139 -0
- package/dist/api.js +7 -0
- package/dist/channel-ou_w_2j-.js +484 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-C9WxiAiR.js +25 -0
- package/dist/channel.setup-CiDeBFrn.js +10 -0
- package/dist/contract-api.js +3 -0
- package/dist/doctor-contract-DgqHp8E2.js +128 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/index.js +27 -0
- package/dist/monitor-Cg7K_s_s.js +705 -0
- package/dist/runtime-QNU7vLgI.js +106 -0
- package/dist/runtime-api.js +22 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-audit-BZLhil-V.js +34 -0
- package/dist/send-BsmySxe3.js +534 -0
- package/dist/session-route-C0-Xr8bt.js +92 -0
- package/dist/setup-core-CqipqY98.js +40 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-NCOuKu-l.js +359 -0
- package/dist/shared-DSy8aIUx.js +120 -0
- package/dist/test-api.js +5 -0
- package/dist/zalo-js-CHCUlY3c.js +1279 -0
- package/package.json +15 -6
- package/api.ts +0 -9
- package/channel-plugin-api.ts +0 -3
- package/contract-api.ts +0 -2
- package/doctor-contract-api.ts +0 -1
- package/index.ts +0 -34
- package/runtime-api.ts +0 -67
- package/secret-contract-api.ts +0 -4
- package/setup-entry.ts +0 -9
- package/setup-plugin-api.ts +0 -2
- package/src/accounts.runtime.ts +0 -1
- package/src/accounts.test-mocks.ts +0 -14
- package/src/accounts.test.ts +0 -266
- package/src/accounts.ts +0 -131
- package/src/channel-api.ts +0 -20
- package/src/channel.adapters.ts +0 -391
- package/src/channel.directory.test.ts +0 -59
- package/src/channel.runtime.ts +0 -12
- package/src/channel.sendpayload.test.ts +0 -172
- package/src/channel.setup.test.ts +0 -33
- package/src/channel.setup.ts +0 -12
- package/src/channel.test.ts +0 -377
- package/src/channel.ts +0 -219
- package/src/config-schema.ts +0 -33
- package/src/directory.ts +0 -54
- package/src/doctor-contract.ts +0 -156
- package/src/doctor.test.ts +0 -77
- package/src/doctor.ts +0 -37
- package/src/group-policy.test.ts +0 -61
- package/src/group-policy.ts +0 -83
- package/src/message-sid.test.ts +0 -66
- package/src/message-sid.ts +0 -80
- package/src/monitor.account-scope.test.ts +0 -107
- package/src/monitor.group-gating.test.ts +0 -816
- package/src/monitor.send-mocks.ts +0 -20
- package/src/monitor.ts +0 -1044
- package/src/probe.test.ts +0 -60
- package/src/probe.ts +0 -35
- package/src/qr-temp-file.ts +0 -22
- package/src/reaction.test.ts +0 -19
- package/src/reaction.ts +0 -32
- package/src/runtime.ts +0 -9
- package/src/security-audit.test.ts +0 -80
- package/src/security-audit.ts +0 -71
- package/src/send.test.ts +0 -395
- package/src/send.ts +0 -272
- package/src/session-route.ts +0 -121
- package/src/setup-core.ts +0 -33
- package/src/setup-surface.test.ts +0 -363
- package/src/setup-surface.ts +0 -470
- package/src/setup-test-helpers.ts +0 -42
- package/src/shared.ts +0 -92
- package/src/status-issues.test.ts +0 -31
- package/src/status-issues.ts +0 -58
- package/src/test-helpers.ts +0 -26
- package/src/text-styles.test.ts +0 -203
- package/src/text-styles.ts +0 -540
- package/src/tool.test.ts +0 -212
- package/src/tool.ts +0 -210
- package/src/types.ts +0 -125
- package/src/zalo-js.credentials.test.ts +0 -465
- package/src/zalo-js.test-mocks.ts +0 -89
- package/src/zalo-js.ts +0 -1911
- package/src/zca-client.test.ts +0 -24
- package/src/zca-client.ts +0 -259
- package/src/zca-constants.ts +0 -55
- package/src/zca-js-exports.d.ts +0 -22
- package/test-api.ts +0 -21
- package/tsconfig.json +0 -16
package/src/channel.adapters.ts
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
import { createScopedDmSecurityResolver } from "openclaw/plugin-sdk/channel-config-helpers";
|
|
2
|
-
import { createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";
|
|
3
|
-
import {
|
|
4
|
-
createEmptyChannelResult,
|
|
5
|
-
createRawChannelSendResultAdapter,
|
|
6
|
-
} from "openclaw/plugin-sdk/channel-send-result";
|
|
7
|
-
import { createStaticReplyToModeResolver } from "openclaw/plugin-sdk/conversation-runtime";
|
|
8
|
-
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
9
|
-
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
|
10
|
-
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
|
11
|
-
import {
|
|
12
|
-
checkZcaAuthenticated,
|
|
13
|
-
listZalouserAccountIds,
|
|
14
|
-
resolveDefaultZalouserAccountId,
|
|
15
|
-
resolveZalouserAccountSync,
|
|
16
|
-
type ResolvedZalouserAccount,
|
|
17
|
-
} from "./accounts.js";
|
|
18
|
-
import type {
|
|
19
|
-
ChannelGroupContext,
|
|
20
|
-
ChannelMessageActionAdapter,
|
|
21
|
-
GroupToolPolicyConfig,
|
|
22
|
-
OpenClawConfig,
|
|
23
|
-
} from "./channel-api.js";
|
|
24
|
-
import {
|
|
25
|
-
DEFAULT_ACCOUNT_ID,
|
|
26
|
-
chunkTextForOutbound,
|
|
27
|
-
isDangerousNameMatchingEnabled,
|
|
28
|
-
isNumericTargetId,
|
|
29
|
-
normalizeAccountId,
|
|
30
|
-
sendPayloadWithChunkedTextAndMedia,
|
|
31
|
-
} from "./channel-api.js";
|
|
32
|
-
import { buildZalouserGroupCandidates, findZalouserGroupEntry } from "./group-policy.js";
|
|
33
|
-
import { resolveZalouserReactionMessageIds } from "./message-sid.js";
|
|
34
|
-
import { writeQrDataUrlToTempFile } from "./qr-temp-file.js";
|
|
35
|
-
import { getZalouserRuntime } from "./runtime.js";
|
|
36
|
-
import {
|
|
37
|
-
normalizeZalouserTarget,
|
|
38
|
-
parseZalouserOutboundTarget,
|
|
39
|
-
resolveZalouserOutboundSessionRoute,
|
|
40
|
-
} from "./session-route.js";
|
|
41
|
-
|
|
42
|
-
const loadZalouserChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
|
|
43
|
-
|
|
44
|
-
const ZALOUSER_TEXT_CHUNK_LIMIT = 2000;
|
|
45
|
-
|
|
46
|
-
export function resolveZalouserQrProfile(accountId?: string | null): string {
|
|
47
|
-
const normalized = normalizeAccountId(accountId);
|
|
48
|
-
if (!normalized || normalized === DEFAULT_ACCOUNT_ID) {
|
|
49
|
-
return process.env.ZALOUSER_PROFILE?.trim() || process.env.ZCA_PROFILE?.trim() || "default";
|
|
50
|
-
}
|
|
51
|
-
return normalized;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function resolveZalouserOutboundChunkMode(cfg: OpenClawConfig, accountId?: string) {
|
|
55
|
-
return getZalouserRuntime().channel.text.resolveChunkMode(cfg, "zalouser", accountId);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function resolveZalouserOutboundTextChunkLimit(cfg: OpenClawConfig, accountId?: string) {
|
|
59
|
-
return getZalouserRuntime().channel.text.resolveTextChunkLimit(cfg, "zalouser", accountId, {
|
|
60
|
-
fallbackLimit: ZALOUSER_TEXT_CHUNK_LIMIT,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function resolveZalouserGroupPolicyEntry(params: ChannelGroupContext) {
|
|
65
|
-
const account = resolveZalouserAccountSync({
|
|
66
|
-
cfg: params.cfg,
|
|
67
|
-
accountId: params.accountId ?? undefined,
|
|
68
|
-
});
|
|
69
|
-
const groups = account.config.groups ?? {};
|
|
70
|
-
return findZalouserGroupEntry(
|
|
71
|
-
groups,
|
|
72
|
-
buildZalouserGroupCandidates({
|
|
73
|
-
groupId: params.groupId,
|
|
74
|
-
groupChannel: params.groupChannel,
|
|
75
|
-
includeWildcard: true,
|
|
76
|
-
allowNameMatching: isDangerousNameMatchingEnabled(account.config),
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function resolveZalouserGroupToolPolicy(
|
|
82
|
-
params: ChannelGroupContext,
|
|
83
|
-
): GroupToolPolicyConfig | undefined {
|
|
84
|
-
return resolveZalouserGroupPolicyEntry(params)?.tools;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function resolveZalouserRequireMention(params: ChannelGroupContext): boolean {
|
|
88
|
-
const entry = resolveZalouserGroupPolicyEntry(params);
|
|
89
|
-
if (typeof entry?.requireMention === "boolean") {
|
|
90
|
-
return entry.requireMention;
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const zalouserRawSendResultAdapter = createRawChannelSendResultAdapter({
|
|
96
|
-
channel: "zalouser",
|
|
97
|
-
sendText: async ({ to, text, accountId, cfg }) => {
|
|
98
|
-
const { sendMessageZalouser } = await loadZalouserChannelRuntime();
|
|
99
|
-
const account = resolveZalouserAccountSync({ cfg: cfg, accountId });
|
|
100
|
-
const target = parseZalouserOutboundTarget(to);
|
|
101
|
-
return await sendMessageZalouser(target.threadId, text, {
|
|
102
|
-
profile: account.profile,
|
|
103
|
-
isGroup: target.isGroup,
|
|
104
|
-
textMode: "markdown",
|
|
105
|
-
textChunkMode: resolveZalouserOutboundChunkMode(cfg, account.accountId),
|
|
106
|
-
textChunkLimit: resolveZalouserOutboundTextChunkLimit(cfg, account.accountId),
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
sendMedia: async ({ to, text, mediaUrl, accountId, cfg, mediaLocalRoots, mediaReadFile }) => {
|
|
110
|
-
const { sendMessageZalouser } = await loadZalouserChannelRuntime();
|
|
111
|
-
const account = resolveZalouserAccountSync({ cfg: cfg, accountId });
|
|
112
|
-
const target = parseZalouserOutboundTarget(to);
|
|
113
|
-
return await sendMessageZalouser(target.threadId, text, {
|
|
114
|
-
profile: account.profile,
|
|
115
|
-
isGroup: target.isGroup,
|
|
116
|
-
mediaUrl,
|
|
117
|
-
mediaLocalRoots,
|
|
118
|
-
mediaReadFile,
|
|
119
|
-
textMode: "markdown",
|
|
120
|
-
textChunkMode: resolveZalouserOutboundChunkMode(cfg, account.accountId),
|
|
121
|
-
textChunkLimit: resolveZalouserOutboundTextChunkLimit(cfg, account.accountId),
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const resolveZalouserDmPolicy = createScopedDmSecurityResolver<ResolvedZalouserAccount>({
|
|
127
|
-
channelKey: "zalouser",
|
|
128
|
-
resolvePolicy: (account) => account.config.dmPolicy,
|
|
129
|
-
resolveAllowFrom: (account) => account.config.allowFrom,
|
|
130
|
-
policyPathSuffix: "dmPolicy",
|
|
131
|
-
normalizeEntry: (raw) => raw.trim().replace(/^(zalouser|zlu):/i, ""),
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
export const zalouserGroupsAdapter = {
|
|
135
|
-
resolveRequireMention: resolveZalouserRequireMention,
|
|
136
|
-
resolveToolPolicy: resolveZalouserGroupToolPolicy,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const zalouserMessageActions: ChannelMessageActionAdapter = {
|
|
140
|
-
describeMessageTool: ({ cfg, accountId }) => {
|
|
141
|
-
const accounts = accountId
|
|
142
|
-
? [resolveZalouserAccountSync({ cfg, accountId })].filter((account) => account.enabled)
|
|
143
|
-
: listZalouserAccountIds(cfg)
|
|
144
|
-
.map((resolvedAccountId) =>
|
|
145
|
-
resolveZalouserAccountSync({ cfg, accountId: resolvedAccountId }),
|
|
146
|
-
)
|
|
147
|
-
.filter((account) => account.enabled);
|
|
148
|
-
if (accounts.length === 0) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
return { actions: ["react"] };
|
|
152
|
-
},
|
|
153
|
-
supportsAction: ({ action }) => action === "react",
|
|
154
|
-
handleAction: async ({ action, params, cfg, accountId, toolContext }) => {
|
|
155
|
-
if (action !== "react") {
|
|
156
|
-
throw new Error(`Zalouser action ${action} not supported`);
|
|
157
|
-
}
|
|
158
|
-
const { sendReactionZalouser } = await loadZalouserChannelRuntime();
|
|
159
|
-
const account = resolveZalouserAccountSync({ cfg, accountId });
|
|
160
|
-
const threadId =
|
|
161
|
-
(typeof params.threadId === "string" ? params.threadId.trim() : "") ||
|
|
162
|
-
(typeof params.to === "string" ? params.to.trim() : "") ||
|
|
163
|
-
(typeof params.chatId === "string" ? params.chatId.trim() : "") ||
|
|
164
|
-
(toolContext?.currentChannelId?.trim() ?? "");
|
|
165
|
-
if (!threadId) {
|
|
166
|
-
throw new Error("Zalouser react requires threadId (or to/chatId).");
|
|
167
|
-
}
|
|
168
|
-
const emoji = typeof params.emoji === "string" ? params.emoji.trim() : "";
|
|
169
|
-
if (!emoji) {
|
|
170
|
-
throw new Error("Zalouser react requires emoji.");
|
|
171
|
-
}
|
|
172
|
-
const ids = resolveZalouserReactionMessageIds({
|
|
173
|
-
messageId: typeof params.messageId === "string" ? params.messageId : undefined,
|
|
174
|
-
cliMsgId: typeof params.cliMsgId === "string" ? params.cliMsgId : undefined,
|
|
175
|
-
currentMessageId: toolContext?.currentMessageId,
|
|
176
|
-
});
|
|
177
|
-
if (!ids) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
"Zalouser react requires messageId + cliMsgId (or a current message context id).",
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
const result = await sendReactionZalouser({
|
|
183
|
-
profile: account.profile,
|
|
184
|
-
threadId,
|
|
185
|
-
isGroup: params.isGroup === true,
|
|
186
|
-
msgId: ids.msgId,
|
|
187
|
-
cliMsgId: ids.cliMsgId,
|
|
188
|
-
emoji,
|
|
189
|
-
remove: params.remove === true,
|
|
190
|
-
});
|
|
191
|
-
if (!result.ok) {
|
|
192
|
-
throw new Error(result.error || "Failed to react on Zalo message");
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
content: [
|
|
196
|
-
{
|
|
197
|
-
type: "text" as const,
|
|
198
|
-
text:
|
|
199
|
-
params.remove === true
|
|
200
|
-
? `Removed reaction ${emoji} from ${ids.msgId}`
|
|
201
|
-
: `Reacted ${emoji} on ${ids.msgId}`,
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
details: {
|
|
205
|
-
messageId: ids.msgId,
|
|
206
|
-
cliMsgId: ids.cliMsgId,
|
|
207
|
-
threadId,
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export const zalouserResolverAdapter = {
|
|
214
|
-
resolveTargets: async ({
|
|
215
|
-
cfg,
|
|
216
|
-
accountId,
|
|
217
|
-
inputs,
|
|
218
|
-
kind,
|
|
219
|
-
runtime,
|
|
220
|
-
}: {
|
|
221
|
-
cfg: OpenClawConfig;
|
|
222
|
-
accountId?: string | null;
|
|
223
|
-
inputs: string[];
|
|
224
|
-
kind: "user" | "group";
|
|
225
|
-
runtime: RuntimeEnv;
|
|
226
|
-
}) => {
|
|
227
|
-
const results = [];
|
|
228
|
-
for (const input of inputs) {
|
|
229
|
-
const trimmed = input.trim();
|
|
230
|
-
if (!trimmed) {
|
|
231
|
-
results.push({ input, resolved: false, note: "empty input" });
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
if (/^\d+$/.test(trimmed)) {
|
|
235
|
-
results.push({ input, resolved: true, id: trimmed });
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
try {
|
|
239
|
-
const runtimeModule = await loadZalouserChannelRuntime();
|
|
240
|
-
const account = resolveZalouserAccountSync({
|
|
241
|
-
cfg: cfg,
|
|
242
|
-
accountId: accountId ?? resolveDefaultZalouserAccountId(cfg),
|
|
243
|
-
});
|
|
244
|
-
if (kind === "user") {
|
|
245
|
-
const friends = await runtimeModule.listZaloFriendsMatching(account.profile, trimmed);
|
|
246
|
-
const best = friends[0];
|
|
247
|
-
results.push({
|
|
248
|
-
input,
|
|
249
|
-
resolved: Boolean(best?.userId),
|
|
250
|
-
id: best?.userId,
|
|
251
|
-
name: best?.displayName,
|
|
252
|
-
note: friends.length > 1 ? "multiple matches; chose first" : undefined,
|
|
253
|
-
});
|
|
254
|
-
} else {
|
|
255
|
-
const groups = await runtimeModule.listZaloGroupsMatching(account.profile, trimmed);
|
|
256
|
-
const best =
|
|
257
|
-
groups.find(
|
|
258
|
-
(group) =>
|
|
259
|
-
normalizeLowercaseStringOrEmpty(group.name) ===
|
|
260
|
-
normalizeLowercaseStringOrEmpty(trimmed),
|
|
261
|
-
) ?? groups[0];
|
|
262
|
-
results.push({
|
|
263
|
-
input,
|
|
264
|
-
resolved: Boolean(best?.groupId),
|
|
265
|
-
id: best?.groupId,
|
|
266
|
-
name: best?.name,
|
|
267
|
-
note: groups.length > 1 ? "multiple matches; chose first" : undefined,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
} catch (err) {
|
|
271
|
-
runtime.error?.(`zalouser resolve failed: ${String(err)}`);
|
|
272
|
-
results.push({ input, resolved: false, note: "lookup failed" });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return results;
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
export const zalouserAuthAdapter = {
|
|
280
|
-
login: async ({
|
|
281
|
-
cfg,
|
|
282
|
-
accountId,
|
|
283
|
-
runtime,
|
|
284
|
-
}: {
|
|
285
|
-
cfg: OpenClawConfig;
|
|
286
|
-
accountId?: string | null;
|
|
287
|
-
runtime: RuntimeEnv;
|
|
288
|
-
}) => {
|
|
289
|
-
const { startZaloQrLogin, waitForZaloQrLogin } = await loadZalouserChannelRuntime();
|
|
290
|
-
const account = resolveZalouserAccountSync({
|
|
291
|
-
cfg: cfg,
|
|
292
|
-
accountId: accountId ?? resolveDefaultZalouserAccountId(cfg),
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
runtime.log(
|
|
296
|
-
`Generating QR login for Zalo Personal (account: ${account.accountId}, profile: ${account.profile})...`,
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
const started = await startZaloQrLogin({
|
|
300
|
-
profile: account.profile,
|
|
301
|
-
timeoutMs: 35_000,
|
|
302
|
-
});
|
|
303
|
-
if (!started.qrDataUrl) {
|
|
304
|
-
throw new Error(started.message || "Failed to start QR login");
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const qrPath = await writeQrDataUrlToTempFile(started.qrDataUrl, account.profile);
|
|
308
|
-
if (qrPath) {
|
|
309
|
-
runtime.log(`Scan QR image: ${qrPath}`);
|
|
310
|
-
} else {
|
|
311
|
-
runtime.log("QR generated but could not be written to a temp file.");
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const waited = await waitForZaloQrLogin({ profile: account.profile, timeoutMs: 180_000 });
|
|
315
|
-
if (!waited.connected) {
|
|
316
|
-
throw new Error(waited.message || "Zalouser login failed");
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
runtime.log(waited.message);
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
export const zalouserSecurityAdapter = {
|
|
324
|
-
resolveDmPolicy: resolveZalouserDmPolicy,
|
|
325
|
-
collectAuditFindings: async (params: {
|
|
326
|
-
accountId?: string | null;
|
|
327
|
-
account: ResolvedZalouserAccount;
|
|
328
|
-
orderedAccountIds: string[];
|
|
329
|
-
hasExplicitAccountPath: boolean;
|
|
330
|
-
}) => (await loadZalouserChannelRuntime()).collectZalouserSecurityAuditFindings(params),
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
export const zalouserThreadingAdapter = {
|
|
334
|
-
resolveReplyToMode: createStaticReplyToModeResolver("off"),
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
export const zalouserPairingTextAdapter = {
|
|
338
|
-
idLabel: "zalouserUserId",
|
|
339
|
-
message: "Your pairing request has been approved.",
|
|
340
|
-
normalizeAllowEntry: createPairingPrefixStripper(/^(zalouser|zlu):/i),
|
|
341
|
-
notify: async ({ cfg, id, message }: { cfg: OpenClawConfig; id: string; message: string }) => {
|
|
342
|
-
const { sendMessageZalouser } = await loadZalouserChannelRuntime();
|
|
343
|
-
const account = resolveZalouserAccountSync({ cfg: cfg });
|
|
344
|
-
const authenticated = await checkZcaAuthenticated(account.profile);
|
|
345
|
-
if (!authenticated) {
|
|
346
|
-
throw new Error("Zalouser not authenticated");
|
|
347
|
-
}
|
|
348
|
-
await sendMessageZalouser(id, message, {
|
|
349
|
-
profile: account.profile,
|
|
350
|
-
});
|
|
351
|
-
},
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
export const zalouserOutboundAdapter = {
|
|
355
|
-
deliveryMode: "direct" as const,
|
|
356
|
-
chunker: chunkTextForOutbound,
|
|
357
|
-
chunkerMode: "markdown" as const,
|
|
358
|
-
sendPayload: async (
|
|
359
|
-
ctx: { payload: object } & Parameters<
|
|
360
|
-
NonNullable<typeof zalouserRawSendResultAdapter.sendText>
|
|
361
|
-
>[0],
|
|
362
|
-
) =>
|
|
363
|
-
await sendPayloadWithChunkedTextAndMedia({
|
|
364
|
-
ctx,
|
|
365
|
-
sendText: (nextCtx) => zalouserRawSendResultAdapter.sendText!(nextCtx),
|
|
366
|
-
sendMedia: (nextCtx) => zalouserRawSendResultAdapter.sendMedia!(nextCtx),
|
|
367
|
-
emptyResult: createEmptyChannelResult("zalouser"),
|
|
368
|
-
}),
|
|
369
|
-
...zalouserRawSendResultAdapter,
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
export const zalouserMessagingAdapter = {
|
|
373
|
-
targetPrefixes: ["zalouser", "zlu"],
|
|
374
|
-
normalizeTarget: (raw: string) => normalizeZalouserTarget(raw),
|
|
375
|
-
resolveOutboundSessionRoute: (
|
|
376
|
-
params: Parameters<typeof resolveZalouserOutboundSessionRoute>[0],
|
|
377
|
-
) => resolveZalouserOutboundSessionRoute(params),
|
|
378
|
-
targetResolver: {
|
|
379
|
-
looksLikeId: (raw: string) => {
|
|
380
|
-
const normalized = normalizeZalouserTarget(raw);
|
|
381
|
-
if (!normalized) {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
if (/^group:[^\s]+$/i.test(normalized) || /^user:[^\s]+$/i.test(normalized)) {
|
|
385
|
-
return true;
|
|
386
|
-
}
|
|
387
|
-
return isNumericTargetId(normalized);
|
|
388
|
-
},
|
|
389
|
-
hint: "<user:id|group:id>",
|
|
390
|
-
},
|
|
391
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import "./accounts.test-mocks.js";
|
|
3
|
-
import { listZalouserDirectoryGroupMembers } from "./directory.js";
|
|
4
|
-
import "./zalo-js.test-mocks.js";
|
|
5
|
-
import { listZaloGroupMembersMock } from "./zalo-js.test-mocks.js";
|
|
6
|
-
|
|
7
|
-
describe("zalouser directory group members", () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
listZaloGroupMembersMock.mockClear();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("accepts prefixed group ids from directory groups list output", async () => {
|
|
13
|
-
await listZalouserDirectoryGroupMembers(
|
|
14
|
-
{
|
|
15
|
-
cfg: {},
|
|
16
|
-
accountId: "default",
|
|
17
|
-
groupId: "group:1471383327500481391",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
listZaloGroupMembers: async (profile, groupId) =>
|
|
21
|
-
await listZaloGroupMembersMock(profile, groupId),
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
expect(listZaloGroupMembersMock).toHaveBeenLastCalledWith("default", "1471383327500481391");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("keeps backward compatibility for raw group ids", async () => {
|
|
29
|
-
await listZalouserDirectoryGroupMembers(
|
|
30
|
-
{
|
|
31
|
-
cfg: {},
|
|
32
|
-
accountId: "default",
|
|
33
|
-
groupId: "1471383327500481391",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
listZaloGroupMembers: async (profile, groupId) =>
|
|
37
|
-
await listZaloGroupMembersMock(profile, groupId),
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
expect(listZaloGroupMembersMock).toHaveBeenLastCalledWith("default", "1471383327500481391");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("accepts provider-native g- group ids without stripping the prefix", async () => {
|
|
45
|
-
await listZalouserDirectoryGroupMembers(
|
|
46
|
-
{
|
|
47
|
-
cfg: {},
|
|
48
|
-
accountId: "default",
|
|
49
|
-
groupId: "g-1471383327500481391",
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
listZaloGroupMembers: async (profile, groupId) =>
|
|
53
|
-
await listZaloGroupMembersMock(profile, groupId),
|
|
54
|
-
},
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(listZaloGroupMembersMock).toHaveBeenLastCalledWith("default", "g-1471383327500481391");
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/channel.runtime.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { probeZalouser } from "./probe.js";
|
|
2
|
-
export { collectZalouserSecurityAuditFindings } from "./security-audit.js";
|
|
3
|
-
export { sendMessageZalouser, sendReactionZalouser } from "./send.js";
|
|
4
|
-
export {
|
|
5
|
-
listZaloFriendsMatching,
|
|
6
|
-
listZaloGroupMembers,
|
|
7
|
-
listZaloGroupsMatching,
|
|
8
|
-
logoutZaloProfile,
|
|
9
|
-
startZaloQrLogin,
|
|
10
|
-
waitForZaloQrLogin,
|
|
11
|
-
getZaloUserInfo,
|
|
12
|
-
} from "./zalo-js.js";
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
installChannelOutboundPayloadContractSuite,
|
|
3
|
-
primeChannelOutboundSendMock,
|
|
4
|
-
type OutboundPayloadHarnessParams,
|
|
5
|
-
} from "openclaw/plugin-sdk/channel-contract-testing";
|
|
6
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
-
import "./accounts.test-mocks.js";
|
|
8
|
-
import "./zalo-js.test-mocks.js";
|
|
9
|
-
import type { ReplyPayload } from "../runtime-api.js";
|
|
10
|
-
import { zalouserPlugin } from "./channel.js";
|
|
11
|
-
import { setZalouserRuntime } from "./runtime.js";
|
|
12
|
-
import * as sendModule from "./send.js";
|
|
13
|
-
|
|
14
|
-
vi.mock("./send.js", () => ({
|
|
15
|
-
sendMessageZalouser: vi.fn().mockResolvedValue({ ok: true, messageId: "zlu-1" }),
|
|
16
|
-
sendReactionZalouser: vi.fn().mockResolvedValue({ ok: true }),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
function baseCtx(payload: ReplyPayload) {
|
|
20
|
-
return {
|
|
21
|
-
cfg: {},
|
|
22
|
-
to: "user:987654321",
|
|
23
|
-
text: "",
|
|
24
|
-
payload,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("zalouserPlugin outbound sendPayload", () => {
|
|
29
|
-
let mockedSend: ReturnType<typeof vi.mocked<(typeof import("./send.js"))["sendMessageZalouser"]>>;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
setZalouserRuntime({
|
|
33
|
-
channel: {
|
|
34
|
-
text: {
|
|
35
|
-
resolveChunkMode: vi.fn(() => "length"),
|
|
36
|
-
resolveTextChunkLimit: vi.fn(() => 1200),
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
} as never);
|
|
40
|
-
mockedSend = vi.mocked(sendModule.sendMessageZalouser);
|
|
41
|
-
primeChannelOutboundSendMock(mockedSend, { ok: true, messageId: "zlu-1" });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("group target delegates with isGroup=true and stripped threadId", async () => {
|
|
45
|
-
mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-g1" });
|
|
46
|
-
|
|
47
|
-
const result = await zalouserPlugin.outbound!.sendPayload!({
|
|
48
|
-
...baseCtx({ text: "hello group" }),
|
|
49
|
-
to: "group:1471383327500481391",
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(mockedSend).toHaveBeenCalledWith(
|
|
53
|
-
"1471383327500481391",
|
|
54
|
-
"hello group",
|
|
55
|
-
expect.objectContaining({ isGroup: true, textMode: "markdown" }),
|
|
56
|
-
);
|
|
57
|
-
expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-g1" });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("treats bare numeric targets as direct chats for backward compatibility", async () => {
|
|
61
|
-
mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-d1" });
|
|
62
|
-
|
|
63
|
-
const result = await zalouserPlugin.outbound!.sendPayload!({
|
|
64
|
-
...baseCtx({ text: "hello" }),
|
|
65
|
-
to: "987654321",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(mockedSend).toHaveBeenCalledWith(
|
|
69
|
-
"987654321",
|
|
70
|
-
"hello",
|
|
71
|
-
expect.objectContaining({ isGroup: false, textMode: "markdown" }),
|
|
72
|
-
);
|
|
73
|
-
expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-d1" });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("preserves provider-native group ids when sending to raw g- targets", async () => {
|
|
77
|
-
mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-g-native" });
|
|
78
|
-
|
|
79
|
-
const result = await zalouserPlugin.outbound!.sendPayload!({
|
|
80
|
-
...baseCtx({ text: "hello native group" }),
|
|
81
|
-
to: "g-1471383327500481391",
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(mockedSend).toHaveBeenCalledWith(
|
|
85
|
-
"g-1471383327500481391",
|
|
86
|
-
"hello native group",
|
|
87
|
-
expect.objectContaining({ isGroup: true, textMode: "markdown" }),
|
|
88
|
-
);
|
|
89
|
-
expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-g-native" });
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("passes long markdown through once so formatting happens before chunking", async () => {
|
|
93
|
-
const text = `**${"a".repeat(2501)}**`;
|
|
94
|
-
mockedSend.mockResolvedValue({ ok: true, messageId: "zlu-code" });
|
|
95
|
-
|
|
96
|
-
const result = await zalouserPlugin.outbound!.sendPayload!({
|
|
97
|
-
...baseCtx({ text }),
|
|
98
|
-
to: "987654321",
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(mockedSend).toHaveBeenCalledTimes(1);
|
|
102
|
-
expect(mockedSend).toHaveBeenCalledWith(
|
|
103
|
-
"987654321",
|
|
104
|
-
text,
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
isGroup: false,
|
|
107
|
-
textMode: "markdown",
|
|
108
|
-
textChunkMode: "length",
|
|
109
|
-
textChunkLimit: 1200,
|
|
110
|
-
}),
|
|
111
|
-
);
|
|
112
|
-
expect(result).toMatchObject({ channel: "zalouser", messageId: "zlu-code" });
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("zalouserPlugin outbound payload contract", () => {
|
|
117
|
-
function createZalouserHarness(params: OutboundPayloadHarnessParams) {
|
|
118
|
-
const mockedSend = vi.mocked(sendModule.sendMessageZalouser);
|
|
119
|
-
setZalouserRuntime({
|
|
120
|
-
channel: {
|
|
121
|
-
text: {
|
|
122
|
-
resolveChunkMode: vi.fn(() => "length"),
|
|
123
|
-
resolveTextChunkLimit: vi.fn(() => 1200),
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
} as never);
|
|
127
|
-
primeChannelOutboundSendMock(mockedSend, { ok: true, messageId: "zlu-1" }, params.sendResults);
|
|
128
|
-
const ctx = {
|
|
129
|
-
cfg: {},
|
|
130
|
-
to: "user:987654321",
|
|
131
|
-
text: "",
|
|
132
|
-
payload: params.payload,
|
|
133
|
-
};
|
|
134
|
-
return {
|
|
135
|
-
run: async () => await zalouserPlugin.outbound!.sendPayload!(ctx),
|
|
136
|
-
sendMock: mockedSend,
|
|
137
|
-
to: "987654321",
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
installChannelOutboundPayloadContractSuite({
|
|
142
|
-
channel: "zalouser",
|
|
143
|
-
chunking: { mode: "passthrough", longTextLength: 3000 },
|
|
144
|
-
createHarness: createZalouserHarness,
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("zalouserPlugin messaging target normalization", () => {
|
|
149
|
-
it("normalizes user/group aliases to canonical targets", () => {
|
|
150
|
-
const normalize = zalouserPlugin.messaging?.normalizeTarget;
|
|
151
|
-
if (!normalize) {
|
|
152
|
-
throw new Error("normalizeTarget unavailable");
|
|
153
|
-
}
|
|
154
|
-
expect(normalize("zlu:g:30003")).toBe("group:30003");
|
|
155
|
-
expect(normalize("zalouser:u:20002")).toBe("user:20002");
|
|
156
|
-
expect(normalize("zlu:g-30003")).toBe("group:g-30003");
|
|
157
|
-
expect(normalize("zalouser:u-20002")).toBe("user:u-20002");
|
|
158
|
-
expect(normalize("20002")).toBe("20002");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("treats canonical and provider-native user/group targets as ids", () => {
|
|
162
|
-
const looksLikeId = zalouserPlugin.messaging?.targetResolver?.looksLikeId;
|
|
163
|
-
if (!looksLikeId) {
|
|
164
|
-
throw new Error("looksLikeId unavailable");
|
|
165
|
-
}
|
|
166
|
-
expect(looksLikeId("user:20002")).toBe(true);
|
|
167
|
-
expect(looksLikeId("group:30003")).toBe(true);
|
|
168
|
-
expect(looksLikeId("g-30003")).toBe(true);
|
|
169
|
-
expect(looksLikeId("u-20002")).toBe(true);
|
|
170
|
-
expect(looksLikeId("Alice Nguyen")).toBe(false);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { createPluginSetupWizardStatus } from "openclaw/plugin-sdk/plugin-test-runtime";
|
|
5
|
-
import { withEnvAsync } from "openclaw/plugin-sdk/test-env";
|
|
6
|
-
import { describe, expect, it } from "vitest";
|
|
7
|
-
import "./zalo-js.test-mocks.js";
|
|
8
|
-
import { zalouserSetupPlugin } from "./setup-test-helpers.js";
|
|
9
|
-
|
|
10
|
-
const zalouserSetupGetStatus = createPluginSetupWizardStatus(zalouserSetupPlugin);
|
|
11
|
-
|
|
12
|
-
describe("zalouser setup plugin", () => {
|
|
13
|
-
it("builds setup status without an initialized runtime", async () => {
|
|
14
|
-
const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-setup-"));
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
|
|
18
|
-
await expect(
|
|
19
|
-
zalouserSetupGetStatus({
|
|
20
|
-
cfg: {},
|
|
21
|
-
accountOverrides: {},
|
|
22
|
-
}),
|
|
23
|
-
).resolves.toMatchObject({
|
|
24
|
-
channel: "zalouser",
|
|
25
|
-
configured: false,
|
|
26
|
-
statusLines: ["Zalo Personal: needs QR login"],
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
} finally {
|
|
30
|
-
await rm(stateDir, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
package/src/channel.setup.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ResolvedZalouserAccount } from "./accounts.js";
|
|
2
|
-
import type { ChannelPlugin } from "./channel-api.js";
|
|
3
|
-
import { zalouserSetupAdapter } from "./setup-core.js";
|
|
4
|
-
import { zalouserSetupWizard } from "./setup-surface.js";
|
|
5
|
-
import { createZalouserPluginBase } from "./shared.js";
|
|
6
|
-
|
|
7
|
-
export const zalouserSetupPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
|
|
8
|
-
...createZalouserPluginBase({
|
|
9
|
-
setupWizard: zalouserSetupWizard,
|
|
10
|
-
setup: zalouserSetupAdapter,
|
|
11
|
-
}),
|
|
12
|
-
};
|