Skip to content

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

Closed
timbrinded wants to merge 3 commits into
openclaw:mainfrom
timbrinded:fix/telegram-dm-topics
Closed

fix(telegram): support message_thread_id for DM topics#17952
timbrinded wants to merge 3 commits into
openclaw:mainfrom
timbrinded:fix/telegram-dm-topics

Conversation

@timbrinded

@timbrinded timbrinded commented Feb 16, 2026

Copy link
Copy Markdown

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 Summary

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

Confidence Score: 5/5

  • 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

Last reviewed commit: e65d964

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Telegram added 'Topics in DMs' which assigns thread IDs to DM
conversations. The existing code unconditionally stripped
message_thread_id for all DM-scoped threads, assuming DMs never
have threads. This caused replies to land outside their topic
in DMs that have topics enabled.

Now pass through message_thread_id when present (> 0) for DM
scope, only omitting it for regular DMs without topics.
Copilot AI review requested due to automatic review settings February 16, 2026 10:19
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS labels Feb 16, 2026
@timbrinded

Copy link
Copy Markdown
Author

Anecdotally these were the fixes i had to do on my installation to fix threading this morning after updating to latest version.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for Telegram's "Topics in DMs" feature by allowing message_thread_id to be passed through for direct message conversations that have topics enabled. Previously, the code unconditionally filtered out all thread IDs for DM scope, assuming DMs never had threads.

Changes:

  • Modified buildTelegramThreadParams to pass through positive thread IDs for DM scope instead of always returning undefined
  • Updated tests in helpers.test.ts to validate that DM topics with valid IDs now include message_thread_id
  • Updated draft-stream.test.ts to expect message_thread_id for DM topics

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/telegram/bot/helpers.ts Changed DM thread ID handling to conditionally pass through positive values
src/telegram/bot/helpers.test.ts Updated tests to reflect new DM topic behavior and validate edge cases
src/telegram/draft-stream.test.ts Updated draft stream test to expect thread ID for DM topics

Comment thread src/telegram/bot/helpers.ts
Comment thread src/telegram/bot/helpers.ts
timbrinded and others added 2 commits February 16, 2026 10:25
The delivery test asserted message_thread_id should NOT be present
for DM-scoped threads. Updated to expect it IS present, matching
the new behavior that passes through thread IDs for DM topics.
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 22, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Feb 23, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Appreciate this patch.\n\nI’m closing as superseded because the DM-topic thread-id behavior from this PR is already represented in current mainline Telegram logic (and related changelog entries), so keeping this branch open now only creates duplicate review surface.\n\nIf you see a remaining edge case not covered by main, reply with a repro and we can reopen quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(telegram): message_thread_id stripped for DM topics since 19b8416a8

4 participants