{"record":{"id":"5caff2e0a013b42c","repo":"langchain-ai/deepagents","slug":"telegram-media-is-too-large-file-size-bytes-exc","errorCode":null,"errorMessage":"Telegram media is too large: {file_size} bytes exceeds {self.config.max_media_bytes}","messagePattern":"Telegram media is too large: (.+?) bytes exceeds (.+?)","errorType":"exception","errorClass":"ChannelMediaError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/channels/telegram.py","lineNumber":660,"sourceCode":"            media_type: Normalized media category.\n            message_id: Telegram message identifier used to name the file.\n\n        Returns:\n            Local path to the downloaded file.\n        \"\"\"\n        payload = await self._transport.call(\"getFile\", file_id=file_id)\n        result = _extract_result(payload)\n        file_path = result.get(\"file_path\") if isinstance(result, dict) else None\n        if not isinstance(file_path, str):\n            msg = \"Telegram getFile response missing file_path\"\n            raise _TelegramError(msg)\n        file_size = result.get(\"file_size\") if isinstance(result, dict) else None\n        if isinstance(file_size, int) and file_size > self.config.max_media_bytes:\n            msg = (\n                \"Telegram media is too large: \"\n                f\"{file_size} bytes exceeds {self.config.max_media_bytes}\"\n            )\n            raise ChannelMediaError(msg)\n        if self.config.inbound_media_dir is None:\n            msg = \"Telegram inbound media directory is not configured\"\n            raise _TelegramError(msg)\n        suffix = _safe_suffix(file_path, media_type)\n        destination = self.config.inbound_media_dir / _inbound_media_filename(\n            message_id=message_id,\n            file_id=file_id,\n            suffix=suffix,\n        )\n        download_url = f\"{self.config.api_base}/file/bot{self.config.bot_token}/{file_path}\"\n        await asyncio.to_thread(\n            _download_file,\n            download_url,\n            destination,\n            self.config.request_timeout_seconds,\n            self.config.max_media_bytes,\n        )\n        return destination","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/channels/telegram.py#L642-L678","documentation":"Before downloading an inbound Telegram attachment, `_download_inbound_media` checks the file size reported by the Telegram API (`get_file` result) against `config.max_media_bytes`. Files whose declared size exceeds the cap raise `ChannelMediaError` so oversized media is never written to disk.","triggerScenarios":"A user sends a photo/video to the bot whose Telegram-reported `file_size` exceeds the configured `max_media_bytes` limit; `_prepare_inbound_media` then aborts during message ingestion.","commonSituations":"Users send large videos to the bot; deployments with a conservative `max_media_bytes` (e.g. a few MB) receiving normal-sized media; bots in busy groups receiving forwarded large files.","solutions":["Raise `max_media_bytes` in the Talon config to accommodate the media sizes your users send (mind disk and memory constraints).","Ask senders to compress media or use Telegram's compressed photo/video send modes, which produce smaller files.","Handle `ChannelMediaError` in your inbound pipeline and reply to the sender that the attachment is too large instead of crashing the handler."],"exampleFix":"# before\nconfig.max_media_bytes = 5 * 1024 * 1024  # 5 MB cap\n# after\nconfig.max_media_bytes = 20 * 1024 * 1024  # 20 MB cap","handlingStrategy":"try-catch","validationCode":"def inbound_size_ok(file_size: int | None, max_bytes: int) -> bool:\n    return file_size is None or file_size <= max_bytes","typeGuard":null,"tryCatchPattern":"try:\n    media = await channel._prepare_inbound_media(message)\nexcept ChannelMediaError as exc:\n    await reply(message, f\"Attachment rejected: {exc}\")","preventionTips":["Size max_media_bytes to the largest media your users legitimately send","Pre-check Telegram's reported file_size before download attempts","Reply to senders explaining the size limit instead of failing silently","Monitor rejected-media metrics to tune the cap"],"tags":["telegram","media","size-limit","download"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}