fix(gateway): gate providers by config presence
This commit is contained in:
@@ -301,7 +301,15 @@ export async function setupProviders(
|
|||||||
}),
|
}),
|
||||||
runtime,
|
runtime,
|
||||||
);
|
);
|
||||||
if (!keepEnv) {
|
if (keepEnv) {
|
||||||
|
next = {
|
||||||
|
...next,
|
||||||
|
telegram: {
|
||||||
|
...next.telegram,
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
token = String(
|
token = String(
|
||||||
guardCancel(
|
guardCancel(
|
||||||
await text({
|
await text({
|
||||||
@@ -368,7 +376,15 @@ export async function setupProviders(
|
|||||||
}),
|
}),
|
||||||
runtime,
|
runtime,
|
||||||
);
|
);
|
||||||
if (!keepEnv) {
|
if (keepEnv) {
|
||||||
|
next = {
|
||||||
|
...next,
|
||||||
|
discord: {
|
||||||
|
...next.discord,
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
token = String(
|
token = String(
|
||||||
guardCancel(
|
guardCancel(
|
||||||
await text({
|
await text({
|
||||||
|
|||||||
@@ -2074,6 +2074,15 @@ export async function startGatewayServer(
|
|||||||
const startTelegramProvider = async () => {
|
const startTelegramProvider = async () => {
|
||||||
if (telegramTask) return;
|
if (telegramTask) return;
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
if (!cfg.telegram) {
|
||||||
|
telegramRuntime = {
|
||||||
|
...telegramRuntime,
|
||||||
|
running: false,
|
||||||
|
lastError: "not configured",
|
||||||
|
};
|
||||||
|
logTelegram.info("skipping provider start (telegram not configured)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (cfg.telegram?.enabled === false) {
|
if (cfg.telegram?.enabled === false) {
|
||||||
telegramRuntime = {
|
telegramRuntime = {
|
||||||
...telegramRuntime,
|
...telegramRuntime,
|
||||||
@@ -2168,6 +2177,15 @@ export async function startGatewayServer(
|
|||||||
const startDiscordProvider = async () => {
|
const startDiscordProvider = async () => {
|
||||||
if (discordTask) return;
|
if (discordTask) return;
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
if (!cfg.discord) {
|
||||||
|
discordRuntime = {
|
||||||
|
...discordRuntime,
|
||||||
|
running: false,
|
||||||
|
lastError: "not configured",
|
||||||
|
};
|
||||||
|
logDiscord.info("skipping provider start (discord not configured)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (cfg.discord?.enabled === false) {
|
if (cfg.discord?.enabled === false) {
|
||||||
discordRuntime = {
|
discordRuntime = {
|
||||||
...discordRuntime,
|
...discordRuntime,
|
||||||
@@ -2270,6 +2288,26 @@ export async function startGatewayServer(
|
|||||||
logSignal.info("skipping provider start (signal.enabled=false)");
|
logSignal.info("skipping provider start (signal.enabled=false)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const signalCfg = cfg.signal;
|
||||||
|
const signalMeaningfullyConfigured = Boolean(
|
||||||
|
signalCfg.account?.trim() ||
|
||||||
|
signalCfg.httpUrl?.trim() ||
|
||||||
|
signalCfg.cliPath?.trim() ||
|
||||||
|
signalCfg.httpHost?.trim() ||
|
||||||
|
typeof signalCfg.httpPort === "number" ||
|
||||||
|
typeof signalCfg.autoStart === "boolean",
|
||||||
|
);
|
||||||
|
if (!signalMeaningfullyConfigured) {
|
||||||
|
signalRuntime = {
|
||||||
|
...signalRuntime,
|
||||||
|
running: false,
|
||||||
|
lastError: "not configured",
|
||||||
|
};
|
||||||
|
logSignal.info(
|
||||||
|
"skipping provider start (signal config present but missing required fields)",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const host = cfg.signal?.httpHost?.trim() || "127.0.0.1";
|
const host = cfg.signal?.httpHost?.trim() || "127.0.0.1";
|
||||||
const port = cfg.signal?.httpPort ?? 8080;
|
const port = cfg.signal?.httpPort ?? 8080;
|
||||||
const baseUrl = cfg.signal?.httpUrl?.trim() || `http://${host}:${port}`;
|
const baseUrl = cfg.signal?.httpUrl?.trim() || `http://${host}:${port}`;
|
||||||
@@ -4345,21 +4383,33 @@ export async function startGatewayServer(
|
|||||||
? Math.max(1000, timeoutMsRaw)
|
? Math.max(1000, timeoutMsRaw)
|
||||||
: 10_000;
|
: 10_000;
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
const telegramCfg = cfg.telegram;
|
||||||
|
const telegramEnabled =
|
||||||
|
Boolean(telegramCfg) && telegramCfg?.enabled !== false;
|
||||||
const { token: telegramToken, source: tokenSource } =
|
const { token: telegramToken, source: tokenSource } =
|
||||||
resolveTelegramToken(cfg);
|
telegramEnabled
|
||||||
|
? resolveTelegramToken(cfg)
|
||||||
|
: { token: "", source: "none" as const };
|
||||||
let telegramProbe: TelegramProbe | undefined;
|
let telegramProbe: TelegramProbe | undefined;
|
||||||
let lastProbeAt: number | null = null;
|
let lastProbeAt: number | null = null;
|
||||||
if (probe && telegramToken) {
|
if (probe && telegramToken && telegramEnabled) {
|
||||||
telegramProbe = await probeTelegram(
|
telegramProbe = await probeTelegram(
|
||||||
telegramToken,
|
telegramToken,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
cfg.telegram?.proxy,
|
telegramCfg?.proxy,
|
||||||
);
|
);
|
||||||
lastProbeAt = Date.now();
|
lastProbeAt = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
const discordEnvToken = process.env.DISCORD_BOT_TOKEN?.trim();
|
const discordCfg = cfg.discord;
|
||||||
const discordConfigToken = cfg.discord?.token?.trim();
|
const discordEnabled =
|
||||||
|
Boolean(discordCfg) && discordCfg?.enabled !== false;
|
||||||
|
const discordEnvToken = discordEnabled
|
||||||
|
? process.env.DISCORD_BOT_TOKEN?.trim()
|
||||||
|
: "";
|
||||||
|
const discordConfigToken = discordEnabled
|
||||||
|
? discordCfg?.token?.trim()
|
||||||
|
: "";
|
||||||
const discordToken = discordEnvToken || discordConfigToken || "";
|
const discordToken = discordEnvToken || discordConfigToken || "";
|
||||||
const discordTokenSource = discordEnvToken
|
const discordTokenSource = discordEnvToken
|
||||||
? "env"
|
? "env"
|
||||||
@@ -4368,7 +4418,7 @@ export async function startGatewayServer(
|
|||||||
: "none";
|
: "none";
|
||||||
let discordProbe: DiscordProbe | undefined;
|
let discordProbe: DiscordProbe | undefined;
|
||||||
let discordLastProbeAt: number | null = null;
|
let discordLastProbeAt: number | null = null;
|
||||||
if (probe && discordToken) {
|
if (probe && discordToken && discordEnabled) {
|
||||||
discordProbe = await probeDiscord(discordToken, timeoutMs);
|
discordProbe = await probeDiscord(discordToken, timeoutMs);
|
||||||
discordLastProbeAt = Date.now();
|
discordLastProbeAt = Date.now();
|
||||||
}
|
}
|
||||||
@@ -4380,7 +4430,17 @@ export async function startGatewayServer(
|
|||||||
const signalBaseUrl =
|
const signalBaseUrl =
|
||||||
signalCfg?.httpUrl?.trim() ||
|
signalCfg?.httpUrl?.trim() ||
|
||||||
`http://${signalHost}:${signalPort}`;
|
`http://${signalHost}:${signalPort}`;
|
||||||
const signalConfigured = Boolean(signalCfg) && signalEnabled;
|
const signalConfigured =
|
||||||
|
Boolean(signalCfg) &&
|
||||||
|
signalEnabled &&
|
||||||
|
Boolean(
|
||||||
|
signalCfg?.account?.trim() ||
|
||||||
|
signalCfg?.httpUrl?.trim() ||
|
||||||
|
signalCfg?.cliPath?.trim() ||
|
||||||
|
signalCfg?.httpHost?.trim() ||
|
||||||
|
typeof signalCfg?.httpPort === "number" ||
|
||||||
|
typeof signalCfg?.autoStart === "boolean",
|
||||||
|
);
|
||||||
let signalProbe: SignalProbe | undefined;
|
let signalProbe: SignalProbe | undefined;
|
||||||
let signalLastProbeAt: number | null = null;
|
let signalLastProbeAt: number | null = null;
|
||||||
if (probe && signalConfigured) {
|
if (probe && signalConfigured) {
|
||||||
@@ -4422,7 +4482,7 @@ export async function startGatewayServer(
|
|||||||
lastError: whatsappRuntime.lastError ?? null,
|
lastError: whatsappRuntime.lastError ?? null,
|
||||||
},
|
},
|
||||||
telegram: {
|
telegram: {
|
||||||
configured: Boolean(telegramToken),
|
configured: telegramEnabled && Boolean(telegramToken),
|
||||||
tokenSource,
|
tokenSource,
|
||||||
running: telegramRuntime.running,
|
running: telegramRuntime.running,
|
||||||
mode: telegramRuntime.mode ?? null,
|
mode: telegramRuntime.mode ?? null,
|
||||||
@@ -4433,7 +4493,7 @@ export async function startGatewayServer(
|
|||||||
lastProbeAt,
|
lastProbeAt,
|
||||||
},
|
},
|
||||||
discord: {
|
discord: {
|
||||||
configured: Boolean(discordToken),
|
configured: discordEnabled && Boolean(discordToken),
|
||||||
tokenSource: discordTokenSource,
|
tokenSource: discordTokenSource,
|
||||||
running: discordRuntime.running,
|
running: discordRuntime.running,
|
||||||
lastStartAt: discordRuntime.lastStartAt ?? null,
|
lastStartAt: discordRuntime.lastStartAt ?? null,
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ export async function buildProviderSummary(
|
|||||||
if (!telegramEnabled) {
|
if (!telegramEnabled) {
|
||||||
lines.push(chalk.cyan("Telegram: disabled"));
|
lines.push(chalk.cyan("Telegram: disabled"));
|
||||||
} else {
|
} else {
|
||||||
const { token: telegramToken } = resolveTelegramToken(effective);
|
const { token: telegramToken } = effective.telegram
|
||||||
const telegramConfigured = Boolean(telegramToken);
|
? resolveTelegramToken(effective)
|
||||||
|
: { token: "" };
|
||||||
|
const telegramConfigured =
|
||||||
|
Boolean(effective.telegram) && Boolean(telegramToken);
|
||||||
lines.push(
|
lines.push(
|
||||||
telegramConfigured
|
telegramConfigured
|
||||||
? chalk.green("Telegram: configured")
|
? chalk.green("Telegram: configured")
|
||||||
@@ -48,11 +51,16 @@ export async function buildProviderSummary(
|
|||||||
if (!signalEnabled) {
|
if (!signalEnabled) {
|
||||||
lines.push(chalk.cyan("Signal: disabled"));
|
lines.push(chalk.cyan("Signal: disabled"));
|
||||||
} else {
|
} else {
|
||||||
const signalConfigured = Boolean(
|
const signalConfigured =
|
||||||
effective.signal?.httpUrl ||
|
Boolean(effective.signal) &&
|
||||||
effective.signal?.cliPath ||
|
Boolean(
|
||||||
effective.signal?.account,
|
effective.signal?.account?.trim() ||
|
||||||
);
|
effective.signal?.httpUrl?.trim() ||
|
||||||
|
effective.signal?.cliPath?.trim() ||
|
||||||
|
effective.signal?.httpHost?.trim() ||
|
||||||
|
typeof effective.signal?.httpPort === "number" ||
|
||||||
|
typeof effective.signal?.autoStart === "boolean",
|
||||||
|
);
|
||||||
lines.push(
|
lines.push(
|
||||||
signalConfigured
|
signalConfigured
|
||||||
? chalk.green("Signal: configured")
|
? chalk.green("Signal: configured")
|
||||||
|
|||||||
Reference in New Issue
Block a user