fix(telegram): skip message_thread_id for private chats to prevent silent message drops (v2)#19050
Open
Limitless2023 wants to merge 1 commit intoopenclaw:mainfrom
Open
Conversation
… prevent silent message drops For private chats (chatId > 0), the opts-level messageThreadId — which typically comes from reply-context — caused Telegram to reject sends with '400: Bad Request: message thread not found'. Messages were silently dropped, affecting sub-agent notifications, cron deliveries, and proactive messages. The fix: in buildTelegramThreadReplyParams, private chats now only use the thread ID embedded in the target address (e.g. '123456789:topic:42') and ignore the opts-level messageThreadId. This preserves DM topic routing (Bot API 9.3, openclaw#18974) while fixing the silent drop for plain private chats. Applies to all send paths: text, media, stickers, and polls. Closes openclaw#17242
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improved v2 of #17252 — Fixes #17242
Closes #17242
Problem
When sending messages to Telegram private chats (positive chatId), the opts-level
messageThreadId— typically derived from reply-context — is passed asmessage_thread_idto the Telegram API. Private chats don't support forum topics, so the API rejects with:Messages are silently dropped, affecting:
sessions_spawn)messagetool sendsRoot cause
buildTelegramThreadReplyParamsunconditionally mergesopts.messageThreadIdinto the thread spec for all chat types, including private chats wheremessage_thread_idis invalid.Fix
In
buildTelegramThreadReplyParams, private chats (chatType === "direct") now only honour the thread ID embedded in the target address (e.g.,123456789:topic:42) and ignore the opts-levelmessageThreadId.This is a single-point fix that covers all send paths: text messages, media, stickers, and polls — addressing the reviewer feedback on #17252 about missing sticker/poll checks.
Why not blanket-strip?
Previous #17252 was rejected because blanket-suppressing
message_thread_idfor all private chats would break DM topic routing (Bot API 9.3, #18974). This v2 distinguishes between:123456789:topic:42)opts.messageThreadId(reply context)Changes
src/telegram/send.ts—buildTelegramThreadReplyParams: for private chats, use onlytargetMessageThreadId(from target string), ignoreopts.messageThreadIdsrc/telegram/send.test.ts— Updated/added tests:messageThreadIdis skipped for private chat text sendsmessageThreadIdis skipped for private chat sticker sendsTest results
All 38 telegram test files pass (469 tests).
Greptile Summary
This PR fixes silent message drops when sending to Telegram private chats with a reply-context
messageThreadId(#17242). The root cause wasbuildTelegramThreadReplyParamsunconditionally forwardingopts.messageThreadId(from reply context) to the API asmessage_thread_id, which private chats reject with400: Bad Request: message thread not found.The fix is a single-point change in
buildTelegramThreadReplyParams:chatType === "direct"): only use the thread ID embedded in the target address (e.g.,123456789:topic:42), ignoring the opts-levelmessageThreadIdopts.messageThreadIdtakes priority, falls back totargetMessageThreadId)This covers all send paths (text, media, stickers, polls) since they all flow through
buildTelegramThreadReplyParams.Confidence Score: 5/5
??operator is semantically equivalent to the previous!= nullternary for the non-private path.Last reviewed commit: 3cd7e0d