fix: convert markdown to HTML in approval messages
Matrix needs formatted_body as HTML, not raw markdown. Added _md_to_html for bold/italic/code conversion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -217,12 +217,28 @@ class PipelineEngine:
|
||||
error=str(exc),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _md_to_html(text: str) -> str:
|
||||
"""Convert basic markdown to HTML for Matrix formatted_body."""
|
||||
import re as _re
|
||||
html = text
|
||||
# Bold: **text** -> <strong>text</strong>
|
||||
html = _re.sub(r'\*\*(.+?)\*\*', r'<strong>\1</strong>', html)
|
||||
# Italic: *text* -> <em>text</em>
|
||||
html = _re.sub(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)', r'<em>\1</em>', html)
|
||||
# Code: `text` -> <code>text</code>
|
||||
html = _re.sub(r'`(.+?)`', r'<code>\1</code>', html)
|
||||
# Newlines
|
||||
html = html.replace("\n", "<br>")
|
||||
return html
|
||||
|
||||
async def _execute_approval_step(
|
||||
self, step: dict, target_room: str, execution_id: str, timeout_s: int
|
||||
) -> str:
|
||||
"""Post approval message and wait for reaction."""
|
||||
message = step.get("message", "Approve this action?")
|
||||
formatted_msg = f"**Approval Required**\n\n{message}\n\nReact with \U0001f44d to approve or \U0001f44e to decline."
|
||||
body = f"**Approval Required**\n\n{message}\n\nReact with \U0001f44d to approve or \U0001f44e to decline."
|
||||
html = self._md_to_html(body)
|
||||
|
||||
# Send message and get event ID
|
||||
resp = await self.matrix_client.room_send(
|
||||
@@ -230,9 +246,9 @@ class PipelineEngine:
|
||||
message_type="m.room.message",
|
||||
content={
|
||||
"msgtype": "m.text",
|
||||
"body": formatted_msg,
|
||||
"body": body,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": formatted_msg.replace("\n", "<br>"),
|
||||
"formatted_body": html,
|
||||
},
|
||||
)
|
||||
event_id = resp.event_id if hasattr(resp, "event_id") else None
|
||||
|
||||
Reference in New Issue
Block a user