|
|
@ -580,17 +580,34 @@ class Apprise(HttpTransport): |
|
|
|
|
|
|
|
|
|
|
|
class MsTeams(HttpTransport): |
|
|
|
def escape_md(self, s): |
|
|
|
# Escape special HTML characters |
|
|
|
s = escape(s) |
|
|
|
# Escape characters that have special meaning in Markdown |
|
|
|
for c in r"\`*_{}[]()#+-.!|": |
|
|
|
s = s.replace(c, "\\" + c) |
|
|
|
return s |
|
|
|
|
|
|
|
def notify(self, check): |
|
|
|
text = tmpl("msteams_message.json", check=check) |
|
|
|
payload = json.loads(text) |
|
|
|
|
|
|
|
# Escape special HTML characters in check's name |
|
|
|
safe_name = escape(check.name_then_code()) |
|
|
|
# Escape characters that have special meaning in Markdown |
|
|
|
for c in r"\`*_{}[]()#+-.!|": |
|
|
|
safe_name = safe_name.replace(c, "\\" + c) |
|
|
|
|
|
|
|
payload["text"] = f"“{safe_name}” is {check.status.upper()}." |
|
|
|
# MS Teams escapes HTML special characters in the summary field. |
|
|
|
# It does not interpret summary content as Markdown. |
|
|
|
name = check.name_then_code() |
|
|
|
payload["summary"] = f"“{name}” is {check.status.upper()}." |
|
|
|
|
|
|
|
# MS teams *strips* HTML special characters from the title field. |
|
|
|
# To avoid that, we use escape(). |
|
|
|
# It does not interpret title as Markdown. |
|
|
|
safe_name = escape(name) |
|
|
|
payload["title"] = f"“{safe_name}” is {check.status.upper()}." |
|
|
|
|
|
|
|
# MS teams allows some HTML in the section text. |
|
|
|
# It also interprets the section text as Markdown. |
|
|
|
# We want to display the raw content, angle brackets and all, |
|
|
|
# so we run escape() and then additionally escape Markdown: |
|
|
|
payload["sections"][0]["text"] = self.escape_md(check.desc) |
|
|
|
|
|
|
|
return self.post(self.channel.value, json=payload) |
|
|
|
|
|
|
|