From e849df64dcce9721844cc1f92fcd427ead210c31 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Sat, 31 Jan 2026 08:54:40 +0530 Subject: [PATCH] fix: normalize telegram account token lookup (#5055) (thanks @jasonsschin) --- CHANGELOG.md | 1 + src/telegram/token.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73f7d39470..79164fbec0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Status: stable. - Gateway: prevent blank token prompts from storing "undefined". (#4873) Thanks @Hisleren. - Telegram: use undici fetch for per-account proxy dispatcher. (#4456) Thanks @spiceoogway. - Telegram: fix HTML nesting for overlapping styles and links. (#4578) Thanks @ThanhNguyxn. +- Telegram: resolve per-account bot token configs with normalized account IDs. (#5055) Thanks @jasonsschin. - Telegram: avoid silent empty replies by tracking normalization skips before fallback. (#3796) - Telegram: accept numeric messageId/chatId in react action and honor channelId fallback. (#4533) Thanks @Ayush10. - Telegram: scope native skill commands to bound agent per bot. (#4360) Thanks @robhparker. diff --git a/src/telegram/token.ts b/src/telegram/token.ts index fe3b7bc366..64c0868209 100644 --- a/src/telegram/token.ts +++ b/src/telegram/token.ts @@ -1,6 +1,7 @@ import fs from "node:fs"; import type { OpenClawConfig } from "../config/config.js"; +import type { TelegramAccountConfig } from "../config/types.telegram.js"; import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js"; export type TelegramTokenSource = "env" | "tokenFile" | "config" | "none"; @@ -25,15 +26,15 @@ export function resolveTelegramToken( // Account IDs are normalized for routing (e.g. lowercased). Config keys may not // be normalized, so resolve per-account config by matching normalized IDs. - const resolveAccountCfg = (id: string) => { + const resolveAccountCfg = (id: string): TelegramAccountConfig | undefined => { const accounts = telegramCfg?.accounts; - if (!accounts || typeof accounts !== "object") return undefined; + if (!accounts || typeof accounts !== "object" || Array.isArray(accounts)) return undefined; // Direct hit (already normalized key) - const direct = (accounts as any)[id]; - if (direct) return direct as any; + const direct = accounts[id]; + if (direct) return direct; // Fallback: match by normalized key - const matchKey = Object.keys(accounts).find((k) => normalizeAccountId(k) === id); - return matchKey ? ((accounts as any)[matchKey] as any) : undefined; + const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === id); + return matchKey ? accounts[matchKey] : undefined; }; const accountCfg = resolveAccountCfg(