fix: honor zalo action discovery account config

This commit is contained in:
Tak Hoffman 2026-04-03 11:37:22 -05:00
parent eb497a89cd
commit 7f4dd21227
No known key found for this signature in database
2 changed files with 37 additions and 5 deletions

View File

@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "./runtime-api.js";
import { zaloMessageActions } from "./actions.js";
describe("zaloMessageActions.describeMessageTool", () => {
it("honors the selected Zalo account during discovery", () => {
const cfg: OpenClawConfig = {
channels: {
zalo: {
enabled: true,
botToken: "root-token",
accounts: {
default: {
enabled: false,
botToken: "default-token",
},
work: {
enabled: true,
botToken: "work-token",
},
},
},
},
};
expect(zaloMessageActions.describeMessageTool?.({ cfg, accountId: "default" })).toBeNull();
expect(zaloMessageActions.describeMessageTool?.({ cfg, accountId: "work" })).toEqual({
actions: ["send"],
capabilities: [],
});
});
});

View File

@ -1,5 +1,5 @@
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
import { listEnabledZaloAccounts } from "./accounts.js";
import { listEnabledZaloAccounts, resolveZaloAccount } from "./accounts.js";
import type {
ChannelMessageActionAdapter,
ChannelMessageActionName,
@ -14,15 +14,15 @@ const loadZaloActionsRuntime = createLazyRuntimeNamedExport(
const providerId = "zalo";
function listEnabledAccounts(cfg: OpenClawConfig) {
return listEnabledZaloAccounts(cfg).filter(
function listEnabledAccounts(cfg: OpenClawConfig, accountId?: string | null) {
return (accountId ? [resolveZaloAccount({ cfg, accountId })] : listEnabledZaloAccounts(cfg)).filter(
(account) => account.enabled && account.tokenSource !== "none",
);
}
export const zaloMessageActions: ChannelMessageActionAdapter = {
describeMessageTool: ({ cfg }) => {
const accounts = listEnabledAccounts(cfg);
describeMessageTool: ({ cfg, accountId }) => {
const accounts = listEnabledAccounts(cfg, accountId);
if (accounts.length === 0) {
return null;
}