mirror of https://github.com/openclaw/openclaw.git
fix: honor zalo action discovery account config
This commit is contained in:
parent
eb497a89cd
commit
7f4dd21227
|
|
@ -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: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue