From 11369a78f90378460fda85f5a3f8c8d5b92ec343 Mon Sep 17 00:00:00 2001 From: Dylan Socolobsky Date: Fri, 10 Apr 2026 18:02:57 -0300 Subject: [PATCH] fix(telegram): handle parentheses in URLs during MarkdownV2 link conversion The link regex in format_message used [^)]+ for the URL portion, which stopped at the first ) character. URLs with nested parentheses (e.g. Wikipedia links like Python_(programming_language)) were improperly parsed. Use a better regex, which is the same the Slack adapter uses. --- gateway/platforms/telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index 01bcf4da9a..67be808be4 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -2075,7 +2075,7 @@ class TelegramAdapter(BasePlatformAdapter): url = m.group(2).replace('\\', '\\\\').replace(')', '\\)') return _ph(f'[{display}]({url})') - text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', _convert_link, text) + text = re.sub(r'\[([^\]]+)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)', _convert_link, text) # 4) Convert markdown headers (## Title) → bold *Title* def _convert_header(m):