#22389: Fix: Matrix plugin not sending images from content blocks
channel: matrix
size: S
Cluster:
Matrix Media Handling Fixes
## Problem
When tools return image data in the `content` array, the Matrix plugin ignores these images and only sends text.
## Solution
This fix extracts image blocks from `reply.content`, saves base64 data to temp files, and adds them to the media list for sending.
## Changes
- Extract content blocks and separate images from text
- Write base64 images to temp files with index counter to avoid collisions
- Include extracted images in the media list
- Clean up temp files after sending
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR successfully implements support for sending images from content blocks in Matrix plugin replies. The implementation extracts image blocks from `reply.content`, converts base64 data to temporary files, and includes them in the media list for delivery.
**Key changes:**
- Adds content block extraction logic to parse image and text blocks from `reply.content`
- Creates temporary directory for storing base64-decoded images
- Properly cleans up temp files in finally block
- Maintains backward compatibility with existing `reply.text` field
**Issues found:**
- File naming uses `Date.now()` which could cause collisions if multiple images are processed within the same millisecond
- Type casting bypasses TypeScript type safety (though this is a pragmatic workaround)
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge with one minor race condition that should be addressed
- The implementation correctly handles the core functionality of extracting and sending images from content blocks. Resource cleanup is properly implemented with try-finally. However, there's a potential file name collision issue using Date.now() for temp file naming that could cause failures under rapid successive image processing. The type casting is pragmatic but not ideal.
- Pay attention to `extensions/matrix/src/matrix/monitor/replies.ts:77` for the file naming race condition
<sub>Last reviewed commit: 73ca371</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#10721: fix for matrix media: destructure downloadContent return value in m...
by mklasen · 2026-02-06
77.1%
#8284: Fix: Webchat images now persist after sending
by vishaltandale00 · 2026-02-03
72.9%
#20278: Fix/matrix missing bot sdk dependency
by saurav470 · 2026-02-18
72.3%
#18219: fix: validate base64 image data before sending to LLM APIs
by Grynn · 2026-02-16
72.0%
#7845: Fix Matrix mention detection with URL-encoded user IDs
by emadomedher · 2026-02-03
72.0%
#7842: Fix Matrix mention detection for Element client (formatted_body links)
by emadomedher · 2026-02-03
71.7%
#10313: fix(matrix): fallback to authenticated media download (Matrix v1.11+)
by iter-next · 2026-02-06
71.5%
#4269: fix: support tool result image format in Control UI
by bobcyw · 2026-01-30
71.4%
#21042: fix(ui): render images in tool result messages
by Mellowambience · 2026-02-19
70.7%
#8852: fix(matrix): Await mxcToHttp to properly detect authenticated media...
by emadomedher · 2026-02-04
70.6%