#6084: Add dynamic Telegram agent routing for DM and groups
channel: telegram
## Summary
- add dynamic Telegram agent routing for DM and groups via config
- create per-user/per-group agent and workspace IDs
- extend Telegram message context to use dynamic agent session keys
- add coverage for dynamic agent routing in tests
## Config
- new key: channels.telegram.dynamicAgents = off|dm|group|dm+group
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new Telegram config knob (`channels.telegram.dynamicAgents`) to route inbound Telegram messages to dynamically generated per-user (DM) and/or per-group agents, and extends Telegram message context/session key generation accordingly. It also updates UI schema hints and adds tests covering the new routing behavior.
Key integration points are `buildTelegramMessageContext` (now accepts a merged `telegramCfg` and may bypass `resolveAgentRoute` when dynamic routing is enabled) and the Telegram message processor which passes the merged Telegram config through to context building.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge, but the dynamic-routing path duplicates session-key construction and may drift from the canonical router behavior.
- Most changes are additive and covered by tests, but the dynamic route constructs `sessionKey`/`mainSessionKey` manually and hardcodes `matchedBy`, which can cause subtle behavior divergence from `resolveAgentRoute` over time. Minor schema/default and comment-language consistency issues remain.
- src/telegram/bot-message-context.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#7058: feat(telegram): add channel_post handler for broadcast channels
by waifu7498173 · 2026-02-02
80.7%
#9051: fix(sessions): respect dmScope config in CLI agent commands
by benleavett · 2026-02-04
78.5%
#7224: feat(telegram): inherit forum topic bindings from parent group
by Buywatermelon · 2026-02-02
77.2%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
77.0%
#6457: fix(telegram): register commands for group scope + preserve topic t...
by dae-sun · 2026-02-01
76.7%
#7751: Telegram: persist inbound history (SQLite) + add read action
by welttowelt · 2026-02-03
76.2%
#15975: feat(telegram): add Business Mode for personal chat access
by scomma · 2026-02-14
76.1%
#6192: Telegram: fix DM Topics thread routing
by ViffyGwaanl · 2026-02-01
76.0%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
75.4%
#14367: feat(telegram): add message read via inbound message store
by michaelquinlan88 · 2026-02-12
75.3%