#14057: feat(telegram): add ignoreMediaTypes config to skip specific inbound media
channel: telegram
stale
size: S
Cluster:
Messaging Platform Improvements
## Problem
In group chats, the bot processes **every** incoming media message — including video notes (circles) and videos — even when it wasn't mentioned. This leads to:
- "File too large" errors on video notes
- Meaningless LLM responses to casual media the bot wasn't asked about
- Noise in active group chats where people share circles/videos frequently
The only existing media controls are `mediaMaxMb` (size limit) and sticker-type filtering — there's no way to skip specific media types at the config level.
## Solution
Add `channels.telegram.ignoreMediaTypes` — an optional array of media type strings to silently skip during inbound processing.
### Behavior matrix
#### Before (current behavior)
| Context | All media types |
|-------------------------|------------------------|
| DM | ✅ Processed |
| Group, no @mention | ✅ Processed |
| Group, bot @mentioned | ✅ Processed |
#### After (with this PR)
| Context | `ignoreMediaTypes` not set | `ignoreMediaTypes` explicitly set |
|-------------------------|-------------------------------------|-----------------------------------|
| DM | ✅ All media processed | 🚫 Skips types from list |
| Group, no @mention | 🚫 Skips `video_note` + `video` | 🚫 Skips types from list |
| Group, bot @mentioned | ✅ All media processed | ✅ All media processed |
### Key design decisions
- **Context-aware defaults**: In groups, `video_note` and `video` are skipped by default (the most common source of noise). In DMs, nothing is filtered.
- **Mention override**: When the bot is `@mentioned` in a group, all media is processed regardless of the ignore list — the user deliberately asked.
- **Caption preservation**: If an ignored media message has caption text, the text is still processed (only the media download is skipped).
- **Explicit config overrides defaults**: Setting `ignoreMediaTypes: []` restores full media processing in groups.
- **Gateway auto-discovery**: The field uses `z.enum()` validation, so it automatically appears in the OpenClaw Gateway admin panel with proper controls.
### Supported media types
`"photo"` | `"video"` | `"video_note"` | `"document"` | `"audio"` | `"voice"` | `"sticker"`
### Config example
```json
{
"channels": {
"telegram": {
"ignoreMediaTypes": ["video_note", "voice"]
}
}
}
```
## Changes
| File | Change |
|------|--------|
| `src/config/zod-schema.providers-core.ts` | Add `ignoreMediaTypes` field with `z.enum()` validation |
| `src/config/types.telegram.ts` | Add TypeScript type + JSDoc |
| `src/telegram/bot-handlers.ts` | Add `resolveTelegramMediaType()` helper, context-aware filtering in single-message handler and `processMediaGroup` |
## Test plan
- [x] `tsc --noEmit` — clean
- [x] `pnpm build` — passes
- [x] All 49 telegram test files pass (414 tests)
- [x] ESLint clean (0 errors)
## Notes
- Open PRs #6516 and #8479 also modify `bot-handlers.ts` around the `resolveMedia` call path — may need rebase coordination if they merge first.
- The `resolveTelegramMediaType()` helper checks `video_note` before `video` because grammY may set both fields on a video note message.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces a new Telegram config option `channels.telegram.ignoreMediaTypes` (validated via Zod) and applies it in the Telegram inbound handlers to skip downloading/processing selected media types. It also adds a small helper module (`src/telegram/media-type-filter.ts`) to resolve a message’s media type and compute the effective ignore list (including group-only defaults). The single-message handler now avoids calling `resolveMedia` for ignored types unless there is caption/text content to process; media groups apply similar filtering across album items, with `@mention` in groups overriding filtering.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are additive and localized: config schema/type additions plus straightforward handler gating that skips media downloads based on an explicit allowlist and existing mention detection. No behavior changes outside Telegram inbound media handling and the new helper module; logic paths still fall back to existing processing when captions/text are present or when mentioned in groups.
- src/telegram/bot-handlers.ts (ensure behavior matches the intended mention/DM/group matrix in real Telegram environments)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22434: feat(telegram): support sending original quality images
by godenjan · 2026-02-21
82.5%
#15467: feat(messages): add debounceMedia option for inbound debouncing
by tangcruz · 2026-02-13
81.7%
#21309: feat(telegram): support outbound media groups (albums) via sendMedi...
by smysle · 2026-02-19
81.0%
#19942: feat(telegram): configurable SSRF policy for media fetch
by onewesong · 2026-02-18
80.7%
#8310: feat(telegram): Add allowBots support for groups (parity with Disco...
by vishaltandale00 · 2026-02-03
79.8%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
78.1%
#20674: fix #20495 & #20515: configure UX + Telegram media group fixes
by neipor · 2026-02-19
77.5%
#15864: feat: add deliverOnlyToolMessages config for clean messaging channe...
by gandalf-the-engineer · 2026-02-14
77.2%
#19399: telegram: fix MEDIA false positives and partial final drop
by HOYALIM · 2026-02-17
77.1%
#7058: feat(telegram): add channel_post handler for broadcast channels
by waifu7498173 · 2026-02-02
77.1%