Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions src/sentinel/notify/telegram_email_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 9 additions & 2 deletions src/sentinel/notify/telegram_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ def send(self, text: str) -> Optional[str]:
logger.error(f"Failed to send notification: {e}")
return None

def _escape_markdown(self, text: str) -> str:
"""Escape special characters for Telegram MarkdownV2."""
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 = [
"_",
"*",
Expand Down