← Back to PRs

#7261: fix(telegram): preserve DM topic thread id for outbound media

by ViffyGwaanl open 2026-02-02 16:20 View on GitHub →
channel: telegram size: S
### 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