Improve Matrix message body parsing with smart format detection - #13
Conversation
- Replace complex 6-path logic with simplified single-path approach - Add smart format detection: prefer plain text body, convert HTML to markdown - Use Matrix format field for reliable HTML detection, fall back to content analysis - Remove unused functions (isMarkdown, detectContentFormat) identified by linter - Fix linting issues (formatting, static check optimizations) - Maintain Matrix spec compliance: body=plain text, formatted_body=HTML - Preserve message formatting through HTML-to-markdown conversion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This seems the opposite of what we would want. If formatted text is available, that's what we should use. It is supposed to convert that code to markdown. |
We are receiving HTML for that, and checking their spec the only https://spec.matrix.org/latest/client-server-api/#mroommessage-msgtypes In the official python SDK, they provide the body field if set, either they remove the HTML from the formatted_body and return plain text: https://github.com/matrix-org/matrix-python-sdk/blob/master/matrix_client/room.py#L110-L116 I haven't set up a test environment yet, I need a local Matrix server, will try that later today. |
- Add docker-compose.yml with Synapse and PostgreSQL services - Configure Synapse with proper permissions and database collation - Add app service configuration for bridge registration - Set room list publication rules for bridge user - Update README with comprehensive setup instructions - Add bridge registration file to gitignore 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Only use formatted_body when it differs from body to avoid unnecessary HTML conversion. This improves handling of Matrix messages with rich formatting while maintaining backward compatibility with plain text messages. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Fix goimports formatting issue by replacing spaces with tabs in variable declaration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR improves Matrix message body parsing by implementing smart format detection that automatically converts HTML content to markdown format. The changes enhance the bridge's ability to properly handle formatted messages from Matrix clients while maintaining compatibility with Mattermost's markdown format.
- Enhanced message content extraction with HTML-to-markdown conversion
- Added development infrastructure with Matrix Synapse server setup
- Improved format detection logic using Matrix format fields and content analysis
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| server/sync_to_mattermost.go | Updated comment to reflect new smart format detection behavior |
| server/bridge_utils.go | Added HTML detection functions and enhanced message content extraction with format conversion |
| docker/synapse_config.yaml | Added Matrix Synapse server configuration for development testing |
| docker-compose.yml | Added Docker Compose setup for local Matrix server with PostgreSQL |
| README.md | Added comprehensive documentation for local development setup with Matrix Synapse |
| } | ||
|
|
||
| return "" | ||
| return content |
There was a problem hiding this comment.
The function can return an empty string when event.Content["body"] doesn't exist and no formatted_body is processed. The fallback to plain body extraction was removed but not properly replaced.
Summary
Changes Made
Message Parsing Improvements
extractMatrixMessageContent: Automatically converts HTML content to markdown using existing conversion functionsDevelopment Setup
🤖 Generated with Claude Code and simplified manually.