#14359: fix: prefer named Telegram account over orphan 'default' in binding resolution
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
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
85.1%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
84.5%
#11347: fix: scope Telegram update offset to bot token
by anooprdawar · 2026-02-07
82.9%
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
82.0%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
81.7%
#8694: Fix Telegram routing when token override omits accountId
by codvik · 2026-02-04
80.8%
#15727: fix(routing): resolve channel default account instead of hardcoded ...
by FuseWeb · 2026-02-13
79.3%
#9437: fix: normalize accountId in binding matching for consistent routing
by dbottme · 2026-02-05
79.3%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
78.0%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
77.7%