← Back to PRs

#19108: fix(telegram): fix send failure in closed forum topics

by Clawborn open 2026-02-17 11:32 View on GitHub →
channel: telegram channel: voice-call gateway size: S trusted-contributor
When sending to a closed forum topic, Telegram returns a 'topic closed' error. Fix: Detect the error and attempt to reopen the topic before retrying the send. Falls through to existing thread-not-found fallback if reopen fails. Recreated from #18149 with only relevant files (telegram send + new test). <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds automatic recovery for closed forum topics in Telegram by detecting "topic closed" errors and attempting to reopen the topic before retrying the send operation. The fix extends the existing `withTelegramThreadFallback` helper to handle this error case before falling back to the existing thread-not-found retry logic. **Key changes:** - Added `TOPIC_CLOSED_RE` regex pattern and `isTelegramTopicClosedError` helper to detect closed topic errors - Added `getMessageThreadId` helper to extract thread ID from params for reopen operation - Extended `withTelegramThreadFallback` to accept optional `recoverOptions` with `chatId` and `api` for calling `reopenForumTopic` - Applied recovery logic consistently across all 3 call sites: `sendMessageTelegram`, `sendStickerTelegram`, and `sendPollTelegram` - Comprehensive test coverage for the reopen logic in new test file **Issue found:** - `getMessageThreadId` doesn't validate `Number.parseInt` result, which could return `NaN` for malformed string inputs <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk once the NaN validation issue is addressed - The implementation follows existing patterns in the codebase, includes comprehensive test coverage, and consistently applies the fix across all relevant call sites. The recovery logic is properly scoped to only handle topic-closed errors and falls through to existing error handling. One logical issue exists with `Number.parseInt` not validating for `NaN`, which could cause the reopen attempt to be skipped silently for malformed thread IDs. - Pay attention to `src/telegram/send.ts:376-377` where `Number.parseInt` needs `NaN` validation <sub>Last reviewed commit: 72079a4</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs