#7261: fix(telegram): preserve DM topic thread id for outbound media
channel: telegram
size: S
Cluster:
Messaging Platform Improvements
### Problem
In Telegram private chats with topics (Bot API 9.3+), async followup sends (routeReply/outbound → sendMessageTelegram) could drop `message_thread_id` when the DM thread id is `1`, because `sendMessageTelegram` always treated thread ids as **forum** scope.
This causes outbound media/documents to land in the main DM window instead of the correct DM topic.
### Fix
- Detect private vs forum chat ids (positive chat id = private chat).
- Build `threadSpec` with scope `dm` for private chats and `forum` otherwise, so `buildTelegramThreadParams` only omits id=1 for forum General topic, but keeps id=1 for DM topics.
### Tests
- Added tests covering DM `message_thread_id=1` for media/doc sends and stickers.
- Added tests ensuring forum General topic id=1 still omits `message_thread_id`.
This should fix delayed media/file replies in DM topics while preserving existing forum behavior.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates Telegram outbound sending to preserve `message_thread_id=1` when sending to DM topics (Bot API 9.3+), while continuing to omit `message_thread_id=1` for forum “General” topic sends. It does this by inferring whether the destination is a private chat vs a forum chat and passing a corresponding `scope` into `buildTelegramThreadParams`, plus adds unit tests covering DM topic `id=1` for documents/media and stickers and forum general-topic omission.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge, but the DM-vs-forum detection and one of the new tests could allow regressions to slip through.
- Core change is small and leverages existing `buildTelegramThreadParams` behavior, but it duplicates chat-id parsing logic in two places and can misclassify non-numeric chat IDs (e.g., `@username`). Additionally, the new “omit message_thread_id” test does not robustly assert absence of the field, reducing confidence that the intended regression is covered.
- src/telegram/send.ts and src/telegram/send.returns-undefined-empty-input.test.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
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
90.3%
#17952: fix(telegram): support message_thread_id for DM topics
by timbrinded · 2026-02-16
88.7%
#14443: fix(telegram): skip General topic thread ID for all chat types (#14...
by lailoo · 2026-02-12
88.7%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
88.1%
#17968: fix(telegram): restore DM topic thread ids with send-path fallback
by Leonccaa · 2026-02-16
87.6%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
87.5%
#6192: Telegram: fix DM Topics thread routing
by ViffyGwaanl · 2026-02-01
86.7%
#19050: fix(telegram): skip message_thread_id for private chats to prevent ...
by Limitless2023 · 2026-02-17
84.7%
#17432: fix(telegram): skip message_thread_id for private chats in sticker/...
by clawinho · 2026-02-15
84.1%
#6457: fix(telegram): register commands for group scope + preserve topic t...
by dae-sun · 2026-02-01
82.8%