@openclaw/zalo 2026.1.29

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/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ ## 2026.1.29
4
+
5
+ ### Changes
6
+ - Version alignment with core OpenClaw release numbers.
7
+
8
+ ## 2026.1.23
9
+
10
+ ### Changes
11
+ - Version alignment with core OpenClaw release numbers.
12
+
13
+ ## 2026.1.22
14
+
15
+ ### Changes
16
+ - Version alignment with core OpenClaw release numbers.
17
+
18
+ ## 2026.1.21
19
+
20
+ ### Changes
21
+ - Version alignment with core OpenClaw release numbers.
22
+
23
+ ## 2026.1.20
24
+
25
+ ### Changes
26
+ - Version alignment with core OpenClaw release numbers.
27
+
28
+ ## 2026.1.17-1
29
+
30
+ ### Changes
31
+ - Version alignment with core OpenClaw release numbers.
32
+
33
+ ## 2026.1.17
34
+
35
+ ### Changes
36
+ - Version alignment with core OpenClaw release numbers.
37
+
38
+ ## 2026.1.16
39
+
40
+ ### Changes
41
+ - Version alignment with core OpenClaw release numbers.
42
+
43
+ ## 2026.1.15
44
+
45
+ ### Changes
46
+ - Version alignment with core OpenClaw release numbers.
47
+
48
+ ## 2026.1.14
49
+
50
+ ### Changes
51
+ - Version alignment with core OpenClaw release numbers.
52
+
53
+ ## 0.1.0
54
+
55
+ ### Features
56
+ - Zalo Bot API channel plugin with token-based auth (env/config/file).
57
+ - Direct message support (DMs only) with pairing/allowlist/open/disabled policies.
58
+ - Polling and webhook delivery modes.
59
+ - Text + image messaging with 2000-char chunking and media size caps.
60
+ - Multi-account support with per-account config.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # @openclaw/zalo
2
+
3
+ Zalo channel plugin for OpenClaw (Bot API).
4
+
5
+ ## Install (local checkout)
6
+
7
+ ```bash
8
+ openclaw plugins install ./extensions/zalo
9
+ ```
10
+
11
+ ## Install (npm)
12
+
13
+ ```bash
14
+ openclaw plugins install @openclaw/zalo
15
+ ```
16
+
17
+ Onboarding: select Zalo and confirm the install prompt to fetch the plugin automatically.
18
+
19
+ ## Config
20
+
21
+ ```json5
22
+ {
23
+ channels: {
24
+ zalo: {
25
+ enabled: true,
26
+ botToken: "12345689:abc-xyz",
27
+ dmPolicy: "pairing",
28
+ proxy: "http://proxy.local:8080"
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ ## Webhook mode
35
+
36
+ ```json5
37
+ {
38
+ channels: {
39
+ zalo: {
40
+ webhookUrl: "https://example.com/zalo-webhook",
41
+ webhookSecret: "your-secret-8-plus-chars",
42
+ webhookPath: "/zalo-webhook"
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ If `webhookPath` is omitted, the plugin uses the webhook URL path.
49
+
50
+ Restart the gateway after config changes.
package/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+
4
+ import { zaloDock, zaloPlugin } from "./src/channel.js";
5
+ import { handleZaloWebhookRequest } from "./src/monitor.js";
6
+ import { setZaloRuntime } from "./src/runtime.js";
7
+
8
+ const plugin = {
9
+ id: "zalo",
10
+ name: "Zalo",
11
+ description: "Zalo channel plugin (Bot API)",
12
+ configSchema: emptyPluginConfigSchema(),
13
+ register(api: OpenClawPluginApi) {
14
+ setZaloRuntime(api.runtime);
15
+ api.registerChannel({ plugin: zaloPlugin, dock: zaloDock });
16
+ api.registerHttpHandler(handleZaloWebhookRequest);
17
+ },
18
+ };
19
+
20
+ export default plugin;
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "zalo",
3
+ "channels": [
4
+ "zalo"
5
+ ],
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {}
10
+ }
11
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@openclaw/zalo",
3
+ "version": "2026.1.29",
4
+ "type": "module",
5
+ "description": "OpenClaw Zalo channel plugin",
6
+ "openclaw": {
7
+ "extensions": [
8
+ "./index.ts"
9
+ ],
10
+ "channel": {
11
+ "id": "zalo",
12
+ "label": "Zalo",
13
+ "selectionLabel": "Zalo (Bot API)",
14
+ "docsPath": "/channels/zalo",
15
+ "docsLabel": "zalo",
16
+ "blurb": "Vietnam-focused messaging platform with Bot API.",
17
+ "aliases": [
18
+ "zl"
19
+ ],
20
+ "order": 80,
21
+ "quickstartAllowFrom": true
22
+ },
23
+ "install": {
24
+ "npmSpec": "@openclaw/zalo",
25
+ "localPath": "extensions/zalo",
26
+ "defaultChoice": "npm"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "openclaw": "workspace:*",
31
+ "undici": "7.19.0"
32
+ }
33
+ }
@@ -0,0 +1,71 @@
1
+ import type { OpenClawConfig } from "openclaw/plugin-sdk";
2
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk";
3
+
4
+ import type { ResolvedZaloAccount, ZaloAccountConfig, ZaloConfig } from "./types.js";
5
+ import { resolveZaloToken } from "./token.js";
6
+
7
+ function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
8
+ const accounts = (cfg.channels?.zalo as ZaloConfig | undefined)?.accounts;
9
+ if (!accounts || typeof accounts !== "object") return [];
10
+ return Object.keys(accounts).filter(Boolean);
11
+ }
12
+
13
+ export function listZaloAccountIds(cfg: OpenClawConfig): string[] {
14
+ const ids = listConfiguredAccountIds(cfg);
15
+ if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
16
+ return ids.sort((a, b) => a.localeCompare(b));
17
+ }
18
+
19
+ export function resolveDefaultZaloAccountId(cfg: OpenClawConfig): string {
20
+ const zaloConfig = cfg.channels?.zalo as ZaloConfig | undefined;
21
+ if (zaloConfig?.defaultAccount?.trim()) return zaloConfig.defaultAccount.trim();
22
+ const ids = listZaloAccountIds(cfg);
23
+ if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
24
+ return ids[0] ?? DEFAULT_ACCOUNT_ID;
25
+ }
26
+
27
+ function resolveAccountConfig(
28
+ cfg: OpenClawConfig,
29
+ accountId: string,
30
+ ): ZaloAccountConfig | undefined {
31
+ const accounts = (cfg.channels?.zalo as ZaloConfig | undefined)?.accounts;
32
+ if (!accounts || typeof accounts !== "object") return undefined;
33
+ return accounts[accountId] as ZaloAccountConfig | undefined;
34
+ }
35
+
36
+ function mergeZaloAccountConfig(cfg: OpenClawConfig, accountId: string): ZaloAccountConfig {
37
+ const raw = (cfg.channels?.zalo ?? {}) as ZaloConfig;
38
+ const { accounts: _ignored, defaultAccount: _ignored2, ...base } = raw;
39
+ const account = resolveAccountConfig(cfg, accountId) ?? {};
40
+ return { ...base, ...account };
41
+ }
42
+
43
+ export function resolveZaloAccount(params: {
44
+ cfg: OpenClawConfig;
45
+ accountId?: string | null;
46
+ }): ResolvedZaloAccount {
47
+ const accountId = normalizeAccountId(params.accountId);
48
+ const baseEnabled = (params.cfg.channels?.zalo as ZaloConfig | undefined)?.enabled !== false;
49
+ const merged = mergeZaloAccountConfig(params.cfg, accountId);
50
+ const accountEnabled = merged.enabled !== false;
51
+ const enabled = baseEnabled && accountEnabled;
52
+ const tokenResolution = resolveZaloToken(
53
+ params.cfg.channels?.zalo as ZaloConfig | undefined,
54
+ accountId,
55
+ );
56
+
57
+ return {
58
+ accountId,
59
+ name: merged.name?.trim() || undefined,
60
+ enabled,
61
+ token: tokenResolution.token,
62
+ tokenSource: tokenResolution.source,
63
+ config: merged,
64
+ };
65
+ }
66
+
67
+ export function listEnabledZaloAccounts(cfg: OpenClawConfig): ResolvedZaloAccount[] {
68
+ return listZaloAccountIds(cfg)
69
+ .map((accountId) => resolveZaloAccount({ cfg, accountId }))
70
+ .filter((account) => account.enabled);
71
+ }
package/src/actions.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type {
2
+ ChannelMessageActionAdapter,
3
+ ChannelMessageActionName,
4
+ OpenClawConfig,
5
+ } from "openclaw/plugin-sdk";
6
+ import { jsonResult, readStringParam } from "openclaw/plugin-sdk";
7
+
8
+ import { listEnabledZaloAccounts } from "./accounts.js";
9
+ import { sendMessageZalo } from "./send.js";
10
+
11
+ const providerId = "zalo";
12
+
13
+ function listEnabledAccounts(cfg: OpenClawConfig) {
14
+ return listEnabledZaloAccounts(cfg).filter(
15
+ (account) => account.enabled && account.tokenSource !== "none",
16
+ );
17
+ }
18
+
19
+ export const zaloMessageActions: ChannelMessageActionAdapter = {
20
+ listActions: ({ cfg }) => {
21
+ const accounts = listEnabledAccounts(cfg as OpenClawConfig);
22
+ if (accounts.length === 0) return [];
23
+ const actions = new Set<ChannelMessageActionName>(["send"]);
24
+ return Array.from(actions);
25
+ },
26
+ supportsButtons: () => false,
27
+ extractToolSend: ({ args }) => {
28
+ const action = typeof args.action === "string" ? args.action.trim() : "";
29
+ if (action !== "sendMessage") return null;
30
+ const to = typeof args.to === "string" ? args.to : undefined;
31
+ if (!to) return null;
32
+ const accountId = typeof args.accountId === "string" ? args.accountId.trim() : undefined;
33
+ return { to, accountId };
34
+ },
35
+ handleAction: async ({ action, params, cfg, accountId }) => {
36
+ if (action === "send") {
37
+ const to = readStringParam(params, "to", { required: true });
38
+ const content = readStringParam(params, "message", {
39
+ required: true,
40
+ allowEmpty: true,
41
+ });
42
+ const mediaUrl = readStringParam(params, "media", { trim: false });
43
+
44
+ const result = await sendMessageZalo(to ?? "", content ?? "", {
45
+ accountId: accountId ?? undefined,
46
+ mediaUrl: mediaUrl ?? undefined,
47
+ cfg: cfg as OpenClawConfig,
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.ts ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Zalo Bot API client
3
+ * @see https://bot.zaloplatforms.com/docs
4
+ */
5
+
6
+ const ZALO_API_BASE = "https://bot-api.zaloplatforms.com";
7
+
8
+ export type ZaloFetch = (input: string, init?: RequestInit) => Promise<Response>;
9
+
10
+ export type ZaloApiResponse<T = unknown> = {
11
+ ok: boolean;
12
+ result?: T;
13
+ error_code?: number;
14
+ description?: string;
15
+ };
16
+
17
+ export type ZaloBotInfo = {
18
+ id: string;
19
+ name: string;
20
+ avatar?: string;
21
+ };
22
+
23
+ export type ZaloMessage = {
24
+ message_id: string;
25
+ from: {
26
+ id: string;
27
+ name?: string;
28
+ avatar?: string;
29
+ };
30
+ chat: {
31
+ id: string;
32
+ chat_type: "PRIVATE" | "GROUP";
33
+ };
34
+ date: number;
35
+ text?: string;
36
+ photo?: string;
37
+ caption?: string;
38
+ sticker?: string;
39
+ };
40
+
41
+ export type ZaloUpdate = {
42
+ event_name:
43
+ | "message.text.received"
44
+ | "message.image.received"
45
+ | "message.sticker.received"
46
+ | "message.unsupported.received";
47
+ message?: ZaloMessage;
48
+ };
49
+
50
+ export type ZaloSendMessageParams = {
51
+ chat_id: string;
52
+ text: string;
53
+ };
54
+
55
+ export type ZaloSendPhotoParams = {
56
+ chat_id: string;
57
+ photo: string;
58
+ caption?: string;
59
+ };
60
+
61
+ export type ZaloSetWebhookParams = {
62
+ url: string;
63
+ secret_token: string;
64
+ };
65
+
66
+ export type ZaloGetUpdatesParams = {
67
+ /** Timeout in seconds (passed as string to API) */
68
+ timeout?: number;
69
+ };
70
+
71
+ export class ZaloApiError extends Error {
72
+ constructor(
73
+ message: string,
74
+ public readonly errorCode?: number,
75
+ public readonly description?: string,
76
+ ) {
77
+ super(message);
78
+ this.name = "ZaloApiError";
79
+ }
80
+
81
+ /** True if this is a long-polling timeout (no updates available) */
82
+ get isPollingTimeout(): boolean {
83
+ return this.errorCode === 408;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Call the Zalo Bot API
89
+ */
90
+ export async function callZaloApi<T = unknown>(
91
+ method: string,
92
+ token: string,
93
+ body?: Record<string, unknown>,
94
+ options?: { timeoutMs?: number; fetch?: ZaloFetch },
95
+ ): Promise<ZaloApiResponse<T>> {
96
+ const url = `${ZALO_API_BASE}/bot${token}/${method}`;
97
+ const controller = new AbortController();
98
+ const timeoutId = options?.timeoutMs
99
+ ? setTimeout(() => controller.abort(), options.timeoutMs)
100
+ : undefined;
101
+ const fetcher = options?.fetch ?? fetch;
102
+
103
+ try {
104
+ const response = await fetcher(url, {
105
+ method: "POST",
106
+ headers: {
107
+ "Content-Type": "application/json",
108
+ },
109
+ body: body ? JSON.stringify(body) : undefined,
110
+ signal: controller.signal,
111
+ });
112
+
113
+ const data = (await response.json()) as ZaloApiResponse<T>;
114
+
115
+ if (!data.ok) {
116
+ throw new ZaloApiError(
117
+ data.description ?? `Zalo API error: ${method}`,
118
+ data.error_code,
119
+ data.description,
120
+ );
121
+ }
122
+
123
+ return data;
124
+ } finally {
125
+ if (timeoutId) clearTimeout(timeoutId);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Validate bot token and get bot info
131
+ */
132
+ export async function getMe(
133
+ token: string,
134
+ timeoutMs?: number,
135
+ fetcher?: ZaloFetch,
136
+ ): Promise<ZaloApiResponse<ZaloBotInfo>> {
137
+ return callZaloApi<ZaloBotInfo>("getMe", token, undefined, { timeoutMs, fetch: fetcher });
138
+ }
139
+
140
+ /**
141
+ * Send a text message
142
+ */
143
+ export async function sendMessage(
144
+ token: string,
145
+ params: ZaloSendMessageParams,
146
+ fetcher?: ZaloFetch,
147
+ ): Promise<ZaloApiResponse<ZaloMessage>> {
148
+ return callZaloApi<ZaloMessage>("sendMessage", token, params, { fetch: fetcher });
149
+ }
150
+
151
+ /**
152
+ * Send a photo message
153
+ */
154
+ export async function sendPhoto(
155
+ token: string,
156
+ params: ZaloSendPhotoParams,
157
+ fetcher?: ZaloFetch,
158
+ ): Promise<ZaloApiResponse<ZaloMessage>> {
159
+ return callZaloApi<ZaloMessage>("sendPhoto", token, params, { fetch: fetcher });
160
+ }
161
+
162
+ /**
163
+ * Get updates using long polling (dev/testing only)
164
+ * Note: Zalo returns a single update per call, not an array like Telegram
165
+ */
166
+ export async function getUpdates(
167
+ token: string,
168
+ params?: ZaloGetUpdatesParams,
169
+ fetcher?: ZaloFetch,
170
+ ): Promise<ZaloApiResponse<ZaloUpdate>> {
171
+ const pollTimeoutSec = params?.timeout ?? 30;
172
+ const timeoutMs = (pollTimeoutSec + 5) * 1000;
173
+ const body = { timeout: String(pollTimeoutSec) };
174
+ return callZaloApi<ZaloUpdate>("getUpdates", token, body, { timeoutMs, fetch: fetcher });
175
+ }
176
+
177
+ /**
178
+ * Set webhook URL for receiving updates
179
+ */
180
+ export async function setWebhook(
181
+ token: string,
182
+ params: ZaloSetWebhookParams,
183
+ fetcher?: ZaloFetch,
184
+ ): Promise<ZaloApiResponse<boolean>> {
185
+ return callZaloApi<boolean>("setWebhook", token, params, { fetch: fetcher });
186
+ }
187
+
188
+ /**
189
+ * Delete webhook configuration
190
+ */
191
+ export async function deleteWebhook(
192
+ token: string,
193
+ fetcher?: ZaloFetch,
194
+ ): Promise<ZaloApiResponse<boolean>> {
195
+ return callZaloApi<boolean>("deleteWebhook", token, undefined, { fetch: fetcher });
196
+ }
197
+
198
+ /**
199
+ * Get current webhook info
200
+ */
201
+ export async function getWebhookInfo(
202
+ token: string,
203
+ fetcher?: ZaloFetch,
204
+ ): Promise<ZaloApiResponse<{ url?: string; has_custom_certificate?: boolean }>> {
205
+ return callZaloApi("getWebhookInfo", token, undefined, { fetch: fetcher });
206
+ }
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import type { OpenClawConfig } from "openclaw/plugin-sdk";
4
+
5
+ import { zaloPlugin } from "./channel.js";
6
+
7
+ describe("zalo directory", () => {
8
+ it("lists peers from allowFrom", async () => {
9
+ const cfg = {
10
+ channels: {
11
+ zalo: {
12
+ allowFrom: ["zalo:123", "zl:234", "345"],
13
+ },
14
+ },
15
+ } as unknown as OpenClawConfig;
16
+
17
+ expect(zaloPlugin.directory).toBeTruthy();
18
+ expect(zaloPlugin.directory?.listPeers).toBeTruthy();
19
+ expect(zaloPlugin.directory?.listGroups).toBeTruthy();
20
+
21
+ await expect(
22
+ zaloPlugin.directory!.listPeers({ cfg, accountId: undefined, query: undefined, limit: undefined }),
23
+ ).resolves.toEqual(
24
+ expect.arrayContaining([
25
+ { kind: "user", id: "123" },
26
+ { kind: "user", id: "234" },
27
+ { kind: "user", id: "345" },
28
+ ]),
29
+ );
30
+
31
+ await expect(zaloPlugin.directory!.listGroups({ cfg, accountId: undefined, query: undefined, limit: undefined })).resolves.toEqual(
32
+ [],
33
+ );
34
+ });
35
+ });