← Back to PRs

#14057: feat(telegram): add ignoreMediaTypes config to skip specific inbound media

by pavelsamoylenko open 2026-02-11 11:27 View on GitHub →
channel: telegram stale size: S
## 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