#17968: fix(telegram): restore DM topic thread ids with send-path fallback
channel: telegram
size: M
Cluster:
Messaging Platform Improvements
## Summary
Restores DM topic reply targeting by including `message_thread_id` for `scope: "dm"` in `buildTelegramThreadParams()`.
This keeps private-topic/thread UX working while preserving existing send-path fallback behavior (retry without thread id on Telegram rejection).
## Why
`2026.2.15` omitted DM `message_thread_id` to avoid `400 Bad Request: message thread not found`.
That fixed delivery failures, but can cause replies in Telegram private topics to appear in the main tab instead of the active topic.
## Changes
- `src/telegram/bot/helpers.ts`
- For `thread.scope === "dm"`, return `{ message_thread_id }` instead of omitting.
- Keep General forum topic (`id=1`) omission behavior unchanged.
- `src/telegram/bot/helpers.test.ts`
- Update DM-thread expectations to include/normalize `message_thread_id`.
## Related
- Follow-up regression report: #17960
- Prior fix: #10942
## Notes
I could not run the full test suite in this environment because project test deps/tooling are not fully installed in the sandbox PATH, but the updated unit tests reflect the new behavior.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR re-enables `message_thread_id` for DM-scoped threads in `buildTelegramThreadParams`, restoring proper reply targeting in Telegram private topic/thread conversations. The prior fix (#10942) had omitted this field entirely to avoid `400 Bad Request: message thread not found` errors, but that caused replies to land in the main chat tab instead of the active topic.
- `buildTelegramThreadParams` now returns `{ message_thread_id }` for `scope: "dm"` instead of `undefined`
- Tests updated to assert thread ID inclusion and normalization for DM threads
- The `send.ts` path has `withTelegramThreadFallback` to retry without the thread ID on rejection, but the `delivery.ts` path (bot reply delivery) does not have this fallback — this was already discussed in a prior review thread
<h3>Confidence Score: 3/5</h3>
- This PR is a targeted behavior change with a known gap in fallback coverage on one send path.
- The code change itself is small and correct for its stated purpose. Tests are consistent with the implementation. However, the `delivery.ts` send path (used for bot reply delivery) lacks the `withTelegramThreadFallback` mechanism that `send.ts` has, meaning if a DM topic thread ID becomes stale, replies through `delivery.ts` will fail without retry. This was the exact scenario the prior fix was protecting against. The score of 3 reflects that the change works correctly for valid DM topics but reintroduces a partial regression risk on one delivery path.
- `src/telegram/bot/delivery.ts` — uses `buildTelegramThreadParams` directly without `withTelegramThreadFallback`, meaning DM thread ID failures won't be retried on this path.
<sub>Last reviewed commit: 17d256b</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17952: fix(telegram): support message_thread_id for DM topics
by timbrinded · 2026-02-16
91.5%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
89.3%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
87.6%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
87.6%
#14443: fix(telegram): skip General topic thread ID for all chat types (#14...
by lailoo · 2026-02-12
86.2%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
86.0%
#6192: Telegram: fix DM Topics thread routing
by ViffyGwaanl · 2026-02-01
83.3%
#19050: fix(telegram): skip message_thread_id for private chats to prevent ...
by Limitless2023 · 2026-02-17
83.1%
#8985: fix(telegram): preserve forum topic context for pairing auto-replies
by lailoo · 2026-02-04
81.5%
#11653: fix(telegram): retry without message_thread_id on stale forum threa...
by liuxiaopai-ai · 2026-02-08
81.4%