notifier: Add body_format as an option

This lets you format the messages through apprise a little nicer

Signed-off-by: Chris Thornton <cwgthornton@gmail.com>
This commit is contained in:
Chris Thornton authored and Eric Callahan committed 2023-05-07 05:59:43 -04:00
1 parent 6c7dfe5921
commit b21f177e95
2 files changed
+9

No files matched your search

+3
View File
@@ -2343,6 +2343,9 @@ body: "Your printer status has changed to {event_name}"
# is received from Klippy using a gcode_macro.
# The default is a body containining the "name" of the notification as entered
# in the section header.
body_format:
# The formatting to use for the body, can be `text`, `html` and `markdown`.
# The default is `text`.
title:
# The optional title of the notification. This option accepts Jinja2 templates,
# the template will receive a context with the same fields as the body. The
+6
View File
@@ -182,6 +182,10 @@ class NotifierInstance:
self.title = config.gettemplate("title", None)
self.body = config.gettemplate("body", None)
upper_body_format = config.get("body_format", 'text').upper()
if not hasattr(apprise.NotifyFormat, upper_body_format):
raise config.error(f"Invalid body_format for {config.get_name()}")
self.body_format = getattr(apprise.NotifyFormat, upper_body_format)
self.events: List[str] = config.getlist("events", separator=",")
self.apprise.add(self.url)
@@ -191,6 +195,7 @@ class NotifierInstance:
"url": self.config.get("url"),
"title": self.config.get("title", None),
"body": self.config.get("body", None),
"body_format": self.config.get("body_format", None),
"events": self.events,
"attach": self.attach
}
@@ -251,6 +256,7 @@ class NotifierInstance:
attachments.append(str(attach_path))
await self.apprise.async_notify(
rendered_body.strip(), rendered_title.strip(),
body_format=self.body_format,
attach=None if not attachments else attachments
)