@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.
Files changed (87) hide show
  1. package/dist/accounts-9NLDDlZ8.js +118 -0
  2. package/dist/actions.runtime-kJ65ZxW7.js +5 -0
  3. package/dist/api.js +5 -0
  4. package/dist/channel-VPbtV3Oq.js +343 -0
  5. package/dist/channel-plugin-api.js +2 -0
  6. package/dist/channel.runtime-BnTAWQx5.js +106 -0
  7. package/dist/contract-api.js +3 -0
  8. package/dist/group-access-DZR43lOR.js +30 -0
  9. package/dist/index.js +22 -0
  10. package/dist/monitor-DMysJBWa.js +823 -0
  11. package/dist/monitor.webhook-DqnuvgjV.js +175 -0
  12. package/dist/proxy-CY8VuC6H.js +135 -0
  13. package/dist/runtime-BRFxnYQx.js +8 -0
  14. package/dist/runtime-api-MOTmRW4F.js +19 -0
  15. package/dist/runtime-api.js +3 -0
  16. package/dist/secret-contract-Dw93tGo2.js +87 -0
  17. package/dist/secret-contract-api.js +2 -0
  18. package/dist/send-Gv3l5EGI.js +101 -0
  19. package/dist/setup-api.js +30 -0
  20. package/dist/setup-core-DigRD3j1.js +166 -0
  21. package/dist/setup-entry.js +15 -0
  22. package/dist/setup-surface-2Up3yWov.js +216 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +15 -6
  25. package/api.ts +0 -9
  26. package/channel-plugin-api.ts +0 -1
  27. package/contract-api.ts +0 -5
  28. package/index.test.ts +0 -15
  29. package/index.ts +0 -20
  30. package/runtime-api.test.ts +0 -17
  31. package/runtime-api.ts +0 -75
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-api.ts +0 -34
  34. package/setup-entry.ts +0 -13
  35. package/src/accounts.test.ts +0 -70
  36. package/src/accounts.ts +0 -60
  37. package/src/actions.runtime.ts +0 -5
  38. package/src/actions.test.ts +0 -32
  39. package/src/actions.ts +0 -62
  40. package/src/api.test.ts +0 -149
  41. package/src/api.ts +0 -265
  42. package/src/approval-auth.test.ts +0 -17
  43. package/src/approval-auth.ts +0 -25
  44. package/src/channel.directory.test.ts +0 -59
  45. package/src/channel.runtime.ts +0 -93
  46. package/src/channel.startup.test.ts +0 -101
  47. package/src/channel.ts +0 -275
  48. package/src/config-schema.test.ts +0 -30
  49. package/src/config-schema.ts +0 -29
  50. package/src/group-access.ts +0 -49
  51. package/src/monitor.group-policy.test.ts +0 -94
  52. package/src/monitor.image.polling.test.ts +0 -110
  53. package/src/monitor.lifecycle.test.ts +0 -198
  54. package/src/monitor.pairing.lifecycle.test.ts +0 -141
  55. package/src/monitor.polling.media-reply.test.ts +0 -425
  56. package/src/monitor.reply-once.lifecycle.test.ts +0 -171
  57. package/src/monitor.ts +0 -1028
  58. package/src/monitor.types.ts +0 -4
  59. package/src/monitor.webhook.test.ts +0 -806
  60. package/src/monitor.webhook.ts +0 -278
  61. package/src/outbound-media.test.ts +0 -182
  62. package/src/outbound-media.ts +0 -241
  63. package/src/outbound-payload.contract.test.ts +0 -45
  64. package/src/probe.ts +0 -45
  65. package/src/proxy.ts +0 -24
  66. package/src/runtime-api.ts +0 -75
  67. package/src/runtime-support.ts +0 -91
  68. package/src/runtime.ts +0 -9
  69. package/src/secret-contract.ts +0 -109
  70. package/src/secret-input.ts +0 -5
  71. package/src/send.test.ts +0 -120
  72. package/src/send.ts +0 -153
  73. package/src/session-route.ts +0 -32
  74. package/src/setup-allow-from.ts +0 -94
  75. package/src/setup-core.ts +0 -149
  76. package/src/setup-status.test.ts +0 -33
  77. package/src/setup-surface.test.ts +0 -175
  78. package/src/setup-surface.ts +0 -291
  79. package/src/status-issues.test.ts +0 -17
  80. package/src/status-issues.ts +0 -37
  81. package/src/test-support/lifecycle-test-support.ts +0 -413
  82. package/src/test-support/monitor-mocks-test-support.ts +0 -209
  83. package/src/token.test.ts +0 -92
  84. package/src/token.ts +0 -79
  85. package/src/types.ts +0 -50
  86. package/test-api.ts +0 -1
  87. package/tsconfig.json +0 -16
@@ -1,70 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { resolveZaloAccount } from "./accounts.js";
3
-
4
- describe("resolveZaloAccount", () => {
5
- it("resolves account config when account key casing differs from normalized id", () => {
6
- const resolved = resolveZaloAccount({
7
- cfg: {
8
- channels: {
9
- zalo: {
10
- webhookUrl: "https://top.example.com",
11
- accounts: {
12
- Work: {
13
- name: "Work",
14
- webhookUrl: "https://work.example.com",
15
- },
16
- },
17
- },
18
- },
19
- },
20
- accountId: "work",
21
- });
22
-
23
- expect(resolved.accountId).toBe("work");
24
- expect(resolved.name).toBe("Work");
25
- expect(resolved.config.webhookUrl).toBe("https://work.example.com");
26
- });
27
-
28
- it("falls back to top-level config for named accounts without overrides", () => {
29
- const resolved = resolveZaloAccount({
30
- cfg: {
31
- channels: {
32
- zalo: {
33
- enabled: true,
34
- webhookUrl: "https://top.example.com",
35
- accounts: {
36
- work: {},
37
- },
38
- },
39
- },
40
- },
41
- accountId: "work",
42
- });
43
-
44
- expect(resolved.accountId).toBe("work");
45
- expect(resolved.enabled).toBe(true);
46
- expect(resolved.config.webhookUrl).toBe("https://top.example.com");
47
- });
48
-
49
- it("uses configured defaultAccount when accountId is omitted", () => {
50
- const resolved = resolveZaloAccount({
51
- cfg: {
52
- channels: {
53
- zalo: {
54
- defaultAccount: "work",
55
- accounts: {
56
- work: {
57
- name: "Work",
58
- botToken: "work-token",
59
- },
60
- },
61
- },
62
- },
63
- },
64
- });
65
-
66
- expect(resolved.accountId).toBe("work");
67
- expect(resolved.name).toBe("Work");
68
- expect(resolved.token).toBe("work-token");
69
- });
70
- });
package/src/accounts.ts DELETED
@@ -1,60 +0,0 @@
1
- import {
2
- createAccountListHelpers,
3
- resolveMergedAccountConfig,
4
- } from "openclaw/plugin-sdk/account-helpers";
5
- import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
6
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
7
- import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
8
- import { resolveZaloToken } from "./token.js";
9
- import type { ResolvedZaloAccount, ZaloAccountConfig, ZaloConfig } from "./types.js";
10
-
11
- export type { ResolvedZaloAccount };
12
-
13
- const { listAccountIds: listZaloAccountIds, resolveDefaultAccountId: resolveDefaultZaloAccountId } =
14
- createAccountListHelpers("zalo");
15
- export { listZaloAccountIds, resolveDefaultZaloAccountId };
16
-
17
- function mergeZaloAccountConfig(cfg: OpenClawConfig, accountId: string): ZaloAccountConfig {
18
- return resolveMergedAccountConfig<ZaloAccountConfig>({
19
- channelConfig: cfg.channels?.zalo as ZaloAccountConfig | undefined,
20
- accounts: (cfg.channels?.zalo as ZaloConfig | undefined)?.accounts as
21
- | Record<string, Partial<ZaloAccountConfig>>
22
- | undefined,
23
- accountId,
24
- omitKeys: ["defaultAccount"],
25
- });
26
- }
27
-
28
- export function resolveZaloAccount(params: {
29
- cfg: OpenClawConfig;
30
- accountId?: string | null;
31
- allowUnresolvedSecretRef?: boolean;
32
- }): ResolvedZaloAccount {
33
- const accountId = normalizeAccountId(
34
- params.accountId ?? (params.cfg.channels?.zalo as ZaloConfig | undefined)?.defaultAccount,
35
- );
36
- const baseEnabled = (params.cfg.channels?.zalo as ZaloConfig | undefined)?.enabled !== false;
37
- const merged = mergeZaloAccountConfig(params.cfg, accountId);
38
- const accountEnabled = merged.enabled !== false;
39
- const enabled = baseEnabled && accountEnabled;
40
- const tokenResolution = resolveZaloToken(
41
- params.cfg.channels?.zalo as ZaloConfig | undefined,
42
- accountId,
43
- { allowUnresolvedSecretRef: params.allowUnresolvedSecretRef },
44
- );
45
-
46
- return {
47
- accountId,
48
- name: normalizeOptionalString(merged.name),
49
- enabled,
50
- token: tokenResolution.token,
51
- tokenSource: tokenResolution.source,
52
- config: merged,
53
- };
54
- }
55
-
56
- export function listEnabledZaloAccounts(cfg: OpenClawConfig): ResolvedZaloAccount[] {
57
- return listZaloAccountIds(cfg)
58
- .map((accountId) => resolveZaloAccount({ cfg, accountId }))
59
- .filter((account) => account.enabled);
60
- }
@@ -1,5 +0,0 @@
1
- import { sendMessageZalo as sendMessageZaloImpl } from "./send.js";
2
-
3
- export const zaloActionsRuntime = {
4
- sendMessageZalo: sendMessageZaloImpl,
5
- };
@@ -1,32 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { zaloMessageActions } from "./actions.js";
3
- import type { OpenClawConfig } from "./runtime-api.js";
4
-
5
- describe("zaloMessageActions.describeMessageTool", () => {
6
- it("honors the selected Zalo account during discovery", () => {
7
- const cfg: OpenClawConfig = {
8
- channels: {
9
- zalo: {
10
- enabled: true,
11
- botToken: "root-token",
12
- accounts: {
13
- default: {
14
- enabled: false,
15
- botToken: "default-token",
16
- },
17
- work: {
18
- enabled: true,
19
- botToken: "work-token",
20
- },
21
- },
22
- },
23
- },
24
- };
25
-
26
- expect(zaloMessageActions.describeMessageTool?.({ cfg, accountId: "default" })).toBeNull();
27
- expect(zaloMessageActions.describeMessageTool?.({ cfg, accountId: "work" })).toEqual({
28
- actions: ["send"],
29
- capabilities: [],
30
- });
31
- });
32
- });
package/src/actions.ts DELETED
@@ -1,62 +0,0 @@
1
- import { jsonResult, readStringParam } from "openclaw/plugin-sdk/channel-actions";
2
- import type {
3
- ChannelMessageActionAdapter,
4
- ChannelMessageActionName,
5
- } from "openclaw/plugin-sdk/channel-contract";
6
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
7
- import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
8
- import { extractToolSend } from "openclaw/plugin-sdk/tool-send";
9
- import { listEnabledZaloAccounts, resolveZaloAccount } from "./accounts.js";
10
-
11
- const loadZaloActionsRuntime = createLazyRuntimeNamedExport(
12
- () => import("./actions.runtime.js"),
13
- "zaloActionsRuntime",
14
- );
15
-
16
- const providerId = "zalo";
17
-
18
- function listEnabledAccounts(cfg: OpenClawConfig, accountId?: string | null) {
19
- return (
20
- accountId ? [resolveZaloAccount({ cfg, accountId })] : listEnabledZaloAccounts(cfg)
21
- ).filter((account) => account.enabled && account.tokenSource !== "none");
22
- }
23
-
24
- export const zaloMessageActions: ChannelMessageActionAdapter = {
25
- describeMessageTool: ({ cfg, accountId }) => {
26
- const accounts = listEnabledAccounts(cfg, accountId);
27
- if (accounts.length === 0) {
28
- return null;
29
- }
30
- const actions = new Set<ChannelMessageActionName>(["send"]);
31
- return { actions: Array.from(actions), capabilities: [] };
32
- },
33
- extractToolSend: ({ args }) => extractToolSend(args, "sendMessage"),
34
- handleAction: async ({ action, params, cfg, accountId }) => {
35
- if (action === "send") {
36
- const to = readStringParam(params, "to", { required: true });
37
- const content = readStringParam(params, "message", {
38
- required: true,
39
- allowEmpty: true,
40
- });
41
- const mediaUrl = readStringParam(params, "media", { trim: false });
42
-
43
- const { sendMessageZalo } = await loadZaloActionsRuntime();
44
- const result = await sendMessageZalo(to ?? "", content ?? "", {
45
- accountId: accountId ?? undefined,
46
- mediaUrl: mediaUrl ?? undefined,
47
- cfg: cfg,
48
- });
49
-
50
- if (!result.ok) {
51
- return jsonResult({
52
- ok: false,
53
- error: result.error ?? "Failed to send Zalo message",
54
- });
55
- }
56
-
57
- return jsonResult({ ok: true, to, messageId: result.messageId });
58
- }
59
-
60
- throw new Error(`Action ${action} is not supported for provider ${providerId}.`);
61
- },
62
- };
package/src/api.test.ts DELETED
@@ -1,149 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const resolvePinnedHostnameWithPolicyMock = vi.fn();
4
-
5
- vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
6
- resolvePinnedHostnameWithPolicy: (...args: unknown[]) =>
7
- resolvePinnedHostnameWithPolicyMock(...args),
8
- }));
9
-
10
- import { deleteWebhook, getWebhookInfo, sendChatAction, sendPhoto, type ZaloFetch } from "./api.js";
11
-
12
- function createOkFetcher() {
13
- return vi.fn<ZaloFetch>(async () => new Response(JSON.stringify({ ok: true, result: {} })));
14
- }
15
-
16
- async function expectPostJsonRequest(run: (token: string, fetcher: ZaloFetch) => Promise<unknown>) {
17
- const fetcher = createOkFetcher();
18
- await run("test-token", fetcher);
19
- expect(fetcher).toHaveBeenCalledTimes(1);
20
- const [, init] = fetcher.mock.calls[0] ?? [];
21
- expect(init?.method).toBe("POST");
22
- expect(init?.headers).toEqual({ "Content-Type": "application/json" });
23
- }
24
-
25
- describe("Zalo API request methods", () => {
26
- beforeEach(() => {
27
- resolvePinnedHostnameWithPolicyMock.mockReset();
28
- resolvePinnedHostnameWithPolicyMock.mockResolvedValue({
29
- hostname: "example.com",
30
- addresses: ["93.184.216.34"],
31
- lookup: vi.fn(),
32
- });
33
- });
34
-
35
- it("uses POST for getWebhookInfo", async () => {
36
- await expectPostJsonRequest(getWebhookInfo);
37
- });
38
-
39
- it("keeps POST for deleteWebhook", async () => {
40
- await expectPostJsonRequest(deleteWebhook);
41
- });
42
-
43
- it("aborts sendChatAction when the typing timeout elapses", async () => {
44
- vi.useFakeTimers();
45
- try {
46
- const fetcher = vi.fn<ZaloFetch>(
47
- (_, init) =>
48
- new Promise<Response>((_, reject) => {
49
- init?.signal?.addEventListener("abort", () => reject(new Error("aborted")), {
50
- once: true,
51
- });
52
- }),
53
- );
54
-
55
- const promise = sendChatAction(
56
- "test-token",
57
- {
58
- chat_id: "chat-123",
59
- action: "typing",
60
- },
61
- fetcher,
62
- 25,
63
- );
64
- const rejected = expect(promise).rejects.toThrow("aborted");
65
-
66
- await vi.advanceTimersByTimeAsync(25);
67
-
68
- await rejected;
69
- const [, init] = fetcher.mock.calls[0] ?? [];
70
- expect(init?.signal?.aborted).toBe(true);
71
- } finally {
72
- vi.useRealTimers();
73
- }
74
- });
75
-
76
- it("validates outbound photo URLs against the SSRF guard before posting", async () => {
77
- const fetcher = createOkFetcher();
78
-
79
- await sendPhoto(
80
- "test-token",
81
- {
82
- chat_id: "chat-123",
83
- photo: "https://example.com/image.png",
84
- },
85
- fetcher,
86
- );
87
-
88
- expect(resolvePinnedHostnameWithPolicyMock).toHaveBeenCalledWith("example.com", {
89
- policy: {},
90
- });
91
- expect(fetcher).toHaveBeenCalledTimes(1);
92
- });
93
-
94
- it("blocks private-network photo URLs before they reach the Zalo API", async () => {
95
- const fetcher = createOkFetcher();
96
- resolvePinnedHostnameWithPolicyMock.mockRejectedValueOnce(
97
- new Error("Blocked hostname or private/internal/special-use IP address"),
98
- );
99
-
100
- await expect(
101
- sendPhoto(
102
- "test-token",
103
- {
104
- chat_id: "chat-123",
105
- photo: "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
106
- },
107
- fetcher,
108
- ),
109
- ).rejects.toThrow("Blocked hostname or private/internal/special-use IP address");
110
-
111
- expect(fetcher).not.toHaveBeenCalled();
112
- });
113
-
114
- it("rejects non-http photo URLs", async () => {
115
- const fetcher = createOkFetcher();
116
-
117
- await expect(
118
- sendPhoto(
119
- "test-token",
120
- {
121
- chat_id: "chat-123",
122
- photo: "file:///etc/passwd",
123
- },
124
- fetcher,
125
- ),
126
- ).rejects.toThrow("Zalo photo URL must use HTTP or HTTPS");
127
-
128
- expect(resolvePinnedHostnameWithPolicyMock).not.toHaveBeenCalled();
129
- expect(fetcher).not.toHaveBeenCalled();
130
- });
131
-
132
- it("rejects non-URL strings", async () => {
133
- const fetcher = createOkFetcher();
134
-
135
- await expect(
136
- sendPhoto(
137
- "test-token",
138
- {
139
- chat_id: "chat-123",
140
- photo: "not a url",
141
- },
142
- fetcher,
143
- ),
144
- ).rejects.toThrow("Zalo photo URL must be an absolute HTTP or HTTPS URL");
145
-
146
- expect(resolvePinnedHostnameWithPolicyMock).not.toHaveBeenCalled();
147
- expect(fetcher).not.toHaveBeenCalled();
148
- });
149
- });
package/src/api.ts DELETED
@@ -1,265 +0,0 @@
1
- /**
2
- * Zalo Bot API client
3
- * @see https://bot.zaloplatforms.com/docs
4
- */
5
-
6
- import { resolvePinnedHostnameWithPolicy, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
7
-
8
- const ZALO_API_BASE = "https://bot-api.zaloplatforms.com";
9
- const ZALO_MEDIA_SSRF_POLICY: SsrFPolicy = {};
10
-
11
- export type ZaloFetch = (input: string, init?: RequestInit) => Promise<Response>;
12
-
13
- export type ZaloApiResponse<T = unknown> = {
14
- ok: boolean;
15
- result?: T;
16
- error_code?: number;
17
- description?: string;
18
- };
19
-
20
- export type ZaloBotInfo = {
21
- id: string;
22
- name: string;
23
- avatar?: string;
24
- };
25
-
26
- export type ZaloMessage = {
27
- message_id: string;
28
- from: {
29
- id: string;
30
- name?: string;
31
- display_name?: string;
32
- avatar?: string;
33
- is_bot?: boolean;
34
- };
35
- chat: {
36
- id: string;
37
- chat_type: "PRIVATE" | "GROUP";
38
- };
39
- date: number;
40
- text?: string;
41
- photo_url?: string;
42
- caption?: string;
43
- sticker?: string;
44
- message_type?: string;
45
- };
46
-
47
- export type ZaloUpdate = {
48
- event_name:
49
- | "message.text.received"
50
- | "message.image.received"
51
- | "message.sticker.received"
52
- | "message.unsupported.received";
53
- message?: ZaloMessage;
54
- };
55
-
56
- export type ZaloSendMessageParams = {
57
- chat_id: string;
58
- text: string;
59
- };
60
-
61
- export type ZaloSendPhotoParams = {
62
- chat_id: string;
63
- photo: string;
64
- caption?: string;
65
- };
66
-
67
- export type ZaloSendChatActionParams = {
68
- chat_id: string;
69
- action: "typing" | "upload_photo";
70
- };
71
-
72
- export type ZaloSetWebhookParams = {
73
- url: string;
74
- secret_token: string;
75
- };
76
-
77
- export type ZaloWebhookInfo = {
78
- url?: string;
79
- updated_at?: number;
80
- has_custom_certificate?: boolean;
81
- };
82
-
83
- export type ZaloGetUpdatesParams = {
84
- /** Timeout in seconds (passed as string to API) */
85
- timeout?: number;
86
- };
87
-
88
- export class ZaloApiError extends Error {
89
- constructor(
90
- message: string,
91
- public readonly errorCode?: number,
92
- public readonly description?: string,
93
- ) {
94
- super(message);
95
- this.name = "ZaloApiError";
96
- }
97
-
98
- /** True if this is a long-polling timeout (no updates available) */
99
- get isPollingTimeout(): boolean {
100
- return this.errorCode === 408;
101
- }
102
- }
103
-
104
- /**
105
- * Call the Zalo Bot API
106
- */
107
- export async function callZaloApi<T = unknown>(
108
- method: string,
109
- token: string,
110
- body?: Record<string, unknown>,
111
- options?: { timeoutMs?: number; fetch?: ZaloFetch },
112
- ): Promise<ZaloApiResponse<T>> {
113
- const url = `${ZALO_API_BASE}/bot${token}/${method}`;
114
- const controller = new AbortController();
115
- const timeoutId = options?.timeoutMs
116
- ? setTimeout(() => controller.abort(), options.timeoutMs)
117
- : undefined;
118
- const fetcher = options?.fetch ?? fetch;
119
-
120
- try {
121
- const response = await fetcher(url, {
122
- method: "POST",
123
- headers: {
124
- "Content-Type": "application/json",
125
- },
126
- body: body ? JSON.stringify(body) : undefined,
127
- signal: controller.signal,
128
- });
129
-
130
- const data = (await response.json()) as ZaloApiResponse<T>;
131
-
132
- if (!data.ok) {
133
- throw new ZaloApiError(
134
- data.description ?? `Zalo API error: ${method}`,
135
- data.error_code,
136
- data.description,
137
- );
138
- }
139
-
140
- return data;
141
- } finally {
142
- if (timeoutId) {
143
- clearTimeout(timeoutId);
144
- }
145
- }
146
- }
147
-
148
- /**
149
- * Validate bot token and get bot info
150
- */
151
- export async function getMe(
152
- token: string,
153
- timeoutMs?: number,
154
- fetcher?: ZaloFetch,
155
- ): Promise<ZaloApiResponse<ZaloBotInfo>> {
156
- return callZaloApi<ZaloBotInfo>("getMe", token, undefined, { timeoutMs, fetch: fetcher });
157
- }
158
-
159
- /**
160
- * Send a text message
161
- */
162
- export async function sendMessage(
163
- token: string,
164
- params: ZaloSendMessageParams,
165
- fetcher?: ZaloFetch,
166
- ): Promise<ZaloApiResponse<ZaloMessage>> {
167
- return callZaloApi<ZaloMessage>("sendMessage", token, params, { fetch: fetcher });
168
- }
169
-
170
- /**
171
- * Send a photo message
172
- */
173
- export async function sendPhoto(
174
- token: string,
175
- params: ZaloSendPhotoParams,
176
- fetcher?: ZaloFetch,
177
- ): Promise<ZaloApiResponse<ZaloMessage>> {
178
- const photoUrl = params.photo.trim();
179
- let parsedPhotoUrl: URL;
180
- try {
181
- parsedPhotoUrl = new URL(photoUrl);
182
- } catch {
183
- throw new Error("Zalo photo URL must be an absolute HTTP or HTTPS URL");
184
- }
185
-
186
- if (parsedPhotoUrl.protocol !== "http:" && parsedPhotoUrl.protocol !== "https:") {
187
- throw new Error("Zalo photo URL must use HTTP or HTTPS");
188
- }
189
-
190
- await resolvePinnedHostnameWithPolicy(parsedPhotoUrl.hostname, {
191
- policy: ZALO_MEDIA_SSRF_POLICY,
192
- });
193
-
194
- return callZaloApi<ZaloMessage>(
195
- "sendPhoto",
196
- token,
197
- { ...params, photo: parsedPhotoUrl.href },
198
- { fetch: fetcher },
199
- );
200
- }
201
-
202
- /**
203
- * Send a temporary chat action such as typing.
204
- */
205
- export async function sendChatAction(
206
- token: string,
207
- params: ZaloSendChatActionParams,
208
- fetcher?: ZaloFetch,
209
- timeoutMs?: number,
210
- ): Promise<ZaloApiResponse<boolean>> {
211
- return callZaloApi<boolean>("sendChatAction", token, params, {
212
- timeoutMs,
213
- fetch: fetcher,
214
- });
215
- }
216
-
217
- /**
218
- * Get updates using long polling (dev/testing only)
219
- * Note: Zalo returns a single update per call, not an array like Telegram
220
- */
221
- export async function getUpdates(
222
- token: string,
223
- params?: ZaloGetUpdatesParams,
224
- fetcher?: ZaloFetch,
225
- ): Promise<ZaloApiResponse<ZaloUpdate>> {
226
- const pollTimeoutSec = params?.timeout ?? 30;
227
- const timeoutMs = (pollTimeoutSec + 5) * 1000;
228
- const body = { timeout: String(pollTimeoutSec) };
229
- return callZaloApi<ZaloUpdate>("getUpdates", token, body, { timeoutMs, fetch: fetcher });
230
- }
231
-
232
- /**
233
- * Set webhook URL for receiving updates
234
- */
235
- export async function setWebhook(
236
- token: string,
237
- params: ZaloSetWebhookParams,
238
- fetcher?: ZaloFetch,
239
- ): Promise<ZaloApiResponse<ZaloWebhookInfo>> {
240
- return callZaloApi<ZaloWebhookInfo>("setWebhook", token, params, { fetch: fetcher });
241
- }
242
-
243
- /**
244
- * Delete webhook configuration
245
- */
246
- export async function deleteWebhook(
247
- token: string,
248
- fetcher?: ZaloFetch,
249
- timeoutMs?: number,
250
- ): Promise<ZaloApiResponse<ZaloWebhookInfo>> {
251
- return callZaloApi<ZaloWebhookInfo>("deleteWebhook", token, undefined, {
252
- timeoutMs,
253
- fetch: fetcher,
254
- });
255
- }
256
-
257
- /**
258
- * Get current webhook info
259
- */
260
- export async function getWebhookInfo(
261
- token: string,
262
- fetcher?: ZaloFetch,
263
- ): Promise<ZaloApiResponse<ZaloWebhookInfo>> {
264
- return callZaloApi<ZaloWebhookInfo>("getWebhookInfo", token, undefined, { fetch: fetcher });
265
- }
@@ -1,17 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { zaloApprovalAuth } from "./approval-auth.js";
3
-
4
- describe("zaloApprovalAuth", () => {
5
- it("authorizes numeric Zalo user ids", () => {
6
- const cfg = { channels: { zalo: { allowFrom: ["zl:123"] } } };
7
-
8
- expect(
9
- zaloApprovalAuth.authorizeActorAction({
10
- cfg,
11
- senderId: "123",
12
- action: "approve",
13
- approvalKind: "exec",
14
- }),
15
- ).toEqual({ authorized: true });
16
- });
17
- });
@@ -1,25 +0,0 @@
1
- import {
2
- createResolvedApproverActionAuthAdapter,
3
- resolveApprovalApprovers,
4
- } from "openclaw/plugin-sdk/approval-auth-runtime";
5
- import { resolveZaloAccount } from "./accounts.js";
6
-
7
- function normalizeZaloApproverId(value: string | number): string | undefined {
8
- const normalized = String(value)
9
- .trim()
10
- .replace(/^(zalo|zl):/i, "")
11
- .trim();
12
- return /^\d+$/.test(normalized) ? normalized : undefined;
13
- }
14
-
15
- export const zaloApprovalAuth = createResolvedApproverActionAuthAdapter({
16
- channelLabel: "Zalo",
17
- resolveApprovers: ({ cfg, accountId }) => {
18
- const account = resolveZaloAccount({ cfg, accountId }).config;
19
- return resolveApprovalApprovers({
20
- allowFrom: account.allowFrom,
21
- normalizeApprover: normalizeZaloApproverId,
22
- });
23
- },
24
- normalizeSenderId: (value) => normalizeZaloApproverId(value),
25
- });