* Extensions: fix oxfmt drift on main * Plugins: restore runtime barrel exports on main * Config: restore web search compatibility types * Telegram: align test harness with reply runtime * Plugin SDK: fix channel config accessor generics * CLI: remove redundant search provider casts * Tests: restore main typecheck coverage * Lobster: fix test import formatting * Extensions: route bundled seams through plugin-sdk * Tests: use extension env helper for xai * Image generation: fix main oxfmt drift * Config: restore latest main compatibility checks * Plugin SDK: align guardrail tests with lint * Telegram: type native command skill mock
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
|
import { listEnabledZaloAccounts } from "./accounts.js";
|
|
import type {
|
|
ChannelMessageActionAdapter,
|
|
ChannelMessageActionName,
|
|
OpenClawConfig,
|
|
} from "./runtime-api.js";
|
|
import { extractToolSend, jsonResult, readStringParam } from "./runtime-api.js";
|
|
|
|
const loadZaloActionsRuntime = createLazyRuntimeNamedExport(
|
|
() => import("./actions.runtime.js"),
|
|
"zaloActionsRuntime",
|
|
);
|
|
|
|
const providerId = "zalo";
|
|
|
|
function listEnabledAccounts(cfg: OpenClawConfig) {
|
|
return listEnabledZaloAccounts(cfg).filter(
|
|
(account) => account.enabled && account.tokenSource !== "none",
|
|
);
|
|
}
|
|
|
|
export const zaloMessageActions: ChannelMessageActionAdapter = {
|
|
describeMessageTool: ({ cfg }) => {
|
|
const accounts = listEnabledAccounts(cfg);
|
|
if (accounts.length === 0) {
|
|
return null;
|
|
}
|
|
const actions = new Set<ChannelMessageActionName>(["send"]);
|
|
return { actions: Array.from(actions), capabilities: [] };
|
|
},
|
|
extractToolSend: ({ args }) => extractToolSend(args, "sendMessage"),
|
|
handleAction: async ({ action, params, cfg, accountId }) => {
|
|
if (action === "send") {
|
|
const to = readStringParam(params, "to", { required: true });
|
|
const content = readStringParam(params, "message", {
|
|
required: true,
|
|
allowEmpty: true,
|
|
});
|
|
const mediaUrl = readStringParam(params, "media", { trim: false });
|
|
|
|
const { sendMessageZalo } = await loadZaloActionsRuntime();
|
|
const result = await sendMessageZalo(to ?? "", content ?? "", {
|
|
accountId: accountId ?? undefined,
|
|
mediaUrl: mediaUrl ?? undefined,
|
|
cfg: cfg,
|
|
});
|
|
|
|
if (!result.ok) {
|
|
return jsonResult({
|
|
ok: false,
|
|
error: result.error ?? "Failed to send Zalo message",
|
|
});
|
|
}
|
|
|
|
return jsonResult({ ok: true, to, messageId: result.messageId });
|
|
}
|
|
|
|
throw new Error(`Action ${action} is not supported for provider ${providerId}.`);
|
|
},
|
|
};
|