Skip to content

fix(telegram): ignore messageThreadId for DM chats (#14653)#17235

Closed
robbyczgw-cla wants to merge 1 commit intoopenclaw:mainfrom
robbyczgw-cla:fix/telegram-thread-dm-14653
Closed

fix(telegram): ignore messageThreadId for DM chats (#14653)#17235
robbyczgw-cla wants to merge 1 commit intoopenclaw:mainfrom
robbyczgw-cla:fix/telegram-thread-dm-14653

Conversation

@robbyczgw-cla
Copy link
Contributor

@robbyczgw-cla robbyczgw-cla commented Feb 15, 2026

Problem

In Telegram DM chats (non-forum), resolveTelegramThreadSpec() forwards message_thread_id as a thread ID in the threadSpec. This causes reply routing issues since DMs do not have real threads — Telegram sometimes sends message_thread_id in DMs (e.g. when Topics are enabled globally), but it has no semantic meaning there.

Fixes #14653

Solution

Remove the messageThreadId branch from the DM path in resolveTelegramThreadSpec(). DMs now always return { scope: "dm" } without an id field, regardless of whether message_thread_id is present.

Changes

  • src/telegram/bot/helpers.ts — Collapsed the DM branch to always return { scope: "dm" } (+1/−7 lines)
  • src/telegram/bot-message-context.dm-topic-threadid.test.ts — Updated assertions to expect no threadId for DMs
  • src/telegram/bot-message-dispatch.test.ts — Updated 4 test cases: threadSpec for DMs no longer includes id

Testing

All existing Telegram tests pass. The updated tests verify the new behavior: DMs never carry a thread ID.

🤖 AI-assisted: code changes generated with AI assistance, manually reviewed and verified.

Greptile Summary

This PR fixes a reply routing issue in Telegram DMs by removing spurious message_thread_id handling. Previously, when Telegram sent message_thread_id in DM chats (which can happen when Topics are enabled globally), the code incorrectly treated it as a real thread ID, causing session routing problems. The fix ensures DMs always return { scope: "dm" } without an id field, since DMs don't have semantic threads. The change correctly propagates through the codebase: replyThreadId, dmThreadId, and MessageThreadId all become undefined for DMs, which is the intended behavior. All test updates properly verify that DMs never carry thread IDs, even when message_thread_id is present in the Telegram message payload.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is minimal, well-scoped, and correctly addresses a real bug. The logic change collapses the DM branch to always return { scope: "dm" } without an id, which aligns with Telegram's semantics where message_thread_id has no meaning in DM chats. All affected code paths handle undefined threadSpec.id correctly (e.g., buildTypingThreadParams, dmThreadId extraction, session key resolution). The test updates comprehensively verify the new behavior across multiple scenarios. No edge cases or potential issues identified.
  • No files require special attention

Last reviewed commit: cd890e1

@robbyczgw-cla
Copy link
Contributor Author

Closing — this appears to be already fixed upstream. resolveTelegramThreadSpec now returns { scope: "dm" } without an id field for private chats, and buildTelegramThreadParams returns undefined when thread.id == null. The bug no longer reproduces on latest main.

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.

Telegram plugin: replyTo parameter incorrectly mapped to message_thread_id instead of reply_to_message_id

1 participant