fix(telegram): escape Markdown special chars in send_exec_approval

The command preview and description were wrapped in Markdown v1 inline
code (backticks) without escaping, causing Telegram API parse errors
when the command itself contained backticks or asterisks.

Fixes: 'Can't parse entities: can't find end of the entity'
This commit is contained in:
root 2026-04-14 23:03:34 +08:00 committed by Teknium
parent 4936b19144
commit 06d6903d3c

View file

@ -1076,10 +1076,13 @@ class TelegramAdapter(BasePlatformAdapter):
try:
cmd_preview = command[:3800] + "..." if len(command) > 3800 else command
# Escape backticks that would break Markdown v1 inline code parsing
safe_cmd = cmd_preview.replace("`", "'")
safe_desc = description.replace("`", "'").replace("*", "")
text = (
f"⚠️ *Command Approval Required*\n\n"
f"`{cmd_preview}`\n\n"
f"Reason: {description}"
f"`{safe_cmd}`\n\n"
f"Reason: {safe_desc}"
)
# Resolve thread context for thread replies