fix: normalize telegram account token lookup (#5055) (thanks @jasonsschin)
This commit is contained in:
parent
e913de0720
commit
e849df64dc
2 changed files with 8 additions and 6 deletions
|
|
@ -78,6 +78,7 @@ Status: stable.
|
||||||
- Gateway: prevent blank token prompts from storing "undefined". (#4873) Thanks @Hisleren.
|
- Gateway: prevent blank token prompts from storing "undefined". (#4873) Thanks @Hisleren.
|
||||||
- Telegram: use undici fetch for per-account proxy dispatcher. (#4456) Thanks @spiceoogway.
|
- 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: 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: 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: 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.
|
- Telegram: scope native skill commands to bound agent per bot. (#4360) Thanks @robhparker.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
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";
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||||
|
|
||||||
export type TelegramTokenSource = "env" | "tokenFile" | "config" | "none";
|
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
|
// Account IDs are normalized for routing (e.g. lowercased). Config keys may not
|
||||||
// be normalized, so resolve per-account config by matching normalized IDs.
|
// 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;
|
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)
|
// Direct hit (already normalized key)
|
||||||
const direct = (accounts as any)[id];
|
const direct = accounts[id];
|
||||||
if (direct) return direct as any;
|
if (direct) return direct;
|
||||||
// Fallback: match by normalized key
|
// Fallback: match by normalized key
|
||||||
const matchKey = Object.keys(accounts).find((k) => normalizeAccountId(k) === id);
|
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === id);
|
||||||
return matchKey ? ((accounts as any)[matchKey] as any) : undefined;
|
return matchKey ? accounts[matchKey] : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const accountCfg = resolveAccountCfg(
|
const accountCfg = resolveAccountCfg(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue