#6192: Telegram: fix DM Topics thread routing
channel: telegram
Cluster:
Messaging Platform Improvements
### What
Fix thread routing for Telegram *private chats with Topics enabled* by using the raw `message_thread_id` instead of applying forum-group thread resolution.
### Why
`resolveTelegramForumThreadId(...)` is intended for forum groups; in private chats it can cause replies/typing to fall back to the main thread.
### Change
- In groups/supergroups: keep using `resolveTelegramForumThreadId({ isForum, messageThreadId })`
- In private chats: set `resolvedThreadId = messageThreadId`
- Make `replyThreadId` follow `resolvedThreadId`
### Notes
This matches observed behavior when DM Topics are enabled and `message_thread_id` is present.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates Telegram thread routing in `buildTelegramMessageContext` to treat DMs differently from groups: groups/supergroups still derive a `resolvedThreadId` via `resolveTelegramForumThreadId`, while private chats use the raw `message_thread_id`, and replies/typing now consistently use `replyThreadId = resolvedThreadId`.
Overall this aligns the DM behavior with Telegram “Topics in private chats”, but the new `replyThreadId` assignment can change behavior for *non-forum* groups by routing replies/typing into the default forum topic id (often `1`) rather than the main thread when `message_thread_id` is absent.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe but may misroute replies/typing in non-forum groups due to default topic resolution.
- The change is small and targeted, but it modifies group reply routing by always using `resolvedThreadId`, which can differ from the previous behavior when `isForum` is false and `message_thread_id` is missing.
- 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>
<!-- /greptile_comment -->
Most Similar PRs
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
86.7%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
86.2%
#14443: fix(telegram): skip General topic thread ID for all chat types (#14...
by lailoo · 2026-02-12
86.1%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
85.6%
#17952: fix(telegram): support message_thread_id for DM topics
by timbrinded · 2026-02-16
84.4%
#17968: fix(telegram): restore DM topic thread ids with send-path fallback
by Leonccaa · 2026-02-16
83.3%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
83.1%
#19050: fix(telegram): skip message_thread_id for private chats to prevent ...
by Limitless2023 · 2026-02-17
80.9%
#8985: fix(telegram): preserve forum topic context for pairing auto-replies
by lailoo · 2026-02-04
80.9%
#6457: fix(telegram): register commands for group scope + preserve topic t...
by dae-sun · 2026-02-01
80.3%