format message using <p> tags, add support for view action

This commit is contained in:
⛧-440729 [sophie]
2024-09-16 13:45:50 +02:00
parent 256aa8f315
commit 0ba094394a

View File

@@ -190,6 +190,7 @@ class NtfyBot(Plugin):
tags = message.get("tags", None)
click = message.get("click", None)
attachment = message.get("attachment", None)
view_actions = [a for a in message.get("actions", []) if a.get("action", "") == "view"]
if tags:
(emoji, non_emoji) = parse_tags(self.log, tags)
@@ -202,28 +203,35 @@ class NtfyBot(Plugin):
html.escape(server), html.escape(topic))
# build title
if title and click:
html_content += "<h4>%s<a href=\"%s\">%s</a></h4>" % (
html_content += "<p><h4>%s<a href=\"%s\">%s</a></h4></p>" % (
emoji, html.escape(click), html.escape(title))
emoji = ""
elif title:
html_content += "<h4>%s%s</h4>" % (emoji, html.escape(title))
html_content += "<p><h4>%s%s</h4></p>" % (emoji, html.escape(title))
emoji = ""
# build body
if click and not title:
html_content += "%s<a href=\"%s\">%s</a>" % (
html_content += "<p>%s<a href=\"%s\">%s</a></p>" % (
emoji, html.escape(click), html.escape(body).replace("\n", "<br />"))
else:
html_content += emoji + html.escape(body).replace("\n", "<br />")
html_content += "<p>%s%s</p>" % (emoji, html.escape(body).replace("\n", "<br />"))
# add non-emoji tags
if tags:
html_content += "<br/><small>Tags: <code>%s</code></small>" % html.escape(
html_content += "<p><small>Tags: <code>%s</code></small></p>" % html.escape(
tags)
# add actions
if len(view_actions) > 0:
html_content += "<p>"
for action in view_actions:
html_content += "<a href=\"%s\">%s</a>" % (html.escape(action["url"]), html.escape(action["label"]))
html_content += "</p>"
# build attachment
if attachment:
html_content += "<br/><a href=\"%s\">View %s</a>" % (html.escape(
html_content += "<p><a href=\"%s\">View %s</a></p>" % (html.escape(
attachment["url"]), html.escape(attachment["name"]))
html_content += "</blockquote>"