fix: refine bootstrap injections
This commit is contained in:
@@ -1,20 +1,36 @@
|
||||
import chalk from "chalk";
|
||||
import { type ClawdbotConfig, loadConfig } from "../config/config.js";
|
||||
import { resolveTelegramToken } from "../telegram/token.js";
|
||||
import { normalizeE164 } from "../utils.js";
|
||||
import {
|
||||
getWebAuthAgeMs,
|
||||
readWebSelfId,
|
||||
webAuthExists,
|
||||
} from "../web/session.js";
|
||||
|
||||
export type ProviderSummaryOptions = {
|
||||
colorize?: boolean;
|
||||
includeAllowFrom?: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_OPTIONS: Required<ProviderSummaryOptions> = {
|
||||
colorize: false,
|
||||
includeAllowFrom: false,
|
||||
};
|
||||
|
||||
export async function buildProviderSummary(
|
||||
cfg?: ClawdbotConfig,
|
||||
options?: ProviderSummaryOptions,
|
||||
): Promise<string[]> {
|
||||
const effective = cfg ?? loadConfig();
|
||||
const lines: string[] = [];
|
||||
const resolved = { ...DEFAULT_OPTIONS, ...options };
|
||||
const tint = (value: string, color?: (input: string) => string) =>
|
||||
resolved.colorize && color ? color(value) : value;
|
||||
|
||||
const webEnabled = effective.web?.enabled !== false;
|
||||
if (!webEnabled) {
|
||||
lines.push("WhatsApp: disabled");
|
||||
lines.push(tint("WhatsApp: disabled", chalk.cyan));
|
||||
} else {
|
||||
const webLinked = await webAuthExists();
|
||||
const authAgeMs = getWebAuthAgeMs();
|
||||
@@ -22,25 +38,30 @@ export async function buildProviderSummary(
|
||||
const { e164 } = readWebSelfId();
|
||||
lines.push(
|
||||
webLinked
|
||||
? `WhatsApp: linked${e164 ? ` ${e164}` : ""}${authAge}`
|
||||
: "WhatsApp: not linked",
|
||||
? tint(
|
||||
`WhatsApp: linked${e164 ? ` ${e164}` : ""}${authAge}`,
|
||||
chalk.green,
|
||||
)
|
||||
: tint("WhatsApp: not linked", chalk.red),
|
||||
);
|
||||
}
|
||||
|
||||
const telegramEnabled = effective.telegram?.enabled !== false;
|
||||
if (!telegramEnabled) {
|
||||
lines.push("Telegram: disabled");
|
||||
lines.push(tint("Telegram: disabled", chalk.cyan));
|
||||
} else {
|
||||
const { token: telegramToken } = resolveTelegramToken(effective);
|
||||
const telegramConfigured = Boolean(telegramToken?.trim());
|
||||
lines.push(
|
||||
telegramConfigured ? "Telegram: configured" : "Telegram: not configured",
|
||||
telegramConfigured
|
||||
? tint("Telegram: configured", chalk.green)
|
||||
: tint("Telegram: not configured", chalk.cyan),
|
||||
);
|
||||
}
|
||||
|
||||
const signalEnabled = effective.signal?.enabled !== false;
|
||||
if (!signalEnabled) {
|
||||
lines.push("Signal: disabled");
|
||||
lines.push(tint("Signal: disabled", chalk.cyan));
|
||||
} else {
|
||||
const signalConfigured =
|
||||
Boolean(effective.signal) &&
|
||||
@@ -53,20 +74,33 @@ export async function buildProviderSummary(
|
||||
typeof effective.signal?.autoStart === "boolean",
|
||||
);
|
||||
lines.push(
|
||||
signalConfigured ? "Signal: configured" : "Signal: not configured",
|
||||
signalConfigured
|
||||
? tint("Signal: configured", chalk.green)
|
||||
: tint("Signal: not configured", chalk.cyan),
|
||||
);
|
||||
}
|
||||
|
||||
const imessageEnabled = effective.imessage?.enabled !== false;
|
||||
if (!imessageEnabled) {
|
||||
lines.push("iMessage: disabled");
|
||||
lines.push(tint("iMessage: disabled", chalk.cyan));
|
||||
} else {
|
||||
const imessageConfigured = Boolean(effective.imessage);
|
||||
lines.push(
|
||||
imessageConfigured ? "iMessage: configured" : "iMessage: not configured",
|
||||
imessageConfigured
|
||||
? tint("iMessage: configured", chalk.green)
|
||||
: tint("iMessage: not configured", chalk.cyan),
|
||||
);
|
||||
}
|
||||
|
||||
if (resolved.includeAllowFrom) {
|
||||
const allowFrom = effective.whatsapp?.allowFrom?.length
|
||||
? effective.whatsapp.allowFrom.map(normalizeE164).filter(Boolean)
|
||||
: [];
|
||||
if (allowFrom.length) {
|
||||
lines.push(tint(`AllowFrom: ${allowFrom.join(", ")}`, chalk.cyan));
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user