@openclaw/zalo 2026.7.2-beta.7 → 2026.8.1-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.
@@ -1,4 +1,4 @@
1
- import { t as sendMessageZalo } from "./send-BUvbbedq.js";
1
+ import { t as sendMessageZalo } from "./send-BGGtv8x_.js";
2
2
  //#region extensions/zalo/src/actions.runtime.ts
3
3
  const zaloActionsRuntime = { sendMessageZalo };
4
4
  //#endregion
package/dist/api.js CHANGED
@@ -1,5 +1,5 @@
1
- import { n as zaloDmPolicy, r as zaloSetupAdapter, t as createZaloSetupWizardProxy } from "./setup-core-LzhuTlsD.js";
2
- import { t as zaloPlugin } from "./channel-idqJI6YK.js";
1
+ import { n as zaloDmPolicy, r as zaloSetupAdapter, t as createZaloSetupWizardProxy } from "./setup-core-T6qc2eAG.js";
2
+ import { t as zaloPlugin } from "./channel-Dcp-XLf8.js";
3
3
  import { n as resolveZaloRuntimeGroupPolicy } from "./group-access-8qHRzDHx.js";
4
4
  import { zaloSetupWizard } from "./setup-api.js";
5
5
  export { createZaloSetupWizardProxy, resolveZaloRuntimeGroupPolicy, zaloDmPolicy, zaloPlugin, zaloSetupAdapter, zaloSetupWizard };
@@ -1,4 +1,4 @@
1
- import { c as inspectZaloAccount, d as resolveZaloAccount, i as zaloSetupContract, l as listZaloAccountIds, p as buildSecretInputSchema, r as zaloSetupAdapter, t as createZaloSetupWizardProxy, u as resolveDefaultZaloAccountId } from "./setup-core-LzhuTlsD.js";
1
+ import { c as inspectZaloAccount, d as resolveZaloAccount, i as zaloSetupContract, l as listZaloAccountIds, p as buildSecretInputSchema, t as createZaloSetupWizardProxy, u as resolveDefaultZaloAccountId } from "./setup-core-T6qc2eAG.js";
2
2
  import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Bxvjh0Hq.js";
3
3
  import { describeWebhookAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
4
4
  import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
@@ -24,7 +24,7 @@ import { AllowFromListSchema, DmPolicySchema, GroupPolicySchema, MarkdownConfigS
24
24
  import { z } from "zod";
25
25
  import { coerceStatusIssueAccountId, readStatusIssueFields } from "openclaw/plugin-sdk/extension-shared";
26
26
  //#region extensions/zalo/src/actions.ts
27
- const loadZaloActionsRuntime = createLazyRuntimeNamedExport(() => import("./actions.runtime-BYBjeo4Q.js"), "zaloActionsRuntime");
27
+ const loadZaloActionsRuntime = createLazyRuntimeNamedExport(() => import("./actions.runtime-BRP15DNe.js"), "zaloActionsRuntime");
28
28
  const providerId = "zalo";
29
29
  const ZALO_ACTIONS = /* @__PURE__ */ new Set(["send"]);
30
30
  function listEnabledAccounts(cfg, accountId) {
@@ -92,6 +92,7 @@ const zaloApprovalAuth = createChannelApprovalAuth({
92
92
  const ZaloConfigSchema = buildMultiAccountChannelSchema(z.object({
93
93
  name: z.string().optional(),
94
94
  enabled: z.boolean().optional(),
95
+ configWrites: z.boolean().optional(),
95
96
  markdown: MarkdownConfigSchema,
96
97
  botToken: buildSecretInputSchema().optional(),
97
98
  tokenFile: z.string().optional(),
@@ -179,8 +180,8 @@ function looksLikeZaloChatId(raw, normalized) {
179
180
  const target = normalizeZaloMessagingTarget(normalized ?? raw);
180
181
  return Boolean(target);
181
182
  }
182
- const loadZaloChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-DsaLk085.js"));
183
- const zaloSetupWizard = createZaloSetupWizardProxy(async () => (await import("./setup-surface-CQMbpZye.js")).zaloSetupWizard);
183
+ const loadZaloChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-5CivhE5e.js"));
184
+ const zaloSetupWizard = createZaloSetupWizardProxy(async () => (await import("./setup-surface-edfRk3eu.js").then((n) => n.t)).zaloSetupWizard);
184
185
  const zaloTextChunkLimit = 2e3;
185
186
  async function sendZaloDelivery(ctx) {
186
187
  const result = await (await loadZaloChannelRuntime()).sendZaloText({
@@ -263,7 +264,6 @@ const zaloPlugin = createChatChannelPlugin({
263
264
  base: {
264
265
  id: "zalo",
265
266
  meta,
266
- setup: zaloSetupAdapter,
267
267
  setupContract: zaloSetupContract,
268
268
  setupWizard: zaloSetupWizard,
269
269
  capabilities: {
@@ -301,6 +301,10 @@ const zaloPlugin = createChatChannelPlugin({
301
301
  messaging: {
302
302
  targetPrefixes: ["zalo", "zl"],
303
303
  normalizeTarget: normalizeZaloMessagingTarget,
304
+ inferTargetChatType: ({ to }) => {
305
+ const target = normalizeZaloMessagingTarget(to);
306
+ return target ? /^group:/i.test(target) ? "group" : "direct" : void 0;
307
+ },
304
308
  resolveOutboundSessionRoute: (params) => resolveZaloOutboundSessionRoute(params),
305
309
  targetResolver: {
306
310
  looksLikeId: looksLikeZaloChatId,
@@ -1,2 +1,2 @@
1
- import { t as zaloPlugin } from "./channel-idqJI6YK.js";
1
+ import { t as zaloPlugin } from "./channel-Dcp-XLf8.js";
2
2
  export { zaloPlugin };
@@ -1,58 +1,41 @@
1
- import { m as normalizeSecretInputString } from "./setup-core-LzhuTlsD.js";
1
+ import { m as normalizeSecretInputString } from "./setup-core-T6qc2eAG.js";
2
2
  import { i as PAIRING_APPROVED_MESSAGE } from "./runtime-api-qxdOyk3M.js";
3
- import { a as getMe, n as resolveZaloProxyFetch, r as ZaloApiError, t as sendMessageZalo } from "./send-BUvbbedq.js";
3
+ import { a as getMe, n as resolveZaloProxyFetch, r as ZaloApiError, t as sendMessageZalo } from "./send-BGGtv8x_.js";
4
4
  import { createAccountStatusSink } from "openclaw/plugin-sdk/channel-outbound";
5
+ import { runChannelProbe } from "openclaw/plugin-sdk/text-utility-runtime";
5
6
  //#region extensions/zalo/src/probe.ts
7
+ function formatZaloProbeError(error, timeoutMs) {
8
+ if (error instanceof ZaloApiError) return error.description ?? error.message;
9
+ if (error instanceof Error) return error.name === "AbortError" ? `Request timed out after ${timeoutMs}ms` : error.message;
10
+ return String(error);
11
+ }
6
12
  async function probeZalo(token, timeoutMs = 5e3, fetcher) {
7
13
  if (!token?.trim()) return {
8
14
  ok: false,
9
15
  error: "No token provided",
10
16
  elapsedMs: 0
11
17
  };
12
- const startTime = Date.now();
13
- try {
18
+ return await runChannelProbe(void 0, async ({ elapsedMs }) => {
14
19
  const response = await getMe(token.trim(), timeoutMs, fetcher);
15
- const elapsedMs = Date.now() - startTime;
16
20
  if (response.ok && response.result) return {
17
21
  ok: true,
18
22
  bot: response.result,
19
- elapsedMs
23
+ elapsedMs: elapsedMs()
20
24
  };
21
25
  return {
22
26
  ok: false,
23
27
  error: "Invalid response from Zalo API",
24
- elapsedMs
25
- };
26
- } catch (err) {
27
- const elapsedMs = Date.now() - startTime;
28
- if (err instanceof ZaloApiError) return {
29
- ok: false,
30
- error: err.description ?? err.message,
31
- elapsedMs
28
+ elapsedMs: elapsedMs()
32
29
  };
33
- if (err instanceof Error) {
34
- if (err.name === "AbortError") return {
35
- ok: false,
36
- error: `Request timed out after ${timeoutMs}ms`,
37
- elapsedMs
38
- };
39
- return {
40
- ok: false,
41
- error: err.message,
42
- elapsedMs
43
- };
44
- }
45
- return {
46
- ok: false,
47
- error: String(err),
48
- elapsedMs
49
- };
50
- }
30
+ }, (error) => ({
31
+ ok: false,
32
+ error: formatZaloProbeError(error, timeoutMs)
33
+ }));
51
34
  }
52
35
  //#endregion
53
36
  //#region extensions/zalo/src/channel.runtime.ts
54
37
  async function notifyZaloPairingApproval(params) {
55
- const { resolveZaloAccount } = await import("./setup-core-LzhuTlsD.js").then((n) => n.s);
38
+ const { resolveZaloAccount } = await import("./setup-core-T6qc2eAG.js").then((n) => n.s);
56
39
  const account = resolveZaloAccount({ cfg: params.cfg });
57
40
  if (!account.token) throw new Error("Zalo token not configured");
58
41
  await sendMessageZalo(params.id, PAIRING_APPROVED_MESSAGE, { token: account.token });
@@ -86,7 +69,7 @@ async function startZaloGatewayAccount(ctx) {
86
69
  setStatus: ctx.setStatus
87
70
  });
88
71
  ctx.log?.info(`[${account.accountId}] starting provider${zaloBotLabel} mode=${mode}`);
89
- const { monitorZaloProvider } = await import("./monitor-C5cximHM.js");
72
+ const { monitorZaloProvider } = await import("./monitor-Ckz5Mo22.js");
90
73
  return monitorZaloProvider({
91
74
  token,
92
75
  account,
@@ -1,16 +1,18 @@
1
1
  import { n as resolveZaloRuntimeGroupPolicy, t as normalizeZaloAllowEntry } from "./group-access-8qHRzDHx.js";
2
2
  import { t as getZaloRuntime } from "./runtime-api-qxdOyk3M.js";
3
- import { c as sendChatAction, d as setWebhook, f as ZALO_OUTBOUND_MEDIA_TTL_MS, i as deleteWebhook, l as sendMessage, n as resolveZaloProxyFetch, o as getUpdates, r as ZaloApiError, s as getWebhookInfo, u as sendPhoto } from "./send-BUvbbedq.js";
3
+ import { c as sendChatAction, d as setWebhook, f as ZALO_OUTBOUND_MEDIA_TTL_MS, i as deleteWebhook, l as sendMessage, n as resolveZaloProxyFetch, o as getUpdates, r as ZaloApiError, s as getWebhookInfo, u as sendPhoto } from "./send-BGGtv8x_.js";
4
+ import { createMessageReceiptFromOutboundResults } from "openclaw/plugin-sdk/channel-outbound";
4
5
  import { createLazyRuntimeModule, createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
5
6
  import { deliverTextOrMediaReply, resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
6
7
  import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
7
8
  import { resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
8
9
  import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
9
10
  import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
10
- import { registerPluginHttpRoute, resolveWebhookPath } from "openclaw/plugin-sdk/webhook-ingress";
11
+ import { canonicalizeWebhookRouteKey, registerPluginHttpRoute, resolveWebhookPath } from "openclaw/plugin-sdk/webhook-ingress";
11
12
  import { asDateTimestampMs, resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
12
- import { formatInboundMediaUnavailableText, resolveChannelInboundRouteEnvelope } from "openclaw/plugin-sdk/channel-inbound";
13
+ import { createChannelPartialDeliveryError, formatInboundMediaUnavailableText, resolveChannelInboundRouteEnvelope } from "openclaw/plugin-sdk/channel-inbound";
13
14
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
15
+ import { channelReadyPatch } from "openclaw/plugin-sdk/gateway-runtime";
14
16
  import { sleepWithAbort, waitForAbortSignal } from "openclaw/plugin-sdk/runtime-env";
15
17
  import { createHostedOutboundMediaStore } from "openclaw/plugin-sdk/outbound-media";
16
18
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
@@ -115,35 +117,44 @@ async function tryHandleHostedZaloMediaRequest(req, res) {
115
117
  res.end("Expired");
116
118
  return true;
117
119
  }
118
- const entry = await store.read(id, now);
119
- if (!entry || entry.metadata.routePath !== routePath) {
120
+ const metadata = await store.readMetadata(id, now);
121
+ if (!metadata || metadata.routePath !== routePath) {
120
122
  res.statusCode = 404;
121
123
  res.end("Not Found");
122
124
  return true;
123
125
  }
124
- const expiresAt = asDateTimestampMs(entry.metadata.expiresAt);
126
+ const expiresAt = asDateTimestampMs(metadata.expiresAt);
125
127
  if (expiresAt === void 0 || expiresAt <= now) {
126
128
  await store.delete(id);
127
129
  res.statusCode = 410;
128
130
  res.end("Expired");
129
131
  return true;
130
132
  }
131
- if (!safeEqualSecret(url.searchParams.get("token"), entry.metadata.token)) {
133
+ const token = url.searchParams.get("token");
134
+ if (!safeEqualSecret(token, metadata.token)) {
132
135
  res.statusCode = 401;
133
136
  res.end("Unauthorized");
134
137
  return true;
135
138
  }
136
- if (entry.metadata.contentType) res.setHeader("Content-Type", entry.metadata.contentType);
139
+ let servedMetadata = metadata;
140
+ let body;
141
+ if (method === "GET") {
142
+ const entry = await store.read(id, now);
143
+ if (!entry || entry.metadata.routePath !== routePath || !safeEqualSecret(token, entry.metadata.token)) {
144
+ res.statusCode = 404;
145
+ res.end("Not Found");
146
+ return true;
147
+ }
148
+ servedMetadata = entry.metadata;
149
+ body = entry.buffer;
150
+ }
151
+ if (servedMetadata.contentType) res.setHeader("Content-Type", servedMetadata.contentType);
137
152
  res.setHeader("Cache-Control", "no-store");
138
153
  res.setHeader("X-Content-Type-Options", "nosniff");
139
- res.setHeader("Content-Length", String(entry.metadata.byteLength));
140
- if (method === "HEAD") {
141
- res.statusCode = 200;
142
- res.end();
143
- return true;
144
- }
154
+ res.setHeader("Content-Length", String(servedMetadata.byteLength));
145
155
  res.statusCode = 200;
146
- res.end(entry.buffer);
156
+ res.end(body);
157
+ if (method === "HEAD") return true;
147
158
  await store.delete(id);
148
159
  return true;
149
160
  }
@@ -163,31 +174,23 @@ function resolveZaloTimestampMs(date) {
163
174
  if (!date) return;
164
175
  return date >= UNIX_MILLISECONDS_THRESHOLD ? date : date * 1e3;
165
176
  }
166
- const loadZaloWebhookRuntime = createLazyRuntimeNamedExport(() => import("./monitor.webhook-D56OCa3C.js"), "zaloWebhookRuntime");
167
- const loadZaloWebhookIngressRuntime = createLazyRuntimeNamedExport(() => import("./webhook-spool-DzCPbb3O.js"), "zaloWebhookIngressRuntime");
177
+ const loadZaloWebhookRuntime = createLazyRuntimeNamedExport(() => import("./monitor.webhook-S7nThy3R.js"), "zaloWebhookRuntime");
178
+ const loadZaloWebhookIngressRuntime = createLazyRuntimeNamedExport(() => import("./webhook-spool-Bf17xwqi.js"), "zaloWebhookIngressRuntime");
168
179
  const loadZaloWebhookModule = createLazyRuntimeModule(async () => ({
169
180
  ...await loadZaloWebhookRuntime(),
170
181
  ...await loadZaloWebhookIngressRuntime()
171
182
  }));
172
- function releaseSharedHostedMediaRouteRef(routePath) {
173
- const current = hostedMediaRouteRefs.get(routePath);
174
- if (!current) return;
175
- if (current.count > 1) {
176
- current.count -= 1;
177
- return;
178
- }
179
- hostedMediaRouteRefs.delete(routePath);
180
- for (const unregisterHandle of current.unregisters) unregisterHandle();
181
- }
182
183
  function registerSharedHostedMediaRoute(params) {
184
+ const routeKey = canonicalizeWebhookRouteKey(params.path);
183
185
  const unregister = registerPluginHttpRoute({
184
186
  auth: "plugin",
185
187
  match: "prefix",
186
188
  path: params.path,
187
189
  pluginId: "zalo",
188
190
  source: "zalo-hosted-media",
189
- accountId: params.accountId,
190
191
  log: params.log,
192
+ reuseExistingSameOwner: true,
193
+ throwOnFailure: true,
191
194
  handler: async (req, res) => {
192
195
  if (!await tryHandleHostedZaloMediaRequest(req, res) && !res.headersSent) {
193
196
  res.statusCode = 404;
@@ -196,17 +199,23 @@ function registerSharedHostedMediaRoute(params) {
196
199
  }
197
200
  }
198
201
  });
199
- const existing = hostedMediaRouteRefs.get(params.path);
200
- if (existing) {
201
- existing.count += 1;
202
- existing.unregisters.push(unregister);
203
- return () => releaseSharedHostedMediaRouteRef(params.path);
204
- }
205
- hostedMediaRouteRefs.set(params.path, {
206
- count: 1,
207
- unregisters: [unregister]
208
- });
209
- return () => releaseSharedHostedMediaRouteRef(params.path);
202
+ const acquired = hostedMediaRouteRefs.get(routeKey) ?? {
203
+ count: 0,
204
+ unregisters: []
205
+ };
206
+ if (acquired.count === 0) hostedMediaRouteRefs.set(routeKey, acquired);
207
+ acquired.count += 1;
208
+ acquired.unregisters.push(unregister);
209
+ let released = false;
210
+ return () => {
211
+ if (released) return;
212
+ released = true;
213
+ if (hostedMediaRouteRefs.get(routeKey) !== acquired) return;
214
+ acquired.count -= 1;
215
+ if (acquired.count > 0) return;
216
+ hostedMediaRouteRefs.delete(routeKey);
217
+ for (const unregisterHandle of acquired.unregisters) unregisterHandle();
218
+ };
210
219
  }
211
220
  function formatZaloError(error) {
212
221
  if (error instanceof Error) return error.stack ?? `${error.name}: ${error.message}`;
@@ -253,6 +262,7 @@ function startPollingLoop(params) {
253
262
  try {
254
263
  const response = await getUpdates(token, { timeout: pollTimeout }, fetcher);
255
264
  if (isStopped() || abortSignal.aborted) return;
265
+ if (response.ok) statusSink?.(channelReadyPatch());
256
266
  if (response.ok && response.result) {
257
267
  statusSink?.({ lastInboundAt: Date.now() });
258
268
  await processUpdate({
@@ -262,7 +272,13 @@ function startPollingLoop(params) {
262
272
  }
263
273
  } catch (err) {
264
274
  if (err instanceof ZaloApiError && err.isPollingTimeout) {} else if (!isStopped() && !abortSignal.aborted) {
265
- runtime.error?.(`[${account.accountId}] Zalo polling error: ${formatZaloError(err)}`);
275
+ const error = formatZaloError(err);
276
+ runtime.error?.(`[${account.accountId}] Zalo polling error: ${error}`);
277
+ statusSink?.({
278
+ connected: false,
279
+ lifecycle: "recovering",
280
+ lastError: error
281
+ });
266
282
  await sleepWithAbort(5e3, abortSignal).catch(() => void 0);
267
283
  }
268
284
  }
@@ -385,7 +401,7 @@ async function authorizeZaloMessage(params) {
385
401
  defaultGroupPolicy
386
402
  });
387
403
  const shouldComputeAuth = core.channel.commands.shouldComputeCommandAuthorized(rawBody, config);
388
- const access = await resolveStableChannelMessageIngress({
404
+ const resolveChannelIngress = async (contextBinding) => await resolveStableChannelMessageIngress({
389
405
  channelId: "zalo",
390
406
  accountId: account.accountId,
391
407
  identity: {
@@ -401,6 +417,7 @@ async function authorizeZaloMessage(params) {
401
417
  kind: isGroup ? "group" : "direct",
402
418
  id: chatId
403
419
  },
420
+ contextBinding,
404
421
  providerMissingFallbackApplied,
405
422
  dmPolicy,
406
423
  groupPolicy,
@@ -409,6 +426,7 @@ async function authorizeZaloMessage(params) {
409
426
  groupAllowFrom: normalizeStringEntries(account.config.groupAllowFrom),
410
427
  command: shouldComputeAuth ? {} : void 0
411
428
  });
429
+ const access = await resolveChannelIngress();
412
430
  const senderAccess = access.senderAccess;
413
431
  if (isGroup) {
414
432
  warnMissingProviderGroupPolicyFallbackOnce({
@@ -451,6 +469,8 @@ async function authorizeZaloMessage(params) {
451
469
  return;
452
470
  }
453
471
  return {
472
+ channelIngress: access,
473
+ resolveChannelIngress,
454
474
  chatId,
455
475
  commandAuthorized: access.commandAccess.requested ? access.commandAccess.authorized : void 0,
456
476
  isGroup,
@@ -468,7 +488,7 @@ async function processMessageWithPipeline(params) {
468
488
  mediaType
469
489
  });
470
490
  if (!authorization) return;
471
- const { isGroup, chatId, senderId, senderName, rawBody, commandAuthorized } = authorization;
491
+ const { isGroup, chatId, senderId, senderName, rawBody } = authorization;
472
492
  const agentBody = agentBodyOverride ?? rawBody;
473
493
  const { route, buildEnvelope } = resolveChannelInboundRouteEnvelope({
474
494
  cfg: config,
@@ -479,6 +499,17 @@ async function processMessageWithPipeline(params) {
479
499
  id: chatId
480
500
  }
481
501
  });
502
+ const channelIngress = await authorization.resolveChannelIngress({
503
+ agentId: route.agentId,
504
+ sessionKey: route.sessionKey,
505
+ messageId: message_id,
506
+ inboundEventKind: "user_request"
507
+ });
508
+ if (!channelIngress.senderAccess.allowed) {
509
+ logVerbose(core, runtime, `zalo: authorization changed before dispatch for ${senderId}`);
510
+ return;
511
+ }
512
+ const commandAuthorized = channelIngress.commandAccess.requested ? channelIngress.commandAccess.authorized : void 0;
482
513
  if (isGroup && core.channel.commands.isControlCommandMessage(rawBody, config) && commandAuthorized !== true) {
483
514
  logVerbose(core, runtime, `zalo: drop control command from unauthorized sender ${senderId}`);
484
515
  return;
@@ -492,6 +523,7 @@ async function processMessageWithPipeline(params) {
492
523
  body: agentBody
493
524
  });
494
525
  const ctxPayload = core.channel.inbound.buildContext({
526
+ channelIngress,
495
527
  channel: "zalo",
496
528
  accountId: route.accountId,
497
529
  messageId: message_id,
@@ -561,7 +593,6 @@ async function processMessageWithPipeline(params) {
561
593
  payload,
562
594
  token,
563
595
  chatId,
564
- runtime,
565
596
  core,
566
597
  config,
567
598
  webhookUrl: params.webhookUrl,
@@ -575,8 +606,8 @@ async function processMessageWithPipeline(params) {
575
606
  tableMode: "off"
576
607
  });
577
608
  },
578
- onDelivered: () => {
579
- statusSink?.({ lastOutboundAt: Date.now() });
609
+ onDelivered: (_payload, _info, result) => {
610
+ if (result?.visibleReplySent !== false) statusSink?.({ lastOutboundAt: Date.now() });
580
611
  },
581
612
  onError: (err, info) => {
582
613
  runtime.error?.(`[${account.accountId}] Zalo ${info.kind} reply failed: ${String(err)}`);
@@ -606,49 +637,64 @@ async function processMessageWithPipeline(params) {
606
637
  });
607
638
  }
608
639
  async function deliverZaloReply(params) {
609
- const { payload, token, chatId, runtime, core, config, webhookUrl, webhookPath, proxyUrl, mediaMaxBytes, canHostMedia, accountId, statusSink, fetcher } = params;
640
+ const { payload, token, chatId, core, config, webhookUrl, webhookPath, proxyUrl, mediaMaxBytes, canHostMedia, accountId, statusSink, fetcher } = params;
610
641
  const tableMode = params.tableMode ?? "code";
611
642
  const reply = resolveSendableOutboundReplyParts(payload, { text: core.channel.text.convertMarkdownTables(payload.text ?? "", tableMode) });
612
643
  const chunkMode = core.channel.text.resolveChunkMode(config, "zalo", accountId);
613
- await deliverTextOrMediaReply({
614
- payload,
615
- text: reply.text,
616
- chunkText: (value) => core.channel.text.chunkMarkdownTextWithMode(value, ZALO_TEXT_LIMIT, chunkMode),
617
- sendText: async (chunk) => {
618
- try {
619
- await sendMessage(token, {
644
+ const acceptedMessageIds = [];
645
+ let visibleReplySent = false;
646
+ const recordAcceptedSend = (result) => {
647
+ const messageId = result.result?.message_id;
648
+ if (messageId) acceptedMessageIds.push(messageId);
649
+ visibleReplySent = true;
650
+ statusSink?.({ lastOutboundAt: Date.now() });
651
+ };
652
+ try {
653
+ await deliverTextOrMediaReply({
654
+ payload,
655
+ text: reply.text,
656
+ chunkText: (value) => core.channel.text.chunkMarkdownTextWithMode(value, ZALO_TEXT_LIMIT, chunkMode),
657
+ sendText: async (chunk) => {
658
+ recordAcceptedSend(await sendMessage(token, {
620
659
  chat_id: chatId,
621
660
  text: chunk
622
- }, fetcher);
623
- statusSink?.({ lastOutboundAt: Date.now() });
624
- } catch (err) {
625
- runtime.error?.(`Zalo message send failed: ${String(err)}`);
661
+ }, fetcher));
662
+ },
663
+ sendMedia: async ({ mediaUrl, caption }) => {
664
+ const sendableMediaUrl = canHostMedia && webhookUrl && webhookPath ? await prepareHostedZaloMediaUrl({
665
+ mediaUrl,
666
+ webhookUrl,
667
+ webhookPath,
668
+ maxBytes: mediaMaxBytes,
669
+ proxyUrl
670
+ }) : mediaUrl;
671
+ recordAcceptedSend(await sendPhoto(token, {
672
+ chat_id: chatId,
673
+ photo: sendableMediaUrl,
674
+ caption
675
+ }, fetcher));
626
676
  }
627
- },
628
- sendMedia: async ({ mediaUrl, caption }) => {
629
- const sendableMediaUrl = canHostMedia && webhookUrl && webhookPath ? await prepareHostedZaloMediaUrl({
630
- mediaUrl,
631
- webhookUrl,
632
- webhookPath,
633
- maxBytes: mediaMaxBytes,
634
- proxyUrl
635
- }) : mediaUrl;
636
- await sendPhoto(token, {
637
- chat_id: chatId,
638
- photo: sendableMediaUrl,
639
- caption
640
- }, fetcher);
641
- statusSink?.({ lastOutboundAt: Date.now() });
642
- },
643
- onMediaError: (error) => {
644
- runtime.error?.(`Zalo photo send failed: ${error instanceof Error ? error.message : JSON.stringify(error)}`);
645
- }
646
- });
677
+ });
678
+ } catch (error) {
679
+ if (!visibleReplySent) throw error;
680
+ throw createChannelPartialDeliveryError(error, {
681
+ messageIds: acceptedMessageIds,
682
+ receipt: createMessageReceiptFromOutboundResults({
683
+ results: acceptedMessageIds.map((messageId) => ({
684
+ channel: "zalo",
685
+ messageId
686
+ })),
687
+ kind: reply.hasMedia ? "media" : "text"
688
+ }),
689
+ visibleReplySent: true
690
+ });
691
+ }
647
692
  }
648
693
  async function monitorZaloProvider(options) {
649
694
  const { token, account, config, runtime, abortSignal, useWebhook, webhookUrl, webhookSecret, webhookPath, statusSink, fetcher: fetcherOverride } = options;
650
695
  const core = getZaloRuntime();
651
- const effectiveMediaMaxMb = account.config.mediaMaxMb ?? DEFAULT_MEDIA_MAX_MB;
696
+ const configuredMediaMaxMb = account.config.mediaMaxMb;
697
+ const effectiveMediaMaxMb = typeof configuredMediaMaxMb === "number" && configuredMediaMaxMb > 0 ? configuredMediaMaxMb : DEFAULT_MEDIA_MAX_MB;
652
698
  const fetcher = fetcherOverride ?? resolveZaloProxyFetch(account.config.proxy);
653
699
  const mode = useWebhook ? "webhook" : "polling";
654
700
  const effectiveWebhookUrl = normalizeWebhookUrl(webhookUrl ?? account.config.webhookUrl);
@@ -684,7 +730,6 @@ async function monitorZaloProvider(options) {
684
730
  if (hostedMediaRoutePath) {
685
731
  const unregisterHostedMediaRoute = registerSharedHostedMediaRoute({
686
732
  path: hostedMediaRoutePath,
687
- accountId: account.accountId,
688
733
  log: runtime.log
689
734
  });
690
735
  stopHandlers.push(unregisterHostedMediaRoute);
@@ -735,6 +780,7 @@ async function monitorZaloProvider(options) {
735
780
  source: "zalo-webhook",
736
781
  accountId: account.accountId,
737
782
  log: runtime.log,
783
+ throwOnFailure: true,
738
784
  handler: async (req, res) => {
739
785
  if (!await handleZaloWebhookRequest(req, res) && !res.headersSent) {
740
786
  res.statusCode = 404;
@@ -748,6 +794,7 @@ async function monitorZaloProvider(options) {
748
794
  url: effectiveWebhookUrl,
749
795
  secret_token: webhookSecret
750
796
  }, fetcher);
797
+ statusSink?.(channelReadyPatch());
751
798
  let webhookCleanupPromise;
752
799
  cleanupWebhook = async () => {
753
800
  if (!webhookCleanupPromise) webhookCleanupPromise = (async () => {
@@ -800,7 +847,13 @@ async function monitorZaloProvider(options) {
800
847
  });
801
848
  await waitForAbortSignal(abortSignal);
802
849
  } catch (err) {
803
- runtime.error?.(`[${account.accountId}] Zalo provider startup failed mode=${mode}: ${formatZaloError(err)}`);
850
+ const error = formatZaloError(err);
851
+ runtime.error?.(`[${account.accountId}] Zalo provider startup failed mode=${mode}: ${error}`);
852
+ statusSink?.({
853
+ connected: false,
854
+ lifecycle: "recovering",
855
+ lastError: error
856
+ });
804
857
  throw err;
805
858
  } finally {
806
859
  abortSignal.removeEventListener("abort", stopOnAbort);
@@ -1,5 +1,5 @@
1
1
  import { B as registerWebhookTargetWithPluginRoute, G as resolveWebhookTargetWithAuthOrRejectSync, V as resolveClientIp, Z as withResolvedWebhookRequestPipeline, a as WEBHOOK_ANOMALY_COUNTER_DEFAULTS, b as createFixedWindowRateLimiter, l as applyBasicWebhookRequestGuards, o as WEBHOOK_RATE_LIMIT_DEFAULTS, x as createWebhookAnomalyTracker, z as registerWebhookTarget } from "./runtime-api-qxdOyk3M.js";
2
- import { ZaloWebhookPayloadError } from "./webhook-spool-DzCPbb3O.js";
2
+ import { ZaloWebhookPayloadError } from "./webhook-spool-Bf17xwqi.js";
3
3
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
4
4
  import { readWebhookBodyOrReject } from "openclaw/plugin-sdk/webhook-request-guards";
5
5
  //#region extensions/zalo/src/monitor.webhook.ts
@@ -20,9 +20,6 @@ function clearZaloWebhookSecurityStateForTest() {
20
20
  webhookRateLimiter.clear();
21
21
  webhookAnomalyTracker.clear();
22
22
  }
23
- function getZaloWebhookRateLimitStateSizeForTest() {
24
- return webhookRateLimiter.size();
25
- }
26
23
  function getZaloWebhookStatusCounterSizeForTest() {
27
24
  return webhookAnomalyTracker.size();
28
25
  }
@@ -119,7 +116,6 @@ async function handleZaloWebhookRequest(req, res) {
119
116
  }
120
117
  const zaloWebhookRuntime = {
121
118
  clearZaloWebhookSecurityStateForTest,
122
- getZaloWebhookRateLimitStateSizeForTest,
123
119
  getZaloWebhookStatusCounterSizeForTest,
124
120
  handleZaloWebhookRequest,
125
121
  registerZaloWebhookTarget
@@ -1,4 +1,4 @@
1
- import { d as resolveZaloAccount, f as resolveZaloToken } from "./setup-core-LzhuTlsD.js";
1
+ import { d as resolveZaloAccount, f as resolveZaloToken } from "./setup-core-T6qc2eAG.js";
2
2
  import { createMessageReceiptFromOutboundResults } from "openclaw/plugin-sdk/channel-outbound";
3
3
  import { stripChannelTargetPrefix, stripTargetKindPrefix } from "openclaw/plugin-sdk/core";
4
4
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
package/dist/setup-api.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as zaloDmPolicy, r as zaloSetupAdapter, t as createZaloSetupWizardProxy } from "./setup-core-LzhuTlsD.js";
1
+ import { n as zaloDmPolicy, r as zaloSetupAdapter, t as createZaloSetupWizardProxy } from "./setup-core-T6qc2eAG.js";
2
2
  import { n as resolveZaloRuntimeGroupPolicy } from "./group-access-8qHRzDHx.js";
3
3
  import { loadBundledEntryExportSync } from "openclaw/plugin-sdk/channel-entry-contract";
4
4
  //#region extensions/zalo/setup-api.ts
@@ -23,7 +23,7 @@ function createLazyObjectValue(load) {
23
23
  });
24
24
  }
25
25
  function loadSetupSurfaceModule() {
26
- return loadBundledEntryExportSync(import.meta.url, { specifier: "./src/setup-surface.js" });
26
+ return loadBundledEntryExportSync(import.meta.url, { specifier: "./setup-surface.js" });
27
27
  }
28
28
  const zaloSetupWizard = createLazyObjectValue(() => loadSetupSurfaceModule().zaloSetupWizard);
29
29
  //#endregion
@@ -244,7 +244,8 @@ const zaloSetupContract = defineChannelSetupContract({
244
244
  cli: {
245
245
  flags: "--use-env",
246
246
  description: "Use ZALO_BOT_TOKEN"
247
- }
247
+ },
248
+ envVars: ["ZALO_BOT_TOKEN"]
248
249
  }
249
250
  },
250
251
  legacyAdapter: zaloSetupAdapter
@@ -289,4 +290,4 @@ function createZaloSetupWizardProxy(loadWizard) {
289
290
  });
290
291
  }
291
292
  //#endregion
292
- export { noteZaloTokenHelp as a, inspectZaloAccount as c, resolveZaloAccount as d, resolveZaloToken as f, zaloSetupContract as i, listZaloAccountIds as l, normalizeSecretInputString as m, zaloDmPolicy as n, promptZaloAllowFrom as o, buildSecretInputSchema as p, zaloSetupAdapter as r, accounts_exports as s, createZaloSetupWizardProxy as t, resolveDefaultZaloAccountId as u };
293
+ export { noteZaloTokenHelp as a, inspectZaloAccount as c, resolveZaloAccount as d, resolveZaloToken as f, __exportAll as h, zaloSetupContract as i, listZaloAccountIds as l, normalizeSecretInputString as m, zaloDmPolicy as n, promptZaloAllowFrom as o, buildSecretInputSchema as p, zaloSetupAdapter as r, accounts_exports as s, createZaloSetupWizardProxy as t, resolveDefaultZaloAccountId as u };
@@ -1,6 +1,7 @@
1
- import { a as noteZaloTokenHelp, c as inspectZaloAccount, n as zaloDmPolicy, o as promptZaloAllowFrom } from "./setup-core-LzhuTlsD.js";
1
+ import { a as noteZaloTokenHelp, c as inspectZaloAccount, h as __exportAll, n as zaloDmPolicy, o as promptZaloAllowFrom } from "./setup-core-T6qc2eAG.js";
2
2
  import { DEFAULT_ACCOUNT_ID, buildSingleChannelSecretPromptState, createSetupTranslator, createStandardChannelSetupStatus, hasConfiguredSecretInput, promptSingleChannelSecretInput, runSingleChannelSecretStep } from "openclaw/plugin-sdk/setup";
3
3
  //#region extensions/zalo/src/setup-surface.ts
4
+ var setup_surface_exports = /* @__PURE__ */ __exportAll({ zaloSetupWizard: () => zaloSetupWizard });
4
5
  const t = createSetupTranslator();
5
6
  const channel = "zalo";
6
7
  function setZaloUpdateMode(cfg, accountId, mode, webhookUrl, webhookSecret, webhookPath) {
@@ -211,4 +212,4 @@ const zaloSetupWizard = {
211
212
  dmPolicy: zaloDmPolicy
212
213
  };
213
214
  //#endregion
214
- export { zaloSetupWizard };
215
+ export { zaloSetupWizard as n, setup_surface_exports as t };
@@ -0,0 +1,3 @@
1
+ import { r as zaloSetupAdapter } from "./setup-core-T6qc2eAG.js";
2
+ import { n as zaloSetupWizard } from "./setup-surface-edfRk3eu.js";
3
+ export { zaloSetupAdapter, zaloSetupWizard };
@@ -1,8 +1,9 @@
1
1
  import { t as getZaloRuntime } from "./runtime-api-qxdOyk3M.js";
2
- import { r as ZaloApiError } from "./send-BUvbbedq.js";
2
+ import { r as ZaloApiError } from "./send-BGGtv8x_.js";
3
3
  import { DEFAULT_INGRESS_ADOPTION_STALL_MS, DEFAULT_INGRESS_RETRY_MAX_ATTEMPTS, bindIngressLifecycleToReplyOptions, createChannelIngressError, createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
4
4
  import { normalizeNullableString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  import { isRecord } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
6
+ import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
6
7
  import { runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
7
8
  //#region extensions/zalo/src/webhook-spool.ts
8
9
  const ZALO_WEBHOOK_SPOOL_VERSION = 1;
@@ -51,9 +52,6 @@ function parseClaimedUpdate(payload, claimedId) {
51
52
  if (eventName === "message.text.received" && typeof message.text !== "string") throw new ZaloWebhookPayloadError("Zalo text event is missing message.text.");
52
53
  return facts.update;
53
54
  }
54
- function errorText(error) {
55
- return error instanceof Error ? error.message : String(error);
56
- }
57
55
  function isZaloAuthenticationFailure(error) {
58
56
  let current = error;
59
57
  const seen = /* @__PURE__ */ new Set();
@@ -99,14 +97,14 @@ function createZaloWebhookIngress(options) {
99
97
  };
100
98
  if (isZaloAuthenticationFailure(error)) return {
101
99
  reason: "authentication-failed",
102
- message: errorText(error)
100
+ message: formatErrorMessage(error)
103
101
  };
104
102
  return null;
105
103
  },
106
104
  onLog: (message) => options.runtime.error?.(`zalo ingress: ${message}`)
107
105
  },
108
106
  createStoppedError: () => /* @__PURE__ */ new Error("Zalo ingress stopped."),
109
- onError: (error) => options.runtime.error?.(`zalo ingress drain failed: ${errorText(error)}`)
107
+ onError: (error) => options.runtime.error?.(`zalo ingress drain failed: ${formatErrorMessage(error)}`)
110
108
  });
111
109
  return {
112
110
  accept: async (rawEvent) => {
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "id": "zalo",
3
+ "doctorContract": {},
3
4
  "name": "Zalo",
4
5
  "description": "OpenClaw Zalo channel plugin for bot and webhook chats.",
5
6
  "icon": "https://cdn.simpleicons.org/zalo",
@@ -26,6 +27,9 @@
26
27
  "enabled": {
27
28
  "type": "boolean"
28
29
  },
30
+ "configWrites": {
31
+ "type": "boolean"
32
+ },
29
33
  "markdown": {
30
34
  "type": "object",
31
35
  "properties": {
@@ -71,6 +75,29 @@
71
75
  ],
72
76
  "additionalProperties": false
73
77
  },
78
+ {
79
+ "type": "object",
80
+ "properties": {
81
+ "source": {
82
+ "type": "string",
83
+ "const": "store"
84
+ },
85
+ "provider": {
86
+ "type": "string",
87
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
88
+ },
89
+ "id": {
90
+ "type": "string",
91
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
92
+ }
93
+ },
94
+ "required": [
95
+ "source",
96
+ "provider",
97
+ "id"
98
+ ],
99
+ "additionalProperties": false
100
+ },
74
101
  {
75
102
  "type": "object",
76
103
  "properties": {
@@ -155,6 +182,29 @@
155
182
  ],
156
183
  "additionalProperties": false
157
184
  },
185
+ {
186
+ "type": "object",
187
+ "properties": {
188
+ "source": {
189
+ "type": "string",
190
+ "const": "store"
191
+ },
192
+ "provider": {
193
+ "type": "string",
194
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
195
+ },
196
+ "id": {
197
+ "type": "string",
198
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
199
+ }
200
+ },
201
+ "required": [
202
+ "source",
203
+ "provider",
204
+ "id"
205
+ ],
206
+ "additionalProperties": false
207
+ },
158
208
  {
159
209
  "type": "object",
160
210
  "properties": {
@@ -270,6 +320,9 @@
270
320
  "enabled": {
271
321
  "type": "boolean"
272
322
  },
323
+ "configWrites": {
324
+ "type": "boolean"
325
+ },
273
326
  "markdown": {
274
327
  "type": "object",
275
328
  "properties": {
@@ -315,6 +368,29 @@
315
368
  ],
316
369
  "additionalProperties": false
317
370
  },
371
+ {
372
+ "type": "object",
373
+ "properties": {
374
+ "source": {
375
+ "type": "string",
376
+ "const": "store"
377
+ },
378
+ "provider": {
379
+ "type": "string",
380
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
381
+ },
382
+ "id": {
383
+ "type": "string",
384
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
385
+ }
386
+ },
387
+ "required": [
388
+ "source",
389
+ "provider",
390
+ "id"
391
+ ],
392
+ "additionalProperties": false
393
+ },
318
394
  {
319
395
  "type": "object",
320
396
  "properties": {
@@ -399,6 +475,29 @@
399
475
  ],
400
476
  "additionalProperties": false
401
477
  },
478
+ {
479
+ "type": "object",
480
+ "properties": {
481
+ "source": {
482
+ "type": "string",
483
+ "const": "store"
484
+ },
485
+ "provider": {
486
+ "type": "string",
487
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
488
+ },
489
+ "id": {
490
+ "type": "string",
491
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
492
+ }
493
+ },
494
+ "required": [
495
+ "source",
496
+ "provider",
497
+ "id"
498
+ ],
499
+ "additionalProperties": false
500
+ },
402
501
  {
403
502
  "type": "object",
404
503
  "properties": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/zalo",
3
- "version": "2026.7.2-beta.7",
3
+ "version": "2026.8.1-beta.2",
4
4
  "description": "OpenClaw Zalo channel plugin for bot and webhook chats.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "type": "module",
10
10
  "peerDependencies": {
11
- "openclaw": ">=2026.7.2-beta.7"
11
+ "openclaw": ">=2026.8.1-beta.2"
12
12
  },
13
13
  "peerDependenciesMeta": {
14
14
  "openclaw": {
@@ -69,7 +69,10 @@
69
69
  "cli": {
70
70
  "flags": "--use-env",
71
71
  "description": "Use ZALO_BOT_TOKEN"
72
- }
72
+ },
73
+ "envVars": [
74
+ "ZALO_BOT_TOKEN"
75
+ ]
73
76
  }
74
77
  ]
75
78
  }
@@ -80,10 +83,10 @@
80
83
  "minHostVersion": ">=2026.4.10"
81
84
  },
82
85
  "compat": {
83
- "pluginApi": ">=2026.7.2-beta.7"
86
+ "pluginApi": ">=2026.8.1-beta.2"
84
87
  },
85
88
  "build": {
86
- "openclawVersion": "2026.7.2-beta.7"
89
+ "openclawVersion": "2026.8.1-beta.2"
87
90
  },
88
91
  "release": {
89
92
  "publishToClawHub": true,