From b317b4e3fd35e3fdaf0b335c5b06fd512fbb2467 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:54:44 +0000 Subject: [PATCH 1/4] Initial plan From 484def240043067180fd47c9da34bf8ac56592a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 10:01:39 +0000 Subject: [PATCH 2/4] Refactor: Remove duplicated _escape_markdown method Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com> --- .../notify/telegram_email_notifier.py | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/sentinel/notify/telegram_email_notifier.py b/src/sentinel/notify/telegram_email_notifier.py index 6fb0818..b049383 100644 --- a/src/sentinel/notify/telegram_email_notifier.py +++ b/src/sentinel/notify/telegram_email_notifier.py @@ -60,42 +60,9 @@ def _format_email_notification( # Format the message with emojis and markdown message = ( f"📧 *Important Email Alert*\n\n" - f"*From:* {self._escape_markdown(email.sender)}\n" - f"*Subject:* {self._escape_markdown(email.subject)}\n\n" - f"*Summary:* {self._escape_markdown(summary)}" + f"*From:* {self.notifier._escape_markdown(email.sender)}\n" + f"*Subject:* {self.notifier._escape_markdown(email.subject)}\n\n" + f"*Summary:* {self.notifier._escape_markdown(summary)}" ) return message - - def _escape_markdown(self, text: str) -> str: - """Escape special characters for Telegram MarkdownV2. - - Args: - text: Text to escape - - Returns: - Escaped text safe for MarkdownV2 - """ - special_chars = [ - "_", - "*", - "[", - "]", - "(", - ")", - "~", - "`", - ">", - "#", - "+", - "-", - "=", - "|", - "{", - "}", - ".", - "!", - ] - for char in special_chars: - text = text.replace(char, f"\\{char}") - return text From 1cbf98e32cf6d376c8e632ee2b9977ae8323d90c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 10:05:19 +0000 Subject: [PATCH 3/4] Make escape_markdown public for proper encapsulation Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com> --- src/sentinel/notify/telegram_email_notifier.py | 6 +++--- src/sentinel/notify/telegram_notifier.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sentinel/notify/telegram_email_notifier.py b/src/sentinel/notify/telegram_email_notifier.py index b049383..6f6b6dd 100644 --- a/src/sentinel/notify/telegram_email_notifier.py +++ b/src/sentinel/notify/telegram_email_notifier.py @@ -60,9 +60,9 @@ def _format_email_notification( # Format the message with emojis and markdown message = ( f"📧 *Important Email Alert*\n\n" - f"*From:* {self.notifier._escape_markdown(email.sender)}\n" - f"*Subject:* {self.notifier._escape_markdown(email.subject)}\n\n" - f"*Summary:* {self.notifier._escape_markdown(summary)}" + f"*From:* {self.notifier.escape_markdown(email.sender)}\n" + f"*Subject:* {self.notifier.escape_markdown(email.subject)}\n\n" + f"*Summary:* {self.notifier.escape_markdown(summary)}" ) return message diff --git a/src/sentinel/notify/telegram_notifier.py b/src/sentinel/notify/telegram_notifier.py index c5b3507..cc58735 100644 --- a/src/sentinel/notify/telegram_notifier.py +++ b/src/sentinel/notify/telegram_notifier.py @@ -61,7 +61,7 @@ def send(self, text: str) -> Optional[str]: logger.error(f"Failed to send notification: {e}") return None - def _escape_markdown(self, text: str) -> str: + def escape_markdown(self, text: str) -> str: """Escape special characters for Telegram MarkdownV2.""" special_chars = [ "_", From fab295d4bf67e7fc1f3c03516270e411c07a8b02 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 10:06:51 +0000 Subject: [PATCH 4/4] Improve documentation for public escape_markdown method Co-authored-by: pmxi <64939659+pmxi@users.noreply.github.com> --- src/sentinel/notify/telegram_notifier.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sentinel/notify/telegram_notifier.py b/src/sentinel/notify/telegram_notifier.py index cc58735..f77f649 100644 --- a/src/sentinel/notify/telegram_notifier.py +++ b/src/sentinel/notify/telegram_notifier.py @@ -62,7 +62,14 @@ def send(self, text: str) -> Optional[str]: return None def escape_markdown(self, text: str) -> str: - """Escape special characters for Telegram MarkdownV2.""" + """Escape special characters for Telegram MarkdownV2. + + Args: + text: Text to escape + + Returns: + Escaped text safe for MarkdownV2 + """ special_chars = [ "_", "*",