telegram group messages routing to webchat, not telegram

Issue Summary (After Full Investigation)
Observed Problem
- User messages Clawdbot via Telegram group/forum topic
- Clawdbot replies are going to webchat instead of back to the Telegram group
- This happens specifically for Telegram group messages (not DMs)
Root Cause Analysis
Confirmed: Session state metadata is not properly tracked for group sessions
In src/telegram/bot.ts (around line 795), the updateLastRoute() function is only called for DMs (if (!isGroup)), not for groups. This causes:
1. Main session (agent:main:main) HAS lastChannel: "telegram" and lastTo: "chatId" - gets updated for ALL messages
2. Group sessions (agent:main:telegram:group:chatId:topic:xxx) LACK lastChannel and lastTo fields - never get updated
3. Follow-up messages from the group use stale routing state
Other Investigation Findings:
- OriginatingChannel and OriginatingTo ARE correctly set to "telegram" and "telegram:${chatId}" for both DMs and groups (line 574-575)
- Session keys correctly identify group sessions: agent:main:telegram:group:-1003671339398:topic:xxx
- The issue appears to be in how follow-up agent runs resolve their delivery target when there's no explicit lastChannel on the group session entry
Potential Fix Locations
The fix likely needs to remove the !isGroup condition from the updateLastRoute() call in src/telegram/bot.ts so that group sessions also get their lastChannel and lastTo fields properly updated.
Community Questions to Ask
1. Has anyone else encountered Telegram group replies going to webchat?
2. Is there a session.sendPolicy setting that might be overriding routing?
3. Should group sessions maintain lastChannel/lastTo like main sessions do?
4. Is there a known workaround or configuration setting?
Was this page helpful?