mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
99d662473c
* fix(channels): validate headless channel setup * docs(channels): document headless provisioning * fix(channels): repair setup metadata typing * chore(channels): regenerate official channel catalog for env metadata * fix(slack): keep mode-conditional env contract plugin-owned Static --use-env declaration keeps only the unconditional SLACK_BOT_TOKEN; socket-vs-HTTP conditional requirements (app token, signing secret) stay in Slack's own setup validation so HTTP mode no longer demands an irrelevant SLACK_APP_TOKEN. * chore(sdk): regenerate api baselines and catalog after rebase * fix(slack): align manifest env declaration with runtime contract * chore(sdk): regenerate api baselines after rebase * chore(sdk): regenerate api baselines after rebase * chore(sdk): regenerate api baselines after rebase
107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
import { createChannelDmPolicy } from "openclaw/plugin-sdk/channel-dm-policy";
|
|
import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
|
|
// Zalo plugin module implements setup core behavior.
|
|
import {
|
|
createDelegatedSetupWizardProxy,
|
|
createPatchedAccountSetupAdapter,
|
|
createSetupInputPresenceValidator,
|
|
DEFAULT_ACCOUNT_ID,
|
|
normalizeAccountId,
|
|
patchScopedAccountConfig,
|
|
createSetupTranslator,
|
|
setSetupChannelEnabled,
|
|
type ChannelSetupWizard,
|
|
} from "openclaw/plugin-sdk/setup";
|
|
import { resolveDefaultZaloAccountId, resolveZaloAccount } from "./accounts.js";
|
|
import { promptZaloAllowFrom } from "./setup-allow-from.js";
|
|
|
|
const t = createSetupTranslator();
|
|
|
|
const channel = "zalo" as const;
|
|
|
|
export const zaloSetupAdapter = {
|
|
...createPatchedAccountSetupAdapter({
|
|
channelKey: channel,
|
|
validateInput: createSetupInputPresenceValidator({
|
|
defaultAccountOnlyEnvError: "ZALO_BOT_TOKEN can only be used for the default account.",
|
|
whenNotUseEnv: [
|
|
{
|
|
someOf: ["token", "tokenFile"],
|
|
message: "Zalo requires token or --token-file (or --use-env).",
|
|
},
|
|
],
|
|
}),
|
|
buildPatch: (input) =>
|
|
input.useEnv
|
|
? {}
|
|
: input.tokenFile
|
|
? { tokenFile: input.tokenFile }
|
|
: input.token
|
|
? { botToken: input.token }
|
|
: {},
|
|
}),
|
|
singleAccountKeysToMove: ["webhookSecret", "tokenFile"],
|
|
};
|
|
|
|
export const zaloSetupContract = defineChannelSetupContract({
|
|
fields: {
|
|
token: {
|
|
kind: "string",
|
|
sensitive: true,
|
|
cli: { flags: "--token <token>", description: "Zalo bot token" },
|
|
},
|
|
tokenFile: {
|
|
kind: "string",
|
|
sensitive: true,
|
|
cli: { flags: "--token-file <path>", description: "Zalo bot token file" },
|
|
},
|
|
useEnv: {
|
|
kind: "boolean",
|
|
cli: { flags: "--use-env", description: "Use ZALO_BOT_TOKEN" },
|
|
envVars: ["ZALO_BOT_TOKEN"],
|
|
},
|
|
},
|
|
legacyAdapter: zaloSetupAdapter,
|
|
});
|
|
|
|
export const zaloDmPolicy = createChannelDmPolicy({
|
|
label: "Zalo",
|
|
channel,
|
|
resolveAccount: (cfg, accountId) => {
|
|
const resolvedAccountId =
|
|
accountId && normalizeAccountId(accountId)
|
|
? (normalizeAccountId(accountId) ?? DEFAULT_ACCOUNT_ID)
|
|
: resolveDefaultZaloAccountId(cfg);
|
|
return resolveZaloAccount({ cfg, accountId: resolvedAccountId });
|
|
},
|
|
applyPatch: ({ cfg, account, patch }) =>
|
|
patchScopedAccountConfig({ cfg, channelKey: channel, accountId: account.accountId, patch }),
|
|
promptAllowFrom: async ({ cfg, prompter, accountId }) =>
|
|
promptZaloAllowFrom({
|
|
cfg,
|
|
prompter,
|
|
accountId: accountId ?? resolveDefaultZaloAccountId(cfg),
|
|
}),
|
|
});
|
|
|
|
export function createZaloSetupWizardProxy(
|
|
loadWizard: () => Promise<ChannelSetupWizard>,
|
|
): ChannelSetupWizard {
|
|
return createDelegatedSetupWizardProxy({
|
|
channel,
|
|
loadWizard,
|
|
status: {
|
|
configuredLabel: t("wizard.channels.statusConfigured"),
|
|
unconfiguredLabel: t("wizard.channels.statusNeedsToken"),
|
|
configuredHint: t("wizard.channels.statusRecommendedConfigured"),
|
|
unconfiguredHint: t("wizard.channels.statusRecommendedNewcomerFriendly"),
|
|
configuredScore: 1,
|
|
unconfiguredScore: 10,
|
|
},
|
|
credentials: [],
|
|
delegateFinalize: true,
|
|
dmPolicy: zaloDmPolicy,
|
|
disable: (cfg) => setSetupChannelEnabled(cfg, channel, false),
|
|
});
|
|
}
|