@openclaw/zalo 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-9NLDDlZ8.js +118 -0
- package/dist/actions.runtime-kJ65ZxW7.js +5 -0
- package/dist/api.js +5 -0
- package/dist/channel-VPbtV3Oq.js +343 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BnTAWQx5.js +106 -0
- package/dist/contract-api.js +3 -0
- package/dist/group-access-DZR43lOR.js +30 -0
- package/dist/index.js +22 -0
- package/dist/monitor-DMysJBWa.js +823 -0
- package/dist/monitor.webhook-DqnuvgjV.js +175 -0
- package/dist/proxy-CY8VuC6H.js +135 -0
- package/dist/runtime-BRFxnYQx.js +8 -0
- package/dist/runtime-api-MOTmRW4F.js +19 -0
- package/dist/runtime-api.js +3 -0
- package/dist/secret-contract-Dw93tGo2.js +87 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/send-Gv3l5EGI.js +101 -0
- package/dist/setup-api.js +30 -0
- package/dist/setup-core-DigRD3j1.js +166 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-surface-2Up3yWov.js +216 -0
- package/dist/test-api.js +2 -0
- package/package.json +15 -6
- package/api.ts +0 -9
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -5
- package/index.test.ts +0 -15
- package/index.ts +0 -20
- package/runtime-api.test.ts +0 -17
- package/runtime-api.ts +0 -75
- package/secret-contract-api.ts +0 -5
- package/setup-api.ts +0 -34
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -70
- package/src/accounts.ts +0 -60
- package/src/actions.runtime.ts +0 -5
- package/src/actions.test.ts +0 -32
- package/src/actions.ts +0 -62
- package/src/api.test.ts +0 -149
- package/src/api.ts +0 -265
- package/src/approval-auth.test.ts +0 -17
- package/src/approval-auth.ts +0 -25
- package/src/channel.directory.test.ts +0 -59
- package/src/channel.runtime.ts +0 -93
- package/src/channel.startup.test.ts +0 -101
- package/src/channel.ts +0 -275
- package/src/config-schema.test.ts +0 -30
- package/src/config-schema.ts +0 -29
- package/src/group-access.ts +0 -49
- package/src/monitor.group-policy.test.ts +0 -94
- package/src/monitor.image.polling.test.ts +0 -110
- package/src/monitor.lifecycle.test.ts +0 -198
- package/src/monitor.pairing.lifecycle.test.ts +0 -141
- package/src/monitor.polling.media-reply.test.ts +0 -425
- package/src/monitor.reply-once.lifecycle.test.ts +0 -171
- package/src/monitor.ts +0 -1028
- package/src/monitor.types.ts +0 -4
- package/src/monitor.webhook.test.ts +0 -806
- package/src/monitor.webhook.ts +0 -278
- package/src/outbound-media.test.ts +0 -182
- package/src/outbound-media.ts +0 -241
- package/src/outbound-payload.contract.test.ts +0 -45
- package/src/probe.ts +0 -45
- package/src/proxy.ts +0 -24
- package/src/runtime-api.ts +0 -75
- package/src/runtime-support.ts +0 -91
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -109
- package/src/secret-input.ts +0 -5
- package/src/send.test.ts +0 -120
- package/src/send.ts +0 -153
- package/src/session-route.ts +0 -32
- package/src/setup-allow-from.ts +0 -94
- package/src/setup-core.ts +0 -149
- package/src/setup-status.test.ts +0 -33
- package/src/setup-surface.test.ts +0 -175
- package/src/setup-surface.ts +0 -291
- package/src/status-issues.test.ts +0 -17
- package/src/status-issues.ts +0 -37
- package/src/test-support/lifecycle-test-support.ts +0 -413
- package/src/test-support/monitor-mocks-test-support.ts +0 -209
- package/src/token.test.ts +0 -92
- package/src/token.ts +0 -79
- package/src/types.ts +0 -50
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createDirectoryTestRuntime,
|
|
3
|
-
expectDirectorySurface,
|
|
4
|
-
} from "openclaw/plugin-sdk/channel-test-helpers";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import type { OpenClawConfig, RuntimeEnv } from "../runtime-api.js";
|
|
7
|
-
import { zaloPlugin } from "./channel.js";
|
|
8
|
-
|
|
9
|
-
describe("zalo directory", () => {
|
|
10
|
-
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
|
11
|
-
const directory = expectDirectorySurface(zaloPlugin.directory);
|
|
12
|
-
|
|
13
|
-
async function expectPeersFromAllowFrom(allowFrom: string[]) {
|
|
14
|
-
const cfg = {
|
|
15
|
-
channels: {
|
|
16
|
-
zalo: {
|
|
17
|
-
allowFrom,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
} as unknown as OpenClawConfig;
|
|
21
|
-
|
|
22
|
-
await expect(
|
|
23
|
-
directory.listPeers({
|
|
24
|
-
cfg,
|
|
25
|
-
accountId: undefined,
|
|
26
|
-
query: undefined,
|
|
27
|
-
limit: undefined,
|
|
28
|
-
runtime: runtimeEnv,
|
|
29
|
-
}),
|
|
30
|
-
).resolves.toEqual(
|
|
31
|
-
expect.arrayContaining([
|
|
32
|
-
{ kind: "user", id: "123" },
|
|
33
|
-
{ kind: "user", id: "234" },
|
|
34
|
-
{ kind: "user", id: "345" },
|
|
35
|
-
]),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
await expect(
|
|
39
|
-
directory.listGroups({
|
|
40
|
-
cfg,
|
|
41
|
-
accountId: undefined,
|
|
42
|
-
query: undefined,
|
|
43
|
-
limit: undefined,
|
|
44
|
-
runtime: runtimeEnv,
|
|
45
|
-
}),
|
|
46
|
-
).resolves.toEqual([]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
it("lists peers from allowFrom", async () => {
|
|
50
|
-
await expectPeersFromAllowFrom(["zalo:123", "zl:234", "345"]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("normalizes spaced zalo prefixes in allowFrom and pairing entries", async () => {
|
|
54
|
-
await expectPeersFromAllowFrom([" zalo:123 ", " zl:234 ", " 345 "]);
|
|
55
|
-
|
|
56
|
-
expect(zaloPlugin.pairing?.normalizeAllowEntry?.(" zalo:123 ")).toBe("123");
|
|
57
|
-
expect(zaloPlugin.messaging?.normalizeTarget?.(" zl:234 ")).toBe("234");
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/channel.runtime.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { createAccountStatusSink } from "openclaw/plugin-sdk/channel-lifecycle";
|
|
2
|
-
import { probeZalo } from "./probe.js";
|
|
3
|
-
import { resolveZaloProxyFetch } from "./proxy.js";
|
|
4
|
-
import {
|
|
5
|
-
PAIRING_APPROVED_MESSAGE,
|
|
6
|
-
type ChannelPlugin,
|
|
7
|
-
type OpenClawConfig,
|
|
8
|
-
} from "./runtime-api.js";
|
|
9
|
-
import { normalizeSecretInputString } from "./secret-input.js";
|
|
10
|
-
import { sendMessageZalo } from "./send.js";
|
|
11
|
-
import type { ResolvedZaloAccount } from "./types.js";
|
|
12
|
-
|
|
13
|
-
export async function notifyZaloPairingApproval(params: { cfg: OpenClawConfig; id: string }) {
|
|
14
|
-
const { resolveZaloAccount } = await import("./accounts.js");
|
|
15
|
-
const account = resolveZaloAccount({ cfg: params.cfg });
|
|
16
|
-
if (!account.token) {
|
|
17
|
-
throw new Error("Zalo token not configured");
|
|
18
|
-
}
|
|
19
|
-
await sendMessageZalo(params.id, PAIRING_APPROVED_MESSAGE, {
|
|
20
|
-
token: account.token,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function sendZaloText(
|
|
25
|
-
params: Parameters<typeof sendMessageZalo>[2] & {
|
|
26
|
-
to: string;
|
|
27
|
-
text: string;
|
|
28
|
-
},
|
|
29
|
-
) {
|
|
30
|
-
return await sendMessageZalo(params.to, params.text, params);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function probeZaloAccount(params: {
|
|
34
|
-
account: import("./accounts.js").ResolvedZaloAccount;
|
|
35
|
-
timeoutMs?: number;
|
|
36
|
-
}) {
|
|
37
|
-
return await probeZalo(
|
|
38
|
-
params.account.token,
|
|
39
|
-
params.timeoutMs,
|
|
40
|
-
resolveZaloProxyFetch(params.account.config.proxy),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function startZaloGatewayAccount(
|
|
45
|
-
ctx: Parameters<
|
|
46
|
-
NonNullable<NonNullable<ChannelPlugin<ResolvedZaloAccount>["gateway"]>["startAccount"]>
|
|
47
|
-
>[0],
|
|
48
|
-
) {
|
|
49
|
-
const account = ctx.account;
|
|
50
|
-
const token = account.token.trim();
|
|
51
|
-
const mode = account.config.webhookUrl ? "webhook" : "polling";
|
|
52
|
-
let zaloBotLabel = "";
|
|
53
|
-
const fetcher = resolveZaloProxyFetch(account.config.proxy);
|
|
54
|
-
try {
|
|
55
|
-
const probe = await probeZalo(token, 2500, fetcher);
|
|
56
|
-
const name = probe.ok ? probe.bot?.name?.trim() : null;
|
|
57
|
-
if (name) {
|
|
58
|
-
zaloBotLabel = ` (${name})`;
|
|
59
|
-
}
|
|
60
|
-
if (!probe.ok) {
|
|
61
|
-
ctx.log?.warn?.(
|
|
62
|
-
`[${account.accountId}] Zalo probe failed before provider start (${String(probe.elapsedMs)}ms): ${probe.error}`,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
ctx.setStatus({
|
|
66
|
-
accountId: account.accountId,
|
|
67
|
-
bot: probe.bot,
|
|
68
|
-
});
|
|
69
|
-
} catch (err) {
|
|
70
|
-
ctx.log?.warn?.(
|
|
71
|
-
`[${account.accountId}] Zalo probe threw before provider start: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
const statusSink = createAccountStatusSink({
|
|
75
|
-
accountId: ctx.accountId,
|
|
76
|
-
setStatus: ctx.setStatus,
|
|
77
|
-
});
|
|
78
|
-
ctx.log?.info(`[${account.accountId}] starting provider${zaloBotLabel} mode=${mode}`);
|
|
79
|
-
const { monitorZaloProvider } = await import("./monitor.js");
|
|
80
|
-
return monitorZaloProvider({
|
|
81
|
-
token,
|
|
82
|
-
account,
|
|
83
|
-
config: ctx.cfg,
|
|
84
|
-
runtime: ctx.runtime,
|
|
85
|
-
abortSignal: ctx.abortSignal,
|
|
86
|
-
useWebhook: Boolean(account.config.webhookUrl),
|
|
87
|
-
webhookUrl: account.config.webhookUrl,
|
|
88
|
-
webhookSecret: normalizeSecretInputString(account.config.webhookSecret),
|
|
89
|
-
webhookPath: account.config.webhookPath,
|
|
90
|
-
fetcher,
|
|
91
|
-
statusSink,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expectLifecyclePatch,
|
|
3
|
-
expectPendingUntilAbort,
|
|
4
|
-
startAccountAndTrackLifecycle,
|
|
5
|
-
waitForStartedMocks,
|
|
6
|
-
} from "openclaw/plugin-sdk/channel-test-helpers";
|
|
7
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
8
|
-
import type { ResolvedZaloAccount } from "./accounts.js";
|
|
9
|
-
|
|
10
|
-
const hoisted = vi.hoisted(() => ({
|
|
11
|
-
monitorZaloProvider: vi.fn(),
|
|
12
|
-
probeZalo: vi.fn(async () => ({
|
|
13
|
-
ok: false as const,
|
|
14
|
-
error: "probe failed",
|
|
15
|
-
elapsedMs: 1,
|
|
16
|
-
})),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
vi.mock("./monitor.js", () => {
|
|
20
|
-
return {
|
|
21
|
-
monitorZaloProvider: hoisted.monitorZaloProvider,
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
vi.mock("./probe.js", () => {
|
|
26
|
-
return {
|
|
27
|
-
probeZalo: hoisted.probeZalo,
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
vi.mock("./channel.runtime.js", () => ({
|
|
32
|
-
probeZaloAccount: hoisted.probeZalo,
|
|
33
|
-
startZaloGatewayAccount: async (ctx: {
|
|
34
|
-
account: ResolvedZaloAccount;
|
|
35
|
-
abortSignal: AbortSignal;
|
|
36
|
-
setStatus: (patch: Partial<ResolvedZaloAccount>) => void;
|
|
37
|
-
}) => {
|
|
38
|
-
await hoisted.probeZalo();
|
|
39
|
-
ctx.setStatus({ accountId: ctx.account.accountId });
|
|
40
|
-
return await hoisted.monitorZaloProvider({
|
|
41
|
-
token: ctx.account.token,
|
|
42
|
-
account: ctx.account,
|
|
43
|
-
abortSignal: ctx.abortSignal,
|
|
44
|
-
useWebhook: false,
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
import { zaloPlugin } from "./channel.js";
|
|
50
|
-
|
|
51
|
-
function buildAccount(): ResolvedZaloAccount {
|
|
52
|
-
return {
|
|
53
|
-
accountId: "default",
|
|
54
|
-
enabled: true,
|
|
55
|
-
token: "test-token",
|
|
56
|
-
tokenSource: "config",
|
|
57
|
-
config: {},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
describe("zaloPlugin gateway.startAccount", () => {
|
|
62
|
-
afterEach(() => {
|
|
63
|
-
vi.clearAllMocks();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("keeps startAccount pending until abort", async () => {
|
|
67
|
-
hoisted.monitorZaloProvider.mockImplementationOnce(
|
|
68
|
-
async ({ abortSignal }: { abortSignal: AbortSignal }) =>
|
|
69
|
-
await new Promise<void>((resolve) => {
|
|
70
|
-
if (abortSignal.aborted) {
|
|
71
|
-
resolve();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
abortSignal.addEventListener("abort", () => resolve(), { once: true });
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const { abort, patches, task, isSettled } = startAccountAndTrackLifecycle({
|
|
79
|
-
startAccount: zaloPlugin.gateway!.startAccount!,
|
|
80
|
-
account: buildAccount(),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await expectPendingUntilAbort({
|
|
84
|
-
waitForStarted: waitForStartedMocks(hoisted.probeZalo, hoisted.monitorZaloProvider),
|
|
85
|
-
isSettled,
|
|
86
|
-
abort,
|
|
87
|
-
task,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
expectLifecyclePatch(patches, { accountId: "default" });
|
|
91
|
-
expect(isSettled()).toBe(true);
|
|
92
|
-
expect(hoisted.monitorZaloProvider).toHaveBeenCalledWith(
|
|
93
|
-
expect.objectContaining({
|
|
94
|
-
token: "test-token",
|
|
95
|
-
account: expect.objectContaining({ accountId: "default" }),
|
|
96
|
-
abortSignal: abort.signal,
|
|
97
|
-
useWebhook: false,
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
});
|
package/src/channel.ts
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { describeWebhookAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
|
|
2
|
-
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
3
|
-
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
|
|
4
|
-
import {
|
|
5
|
-
adaptScopedAccountAccessor,
|
|
6
|
-
createScopedChannelConfigAdapter,
|
|
7
|
-
createScopedDmSecurityResolver,
|
|
8
|
-
mapAllowFromEntries,
|
|
9
|
-
} from "openclaw/plugin-sdk/channel-config-helpers";
|
|
10
|
-
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
|
|
11
|
-
import {
|
|
12
|
-
buildChannelConfigSchema,
|
|
13
|
-
createChatChannelPlugin,
|
|
14
|
-
type ChannelPlugin,
|
|
15
|
-
} from "openclaw/plugin-sdk/channel-core";
|
|
16
|
-
import {
|
|
17
|
-
buildOpenGroupPolicyRestrictSendersWarning,
|
|
18
|
-
buildOpenGroupPolicyWarning,
|
|
19
|
-
createOpenProviderGroupPolicyWarningCollector,
|
|
20
|
-
} from "openclaw/plugin-sdk/channel-policy";
|
|
21
|
-
import {
|
|
22
|
-
createEmptyChannelResult,
|
|
23
|
-
createRawChannelSendResultAdapter,
|
|
24
|
-
} from "openclaw/plugin-sdk/channel-send-result";
|
|
25
|
-
import { buildTokenChannelStatusSummary } from "openclaw/plugin-sdk/channel-status";
|
|
26
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
27
|
-
import { createStaticReplyToModeResolver } from "openclaw/plugin-sdk/conversation-runtime";
|
|
28
|
-
import { createChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
|
|
29
|
-
import { listResolvedDirectoryUserEntriesFromAllowFrom } from "openclaw/plugin-sdk/directory-runtime";
|
|
30
|
-
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
31
|
-
import {
|
|
32
|
-
isNumericTargetId,
|
|
33
|
-
sendPayloadWithChunkedTextAndMedia,
|
|
34
|
-
} from "openclaw/plugin-sdk/reply-payload";
|
|
35
|
-
import {
|
|
36
|
-
createComputedAccountStatusAdapter,
|
|
37
|
-
createDefaultChannelRuntimeState,
|
|
38
|
-
} from "openclaw/plugin-sdk/status-helpers";
|
|
39
|
-
import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
|
|
40
|
-
import {
|
|
41
|
-
listZaloAccountIds,
|
|
42
|
-
resolveDefaultZaloAccountId,
|
|
43
|
-
resolveZaloAccount,
|
|
44
|
-
type ResolvedZaloAccount,
|
|
45
|
-
} from "./accounts.js";
|
|
46
|
-
import { zaloMessageActions } from "./actions.js";
|
|
47
|
-
import { zaloApprovalAuth } from "./approval-auth.js";
|
|
48
|
-
import { ZaloConfigSchema } from "./config-schema.js";
|
|
49
|
-
import type { ZaloProbeResult } from "./probe.js";
|
|
50
|
-
import { collectRuntimeConfigAssignments, secretTargetRegistryEntries } from "./secret-contract.js";
|
|
51
|
-
import { resolveZaloOutboundSessionRoute } from "./session-route.js";
|
|
52
|
-
import { createZaloSetupWizardProxy, zaloSetupAdapter } from "./setup-core.js";
|
|
53
|
-
import { collectZaloStatusIssues } from "./status-issues.js";
|
|
54
|
-
|
|
55
|
-
const meta = {
|
|
56
|
-
id: "zalo",
|
|
57
|
-
label: "Zalo",
|
|
58
|
-
selectionLabel: "Zalo (Bot API)",
|
|
59
|
-
docsPath: "/channels/zalo",
|
|
60
|
-
docsLabel: "zalo",
|
|
61
|
-
blurb: "Vietnam-focused messaging platform with Bot API.",
|
|
62
|
-
aliases: ["zl"],
|
|
63
|
-
order: 80,
|
|
64
|
-
quickstartAllowFrom: true,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
function normalizeZaloMessagingTarget(raw: string): string | undefined {
|
|
68
|
-
const trimmed = raw?.trim();
|
|
69
|
-
if (!trimmed) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
return trimmed.replace(/^(zalo|zl):/i, "").trim();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const loadZaloChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
|
|
76
|
-
const zaloSetupWizard = createZaloSetupWizardProxy(
|
|
77
|
-
async () => (await import("./setup-surface.js")).zaloSetupWizard,
|
|
78
|
-
);
|
|
79
|
-
const zaloTextChunkLimit = 2000;
|
|
80
|
-
|
|
81
|
-
const zaloRawSendResultAdapter = createRawChannelSendResultAdapter({
|
|
82
|
-
channel: "zalo",
|
|
83
|
-
sendText: async ({ to, text, accountId, cfg }) =>
|
|
84
|
-
await (
|
|
85
|
-
await loadZaloChannelRuntime()
|
|
86
|
-
).sendZaloText({
|
|
87
|
-
to,
|
|
88
|
-
text,
|
|
89
|
-
accountId: accountId ?? undefined,
|
|
90
|
-
cfg,
|
|
91
|
-
}),
|
|
92
|
-
sendMedia: async ({ to, text, mediaUrl, accountId, cfg }) =>
|
|
93
|
-
await (
|
|
94
|
-
await loadZaloChannelRuntime()
|
|
95
|
-
).sendZaloText({
|
|
96
|
-
to,
|
|
97
|
-
text,
|
|
98
|
-
accountId: accountId ?? undefined,
|
|
99
|
-
mediaUrl,
|
|
100
|
-
cfg,
|
|
101
|
-
}),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const zaloConfigAdapter = createScopedChannelConfigAdapter<ResolvedZaloAccount>({
|
|
105
|
-
sectionKey: "zalo",
|
|
106
|
-
listAccountIds: listZaloAccountIds,
|
|
107
|
-
resolveAccount: adaptScopedAccountAccessor(resolveZaloAccount),
|
|
108
|
-
defaultAccountId: resolveDefaultZaloAccountId,
|
|
109
|
-
clearBaseFields: ["botToken", "tokenFile", "name"],
|
|
110
|
-
resolveAllowFrom: (account: ResolvedZaloAccount) => account.config.allowFrom,
|
|
111
|
-
formatAllowFrom: (allowFrom) =>
|
|
112
|
-
formatAllowFromLowercase({ allowFrom, stripPrefixRe: /^(zalo|zl):/i }),
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const resolveZaloDmPolicy = createScopedDmSecurityResolver<ResolvedZaloAccount>({
|
|
116
|
-
channelKey: "zalo",
|
|
117
|
-
resolvePolicy: (account) => account.config.dmPolicy,
|
|
118
|
-
resolveAllowFrom: (account) => account.config.allowFrom,
|
|
119
|
-
policyPathSuffix: "dmPolicy",
|
|
120
|
-
normalizeEntry: (raw) => raw.trim().replace(/^(zalo|zl):/i, ""),
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const collectZaloSecurityWarnings = createOpenProviderGroupPolicyWarningCollector<{
|
|
124
|
-
cfg: OpenClawConfig;
|
|
125
|
-
account: ResolvedZaloAccount;
|
|
126
|
-
}>({
|
|
127
|
-
providerConfigPresent: (cfg) => cfg.channels?.zalo !== undefined,
|
|
128
|
-
resolveGroupPolicy: ({ account }) => account.config.groupPolicy,
|
|
129
|
-
collect: ({ account, groupPolicy }) => {
|
|
130
|
-
if (groupPolicy !== "open") {
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
const explicitGroupAllowFrom = mapAllowFromEntries(account.config.groupAllowFrom);
|
|
134
|
-
const dmAllowFrom = mapAllowFromEntries(account.config.allowFrom);
|
|
135
|
-
const effectiveAllowFrom =
|
|
136
|
-
explicitGroupAllowFrom.length > 0 ? explicitGroupAllowFrom : dmAllowFrom;
|
|
137
|
-
if (effectiveAllowFrom.length > 0) {
|
|
138
|
-
return [
|
|
139
|
-
buildOpenGroupPolicyRestrictSendersWarning({
|
|
140
|
-
surface: "Zalo groups",
|
|
141
|
-
openScope: "any member",
|
|
142
|
-
groupPolicyPath: "channels.zalo.groupPolicy",
|
|
143
|
-
groupAllowFromPath: "channels.zalo.groupAllowFrom",
|
|
144
|
-
}),
|
|
145
|
-
];
|
|
146
|
-
}
|
|
147
|
-
return [
|
|
148
|
-
buildOpenGroupPolicyWarning({
|
|
149
|
-
surface: "Zalo groups",
|
|
150
|
-
openBehavior:
|
|
151
|
-
"with no groupAllowFrom/allowFrom allowlist; any member can trigger (mention-gated)",
|
|
152
|
-
remediation: 'Set channels.zalo.groupPolicy="allowlist" + channels.zalo.groupAllowFrom',
|
|
153
|
-
}),
|
|
154
|
-
];
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount, ZaloProbeResult> =
|
|
159
|
-
createChatChannelPlugin({
|
|
160
|
-
base: {
|
|
161
|
-
id: "zalo",
|
|
162
|
-
meta,
|
|
163
|
-
setup: zaloSetupAdapter,
|
|
164
|
-
setupWizard: zaloSetupWizard,
|
|
165
|
-
capabilities: {
|
|
166
|
-
chatTypes: ["direct", "group"],
|
|
167
|
-
media: true,
|
|
168
|
-
reactions: false,
|
|
169
|
-
threads: false,
|
|
170
|
-
polls: false,
|
|
171
|
-
nativeCommands: false,
|
|
172
|
-
blockStreaming: true,
|
|
173
|
-
},
|
|
174
|
-
reload: { configPrefixes: ["channels.zalo"] },
|
|
175
|
-
configSchema: buildChannelConfigSchema(ZaloConfigSchema),
|
|
176
|
-
config: {
|
|
177
|
-
...zaloConfigAdapter,
|
|
178
|
-
isConfigured: (account) => Boolean(account.token?.trim()),
|
|
179
|
-
describeAccount: (account): ChannelAccountSnapshot =>
|
|
180
|
-
describeWebhookAccountSnapshot({
|
|
181
|
-
account,
|
|
182
|
-
configured: Boolean(account.token?.trim()),
|
|
183
|
-
mode: account.config.webhookUrl ? "webhook" : "polling",
|
|
184
|
-
extra: {
|
|
185
|
-
tokenSource: account.tokenSource,
|
|
186
|
-
},
|
|
187
|
-
}),
|
|
188
|
-
},
|
|
189
|
-
approvalCapability: zaloApprovalAuth,
|
|
190
|
-
secrets: {
|
|
191
|
-
secretTargetRegistryEntries,
|
|
192
|
-
collectRuntimeConfigAssignments,
|
|
193
|
-
},
|
|
194
|
-
groups: {
|
|
195
|
-
resolveRequireMention: () => true,
|
|
196
|
-
},
|
|
197
|
-
actions: zaloMessageActions,
|
|
198
|
-
messaging: {
|
|
199
|
-
targetPrefixes: ["zalo", "zl"],
|
|
200
|
-
normalizeTarget: normalizeZaloMessagingTarget,
|
|
201
|
-
resolveOutboundSessionRoute: (params) => resolveZaloOutboundSessionRoute(params),
|
|
202
|
-
targetResolver: {
|
|
203
|
-
looksLikeId: isNumericTargetId,
|
|
204
|
-
hint: "<chatId>",
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
directory: createChannelDirectoryAdapter({
|
|
208
|
-
listPeers: async (params) =>
|
|
209
|
-
listResolvedDirectoryUserEntriesFromAllowFrom<ResolvedZaloAccount>({
|
|
210
|
-
...params,
|
|
211
|
-
resolveAccount: adaptScopedAccountAccessor(resolveZaloAccount),
|
|
212
|
-
resolveAllowFrom: (account) => account.config.allowFrom,
|
|
213
|
-
normalizeId: (entry) => entry.trim().replace(/^(zalo|zl):/i, ""),
|
|
214
|
-
}),
|
|
215
|
-
listGroups: async () => [],
|
|
216
|
-
}),
|
|
217
|
-
status: createComputedAccountStatusAdapter<ResolvedZaloAccount, ZaloProbeResult>({
|
|
218
|
-
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
|
|
219
|
-
collectStatusIssues: collectZaloStatusIssues,
|
|
220
|
-
buildChannelSummary: ({ snapshot }) => buildTokenChannelStatusSummary(snapshot),
|
|
221
|
-
probeAccount: async ({ account, timeoutMs }) =>
|
|
222
|
-
await (await loadZaloChannelRuntime()).probeZaloAccount({ account, timeoutMs }),
|
|
223
|
-
resolveAccountSnapshot: ({ account }) => {
|
|
224
|
-
const configured = Boolean(account.token?.trim());
|
|
225
|
-
return {
|
|
226
|
-
accountId: account.accountId,
|
|
227
|
-
name: account.name,
|
|
228
|
-
enabled: account.enabled,
|
|
229
|
-
configured,
|
|
230
|
-
extra: {
|
|
231
|
-
tokenSource: account.tokenSource,
|
|
232
|
-
mode: account.config.webhookUrl ? "webhook" : "polling",
|
|
233
|
-
dmPolicy: account.config.dmPolicy ?? "pairing",
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
},
|
|
237
|
-
}),
|
|
238
|
-
gateway: {
|
|
239
|
-
startAccount: async (ctx) =>
|
|
240
|
-
await (await loadZaloChannelRuntime()).startZaloGatewayAccount(ctx),
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
security: {
|
|
244
|
-
resolveDmPolicy: resolveZaloDmPolicy,
|
|
245
|
-
collectWarnings: collectZaloSecurityWarnings,
|
|
246
|
-
},
|
|
247
|
-
pairing: {
|
|
248
|
-
text: {
|
|
249
|
-
idLabel: "zaloUserId",
|
|
250
|
-
message: "Your pairing request has been approved.",
|
|
251
|
-
normalizeAllowEntry: (entry) => entry.trim().replace(/^(zalo|zl):/i, ""),
|
|
252
|
-
notify: async (params) =>
|
|
253
|
-
await (await loadZaloChannelRuntime()).notifyZaloPairingApproval(params),
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
threading: {
|
|
257
|
-
resolveReplyToMode: createStaticReplyToModeResolver("off"),
|
|
258
|
-
},
|
|
259
|
-
outbound: {
|
|
260
|
-
deliveryMode: "direct",
|
|
261
|
-
chunker: chunkTextForOutbound,
|
|
262
|
-
chunkerMode: "text",
|
|
263
|
-
textChunkLimit: zaloTextChunkLimit,
|
|
264
|
-
sendPayload: async (ctx) =>
|
|
265
|
-
await sendPayloadWithChunkedTextAndMedia({
|
|
266
|
-
ctx,
|
|
267
|
-
textChunkLimit: zaloTextChunkLimit,
|
|
268
|
-
chunker: chunkTextForOutbound,
|
|
269
|
-
sendText: (nextCtx) => zaloRawSendResultAdapter.sendText!(nextCtx),
|
|
270
|
-
sendMedia: (nextCtx) => zaloRawSendResultAdapter.sendMedia!(nextCtx),
|
|
271
|
-
emptyResult: createEmptyChannelResult("zalo"),
|
|
272
|
-
}),
|
|
273
|
-
...zaloRawSendResultAdapter,
|
|
274
|
-
},
|
|
275
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { ZaloConfigSchema } from "./config-schema.js";
|
|
3
|
-
|
|
4
|
-
describe("ZaloConfigSchema SecretInput", () => {
|
|
5
|
-
it("accepts SecretRef botToken and webhookSecret at top-level", () => {
|
|
6
|
-
const result = ZaloConfigSchema.safeParse({
|
|
7
|
-
botToken: { source: "env", provider: "default", id: "ZALO_BOT_TOKEN" },
|
|
8
|
-
webhookUrl: "https://example.com/zalo",
|
|
9
|
-
webhookSecret: { source: "env", provider: "default", id: "ZALO_WEBHOOK_SECRET" },
|
|
10
|
-
});
|
|
11
|
-
expect(result.success).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("accepts SecretRef botToken and webhookSecret on account", () => {
|
|
15
|
-
const result = ZaloConfigSchema.safeParse({
|
|
16
|
-
accounts: {
|
|
17
|
-
work: {
|
|
18
|
-
botToken: { source: "env", provider: "default", id: "ZALO_WORK_BOT_TOKEN" },
|
|
19
|
-
webhookUrl: "https://example.com/zalo/work",
|
|
20
|
-
webhookSecret: {
|
|
21
|
-
source: "env",
|
|
22
|
-
provider: "default",
|
|
23
|
-
id: "ZALO_WORK_WEBHOOK_SECRET",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
expect(result.success).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
});
|
package/src/config-schema.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AllowFromListSchema,
|
|
3
|
-
buildCatchallMultiAccountChannelSchema,
|
|
4
|
-
DmPolicySchema,
|
|
5
|
-
GroupPolicySchema,
|
|
6
|
-
MarkdownConfigSchema,
|
|
7
|
-
} from "openclaw/plugin-sdk/channel-config-schema";
|
|
8
|
-
import { z } from "openclaw/plugin-sdk/zod";
|
|
9
|
-
import { buildSecretInputSchema } from "./secret-input.js";
|
|
10
|
-
|
|
11
|
-
const zaloAccountSchema = z.object({
|
|
12
|
-
name: z.string().optional(),
|
|
13
|
-
enabled: z.boolean().optional(),
|
|
14
|
-
markdown: MarkdownConfigSchema,
|
|
15
|
-
botToken: buildSecretInputSchema().optional(),
|
|
16
|
-
tokenFile: z.string().optional(),
|
|
17
|
-
webhookUrl: z.string().optional(),
|
|
18
|
-
webhookSecret: buildSecretInputSchema().optional(),
|
|
19
|
-
webhookPath: z.string().optional(),
|
|
20
|
-
dmPolicy: DmPolicySchema.optional(),
|
|
21
|
-
allowFrom: AllowFromListSchema,
|
|
22
|
-
groupPolicy: GroupPolicySchema.optional(),
|
|
23
|
-
groupAllowFrom: AllowFromListSchema,
|
|
24
|
-
mediaMaxMb: z.number().optional(),
|
|
25
|
-
proxy: z.string().optional(),
|
|
26
|
-
responsePrefix: z.string().optional(),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export const ZaloConfigSchema = buildCatchallMultiAccountChannelSchema(zaloAccountSchema);
|
package/src/group-access.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { isNormalizedSenderAllowed } from "openclaw/plugin-sdk/allow-from";
|
|
2
|
-
import {
|
|
3
|
-
evaluateSenderGroupAccess,
|
|
4
|
-
resolveOpenProviderRuntimeGroupPolicy,
|
|
5
|
-
type GroupPolicy,
|
|
6
|
-
type SenderGroupAccessDecision,
|
|
7
|
-
} from "openclaw/plugin-sdk/group-access";
|
|
8
|
-
|
|
9
|
-
const ZALO_ALLOW_FROM_PREFIX_RE = /^(zalo|zl):/i;
|
|
10
|
-
|
|
11
|
-
export function isZaloSenderAllowed(senderId: string, allowFrom: string[]): boolean {
|
|
12
|
-
return isNormalizedSenderAllowed({
|
|
13
|
-
senderId,
|
|
14
|
-
allowFrom,
|
|
15
|
-
stripPrefixRe: ZALO_ALLOW_FROM_PREFIX_RE,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function resolveZaloRuntimeGroupPolicy(params: {
|
|
20
|
-
providerConfigPresent: boolean;
|
|
21
|
-
groupPolicy?: GroupPolicy;
|
|
22
|
-
defaultGroupPolicy?: GroupPolicy;
|
|
23
|
-
}): {
|
|
24
|
-
groupPolicy: GroupPolicy;
|
|
25
|
-
providerMissingFallbackApplied: boolean;
|
|
26
|
-
} {
|
|
27
|
-
return resolveOpenProviderRuntimeGroupPolicy({
|
|
28
|
-
providerConfigPresent: params.providerConfigPresent,
|
|
29
|
-
groupPolicy: params.groupPolicy,
|
|
30
|
-
defaultGroupPolicy: params.defaultGroupPolicy,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function evaluateZaloGroupAccess(params: {
|
|
35
|
-
providerConfigPresent: boolean;
|
|
36
|
-
configuredGroupPolicy?: GroupPolicy;
|
|
37
|
-
defaultGroupPolicy?: GroupPolicy;
|
|
38
|
-
groupAllowFrom: string[];
|
|
39
|
-
senderId: string;
|
|
40
|
-
}): SenderGroupAccessDecision {
|
|
41
|
-
return evaluateSenderGroupAccess({
|
|
42
|
-
providerConfigPresent: params.providerConfigPresent,
|
|
43
|
-
configuredGroupPolicy: params.configuredGroupPolicy,
|
|
44
|
-
defaultGroupPolicy: params.defaultGroupPolicy,
|
|
45
|
-
groupAllowFrom: params.groupAllowFrom,
|
|
46
|
-
senderId: params.senderId,
|
|
47
|
-
isSenderAllowed: isZaloSenderAllowed,
|
|
48
|
-
});
|
|
49
|
-
}
|