#17081: fix(telegram): suppress file-size error replies in groups when bot is not mentioned
channel: telegram
stale
size: XS
Cluster:
Slack Thread Management Improvements
## 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
#18533: fix(telegram): handle 'file is too big' error for large files
by MisterGuy420 · 2026-02-16
83.0%
#7719: fix(slack): thread replies with @mentions dropped in requireMention...
by SocialNerd42069 · 2026-02-03
77.9%
#20479: fix(slack): keep replies flowing for oversized file uploads
by olyashok · 2026-02-19
76.9%
#20152: fix(slack): allow app_mention events to bypass dedup cache
by nova-openclaw-cgk · 2026-02-18
76.4%
#17256: fix: allow text regex fallback when bot JID not in mentionedJids
by DarlingtonDeveloper · 2026-02-15
76.1%
#11166: fix(whatsapp): detect LID @mentions in self-chat mode
by mcaxtr · 2026-02-07
76.0%
#13829: fix(googlechat): detect bot @mentions via user.type when botUser no...
by mcaxtr · 2026-02-11
75.9%
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
75.3%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
75.3%
#16105: fix: handle message_reaction updates in group polling mode
by claw-sylphx · 2026-02-14
75.2%