#8694: Fix Telegram routing when token override omits accountId
channel: telegram
stale
## Summary
- Infer Telegram accountId from the token when monitorTelegramProvider is called with a token override and no accountId.
- Add a unit test covering the missing-accountId token override scenario.
## Testing
- pnpm exec vitest src/telegram/monitor.test.ts
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `monitorTelegramProvider` to infer a missing `accountId` by scanning configured Telegram accounts and matching the provided token override to each account’s resolved token, then adds a unit test asserting that `createTelegramBot` receives the inferred `accountId`.
The change fits into the existing account-selection flow in `src/telegram/accounts.ts`, which already has a default/fallback resolution strategy when `accountId` is omitted; this PR adds a more direct routing step when the caller supplies a token override.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, with a small correctness gap around default-token sources during token→account matching.
- Changes are localized and covered by a focused unit test; main remaining concern is that accountId inference may not consider default/env/base token sources if `default` isn’t included in the scanned IDs, leading to fallback routing in some configurations.
- src/telegram/monitor.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
81.7%
#14359: fix: prefer named Telegram account over orphan 'default' in binding...
by itsGustav · 2026-02-12
80.8%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
80.8%
#11347: fix: scope Telegram update offset to bot token
by anooprdawar · 2026-02-07
80.5%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
79.4%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
77.7%
#22363: fix(telegram): isolate update offset state by bot token
by AIflow-Labs · 2026-02-21
76.8%
#9437: fix: normalize accountId in binding matching for consistent routing
by dbottme · 2026-02-05
76.5%
#3186: fix(telegram): sanitize update offset + lock polling
by daxiong888 · 2026-01-28
76.4%
#6463: fix(telegram): improve timeout handling and prevent channel exits
by ai-fanatic · 2026-02-01
76.2%