fix(telegram): guard token.trim() against undefined to prevent startup crash

When account.token is undefined (e.g. missing botToken config),
calling .trim() directly throws "Cannot read properties of undefined".
Use nullish coalescing to fall back to empty string before trimming.

Closes #31944
This commit is contained in:
ningding97 2026-03-03 01:31:45 +08:00 committed by Peter Steinberger
parent d21cf44452
commit c1c20491da
1 changed files with 2 additions and 2 deletions

View File

@ -44,7 +44,7 @@ function findTelegramTokenOwnerAccountId(params: {
const tokenOwners = new Map<string, string>();
for (const id of listTelegramAccountIds(params.cfg)) {
const account = resolveTelegramAccount({ cfg: params.cfg, accountId: id });
const token = account.token.trim();
const token = (account.token ?? "").trim();
if (!token) {
continue;
}
@ -465,7 +465,7 @@ export const telegramPlugin: ChannelPlugin<ResolvedTelegramAccount, TelegramProb
ctx.log?.error?.(`[${account.accountId}] ${reason}`);
throw new Error(reason);
}
const token = account.token.trim();
const token = (account.token ?? "").trim();
let telegramBotLabel = "";
try {
const probe = await getTelegramRuntime().channel.telegram.probeTelegram(