Channel Inbound Media Pipeline#
Inbound files from Slack, Telegram, and WhatsApp are converted into session attachments so agents can read them directly. The pipeline was introduced in PR #7248 and reuses the existing session attachment service — native images can be inlined in the model prompt; other files are available in the session working directory.
How It Works#
The pipeline has two stages:
1. Adapter — Emit Media Parts#
Each channel adapter's event parser emits media parts alongside message text. A media part carries a platform file ID, kind (image, audio, video, document), MIME type, and filename — but not a download URL (which rotates).
- Slack:
file_media_parts(event)iteratesevent["files"], keying each part on its Slack fileid. A file-share message with no comment produces no empty text part. - Telegram:
media_parts(message)mapsphoto,document,voice,audio,video, andvideo_notefields. Forphoto, it picks the largest by pixel area (not list order). - WhatsApp: The
_MEDIA_TYPESset was extended from("image", "document")to("image", "document", "audio", "video").
2. Inbox Dispatcher — Download & Store#
InboxDispatcher._attach_media converts each media part into a session attachment part before the turn is invoked.
For each media part it:
- Calls the channel adapter's
fetch_media(connection, media, max_bytes=limits.max_raw_bytes), wheremax_bytescomes from the attachment service'slimits.max_raw_bytes(orNoneif unavailable). - Stores the result via
SessionAttachmentsService.create_attachment, scoped to(project_id, user_id, session_id), with idempotency keychannels:<media_id>. - Calls
reference_attachmentsto link the attachment to the session. - Replaces the
mediapart in the content list with anattachmentpart containing the attachment ID, filename, MIME type, and size.
Failure handling: an oversized file becomes a (too large to read) text note; any other fetch/storage error becomes a (could not be read) note — the message still reaches the agent.
Per-Channel Download Logic#
Each channel adapter implements fetch_media(connection, media, max_bytes):
| Channel | Resolution step | Size check | Notes |
|---|---|---|---|
| Slack | files.info → url_private_download | Pre-download: skip if size > max_bytes; post-download: check len(response.content) | HTML response = login page → raises file_download_denied; private URLs are never persisted. |
| Telegram | getFile → file_path | Pre-download: skip if file_size > max_bytes; post-download: check body length | Bot API independently refuses downloads > 20 MB. Hosted adapter overrides _api_token to use the deployment token. |
| Platform-native download | Via attachment service limits | Uses existing WhatsApp media download flow. |
Download timeout for Slack and Telegram is _MEDIA_TIMEOUT_SECONDS = 30.0.
Known issue: When Slack's
files.infoomitssize, the pre-download check is skipped. The current implementation loads the full HTTP response body before checkinglen(response.content), which can allocate the entire file in worker memory. A reviewer proposed switching to chunked streaming viahttpx.AsyncClient.stream().
Platform Size Limits#
Platforms advertise their own caps; the stricter attachment service limits govern what the agent actually reads.
| Channel | Platform-advertised cap |
|---|---|
| Slack | 1 GB |
100 MB (capabilities: max_bytes = 100 * 1024 * 1024) | |
| Telegram | 20 MB (capabilities: max_bytes = 20 * 1024 * 1024) |
Capabilities are declared in each adapter's capabilities.py:
Key Files#
| Path | Role |
|---|---|
api/oss/src/tasks/asyncio/channels/inbox.py | InboxDispatcher._attach_media — orchestrates fetch + store for all channels |
api/oss/src/core/channels/adapters/slack/adapter.py | SlackAdapter.fetch_media — files.info + authenticated download |
api/oss/src/core/channels/adapters/slack/mapping.py | file_media_parts — builds media parts from Slack event |
api/oss/src/core/channels/adapters/telegram/adapter.py | TelegramAdapter.fetch_media — getFile + download |
api/oss/src/core/channels/adapters/telegram/mapping.py | media_parts — builds media parts from Telegram message |
api/oss/src/core/channels/adapters/whatsapp/mapping.py | WhatsApp media type mapping |
api/oss/tests/pytest/unit/channels/slack/test_slack_adapter.py | Slack adapter tests |
api/oss/tests/pytest/unit/channels/telegram/test_telegram_adapter.py | Telegram adapter tests |
api/oss/tests/pytest/unit/channels/whatsapp/test_whatsapp_dispatcher.py | WhatsApp dispatcher tests |
See also: openspec/changes/channel-inbound-media/ for the design spec and task breakdown.