From b21f177e951f70a0967b4967b1d43d2bfde02e1b Mon Sep 17 00:00:00 2001 From: Chris Thornton Date: Fri, 5 May 2023 15:18:22 -0700 Subject: [PATCH] notifier: Add `body_format` as an option This lets you format the messages through apprise a little nicer Signed-off-by: Chris Thornton --- docs/configuration.md | 3 +++ moonraker/components/notifier.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 8c589af..75e3aa9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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 diff --git a/moonraker/components/notifier.py b/moonraker/components/notifier.py index 241d351..8d7eba8 100644 --- a/moonraker/components/notifier.py +++ b/moonraker/components/notifier.py @@ -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 )