← Back to PRs

#17952: fix(telegram): support message_thread_id for DM topics

by timbrinded open 2026-02-16 10:19 View on GitHub →
channel: telegram stale size: XS
Fixes #17977 ## Summary `buildTelegramThreadParams()` unconditionally returns `undefined` for `scope: "dm"`, stripping `message_thread_id` from all DM sends since `19b8416a8`. This breaks reply targeting for bots with Telegram DM topics enabled (Bot API 9.3, Dec 31 2025). ## Fix Pass through `message_thread_id` when present (`> 0`) for DM scope. Only omit it for regular DMs without topics (where thread ID would be 0 or absent). Invalid values (≤ 0) are filtered at the source rather than relying on the send-path fallback to catch API rejections. ## Changes - `src/telegram/bot/helpers.ts`: Allow positive thread IDs through for DM scope - `src/telegram/bot/helpers.test.ts`: Updated tests for DM topic behavior - `src/telegram/draft-stream.test.ts`: Updated draft stream test for DM topic threading - `src/telegram/bot/delivery.test.ts`: Updated delivery test to expect `message_thread_id` for DM topics <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR restores DM topic support that was unintentionally broken by a previous fix. The change in `buildTelegramThreadParams()` now correctly passes through `message_thread_id` for DMs when a topic ID is present (> 0), while filtering out invalid values (≤ 0) for regular DMs without topics. This aligns with Telegram Bot API 9.3's DM topics feature. - Updated `src/telegram/bot/helpers.ts:133-136` to conditionally return thread params for DM scope based on thread ID value - Updated all related tests to expect `message_thread_id` for DM topics instead of omitting it - The fix properly handles edge cases: filters out 0 and negative IDs, truncates decimals, and preserves existing forum topic behavior <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is surgical, well-tested, and restores previously working functionality. The logic change is simple (adding a conditional check for positive thread IDs), all tests have been updated to match the new behavior, and the fix aligns with documented Telegram Bot API features. The change only affects DM scope while preserving existing forum and regular group behavior. - No files require special attention <sub>Last reviewed commit: e65d964</sub> <!-- 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