refactor: unify onboarding secret-input prompt state wiring

This commit is contained in:
Peter Steinberger
2026-03-07 21:44:58 +00:00
parent 6b1c82c4f1
commit 5eba663c38
15 changed files with 172 additions and 60 deletions

View File

@@ -6,6 +6,7 @@ import type {
WizardPrompter,
} from "openclaw/plugin-sdk/zalo";
import {
buildSingleChannelSecretPromptState,
DEFAULT_ACCOUNT_ID,
hasConfiguredSecretInput,
mergeAllowFromEntries,
@@ -251,10 +252,15 @@ export const zaloOnboardingAdapter: ChannelOnboardingAdapter = {
});
const accountConfigured = Boolean(resolvedAccount.token);
const allowEnv = zaloAccountId === DEFAULT_ACCOUNT_ID;
const canUseEnv = allowEnv && Boolean(process.env.ZALO_BOT_TOKEN?.trim());
const hasConfigToken = Boolean(
hasConfiguredSecretInput(resolvedAccount.config.botToken) || resolvedAccount.config.tokenFile,
);
const tokenPromptState = buildSingleChannelSecretPromptState({
accountConfigured,
hasConfigToken,
allowEnv,
envValue: process.env.ZALO_BOT_TOKEN,
});
let token: SecretInput | null = null;
if (!accountConfigured) {
@@ -265,9 +271,9 @@ export const zaloOnboardingAdapter: ChannelOnboardingAdapter = {
prompter,
providerHint: "zalo",
credentialLabel: "bot token",
accountConfigured,
canUseEnv: canUseEnv && !hasConfigToken,
hasConfigToken,
accountConfigured: tokenPromptState.accountConfigured,
canUseEnv: tokenPromptState.canUseEnv,
hasConfigToken: tokenPromptState.hasConfigToken,
envPrompt: "ZALO_BOT_TOKEN detected. Use env var?",
keepPrompt: "Zalo token already configured. Keep it?",
inputPrompt: "Enter Zalo bot token",
@@ -349,9 +355,11 @@ export const zaloOnboardingAdapter: ChannelOnboardingAdapter = {
prompter,
providerHint: "zalo-webhook",
credentialLabel: "webhook secret",
accountConfigured: hasConfiguredSecretInput(resolvedAccount.config.webhookSecret),
canUseEnv: false,
hasConfigToken: hasConfiguredSecretInput(resolvedAccount.config.webhookSecret),
...buildSingleChannelSecretPromptState({
accountConfigured: hasConfiguredSecretInput(resolvedAccount.config.webhookSecret),
hasConfigToken: hasConfiguredSecretInput(resolvedAccount.config.webhookSecret),
allowEnv: false,
}),
envPrompt: "",
keepPrompt: "Zalo webhook secret already configured. Keep it?",
inputPrompt: "Webhook secret (8-256 chars)",
@@ -368,9 +376,11 @@ export const zaloOnboardingAdapter: ChannelOnboardingAdapter = {
prompter,
providerHint: "zalo-webhook",
credentialLabel: "webhook secret",
accountConfigured: false,
canUseEnv: false,
hasConfigToken: false,
...buildSingleChannelSecretPromptState({
accountConfigured: false,
hasConfigToken: false,
allowEnv: false,
}),
envPrompt: "",
keepPrompt: "Zalo webhook secret already configured. Keep it?",
inputPrompt: "Webhook secret (8-256 chars)",