← Back to PRs

#14359: fix: prefer named Telegram account over orphan 'default' in binding resolution

by itsGustav open 2026-02-12 00:53 View on GitHub →
channel: telegram stale
## Summary Fixes #14354 When a user adds a named Telegram account (e.g. via `openclaw channels add telegram --account mybot`), the top-level `telegram.botToken` still creates an implicit `"default"` account entry. `resolveDefaultTelegramAccountId()` unconditionally preferred `"default"` when it existed in the account list, causing agent bindings to silently target the orphan default account instead of the intended named account. ## Changes **`src/telegram/accounts.ts`** — `resolveDefaultTelegramAccountId()`: - When `"default"` coexists with explicitly named accounts, prefer the first named account - When `"default"` is the only account, behavior is unchanged **`src/telegram/accounts.test.ts`**: - Added test: prefers named account over default when both exist - Added test: returns default when it is the only account ## How to reproduce (before fix) 1. Set up Telegram with a bot token (creates implicit `default` account) 2. Add a named account: `openclaw channels add telegram --account mybot --token <token>` 3. Add an agent with channel binding 4. Observe: binding targets `accountId: "default"` instead of `"mybot"` ## Test results All 6 tests pass (4 existing + 2 new): ``` ✓ falls back to the first configured account when accountId is omitted ✓ uses TELEGRAM_BOT_TOKEN when default account config is missing ✓ prefers default config token over TELEGRAM_BOT_TOKEN ✓ prefers named account over default when both exist (NEW) ✓ returns default when it is the only account (NEW) ✓ does not fall back when accountId is explicitly provided ``` <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates Telegram account default-resolution so that when an implicit `default` account (often created via top-level `channels.telegram.botToken`) coexists with explicitly named accounts, bindings prefer a named account instead of silently targeting the orphan `default`. It keeps the old behavior when `default` is the only available account. Changes are localized to `src/telegram/accounts.ts` (`resolveDefaultTelegramAccountId`) and new Vitest coverage in `src/telegram/accounts.test.ts` for both the coexistence and single-account cases. The logic integrates with existing binding defaults via `resolveDefaultAgentBoundAccountId` and the account ID list provided by `listTelegramAccountIds`. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk. - Change is small and well-scoped: it only affects default account ID selection when both an implicit `default` and at least one named Telegram account exist, and it preserves existing behavior when `default` is the only account. Added tests cover both new branches, and no other codepaths are modified. - No files require special attention <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs