← Back to PRs

#17081: fix(telegram): suppress file-size error replies in groups when bot is not mentioned

by p697 open 2026-02-15 11:36 View on GitHub →
channel: telegram stale size: XS
## Problem When a user sends a large file (e.g. video > 5MB) in a Telegram group with `requireMention: true`, every bot in the group replies with: > ⚠️ File too large. Maximum size is 5MB. This happens because the file-size error is thrown by `resolveMedia()` and caught in a handler that sends the error reply **before** the `requireMention` check runs (which happens later in `processMessage()`). With multiple agents in the same group, this creates a wall of identical error messages. ## Fix Added a `requireMention` check inside the file-size error catch block. When all of these are true, the error reply is silently suppressed: - Message is in a group chat - `requireMention` is not explicitly `false` - The bot was not `@mentioned` in the message text/caption The check uses the same config resolution order as the rest of the codebase: topic → group → channel → global. ## Test All 53 Telegram test files pass (436 tests). Fixes #17048 <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR adds logic to suppress "File too large" error replies in Telegram groups when `requireMention` is enabled and the bot was not `@mentioned`. This is a targeted fix for the spam issue where multiple bots reply with identical error messages to large file uploads. - **Critical: missing `firstDefined` import** — `firstDefined` is used at line 1084 but never imported in `bot-handlers.ts`. This will cause a `ReferenceError` at runtime when the file-size error path is hit in a group chat, crashing the handler instead of suppressing the message. - The `hasBotMention` import was correctly added from `./bot/helpers.js`, and the mention detection logic is sound. - The `requireMention` resolution chain (`topicConfig → groupConfig → opts.requireMention`) is a simplified version of the canonical chain in `processMessage`, missing `activationOverride`. This is acceptable since session-level activation state isn't available in the handler context, and the behavior errs safely toward suppression. <h3>Confidence Score: 2/5</h3> - This PR has a missing import that will cause a runtime crash on the affected code path — must be fixed before merging. - The missing `firstDefined` import in `bot-handlers.ts` will cause a `ReferenceError` at runtime when a large file triggers the media-size error in a group chat. Instead of suppressing the error reply, the handler will crash. The logic and approach are otherwise sound. - `src/telegram/bot-handlers.ts` — missing import for `firstDefined` at line 1084 will cause a runtime error. <sub>Last reviewed commit: a523588</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs