diff --git a/README.md b/README.md index 2febe9f..3e227c1 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,13 @@ The message that is sent when the webhook is triggered. Supports formatting [as defined below](#formatting). +### `message_format` +The format the message is interpreted as. Must be one of: +- `plaintext` (default) +- `markdown` +- `html` + + ### `auth_type` This can be used to protect a webhook against unauthorized access. Can be one of `Basic` for HTTP basic auth with username and password or `Bearer` for bearer token auth. @@ -108,13 +115,6 @@ If `auth_type` is `Basic`, this must be the username and password, separated by If `auth_type` is `Bearer`, this is the token used for token bearer authorization, so requests must carry an `Authorization: Bearer ` header. -### `message_format` -The format the message is interpreted as. Must be one of: -- `plaintext` (default) -- `markdown` -- `html` - - ### `force_json` This setting takes a boolean and specifies whether the request body should be interpreted and parsed as json, even if the content type says otherwise. diff --git a/base-config.yaml b/base-config.yaml index 8b6da4d..387ce72 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -2,8 +2,8 @@ path: "/send" method: "POST" room: "!AAAAAAAAAAAAAAAAAA:example.com" message: "Hello world!" +message_format: "plaintext" auth_type: auth_token: -message_format: "plaintext" force_json: false ignore_empty_messages: false diff --git a/plugin.py b/plugin.py index cb6a765..12d7e1b 100644 --- a/plugin.py +++ b/plugin.py @@ -47,15 +47,22 @@ def do_update(self, helper: ConfigUpdateHelper) -> None: helper.copy("method") helper.copy("room") helper.copy("message") + helper.copy("message_format") helper.copy("auth_type") helper.copy("auth_token") - helper.copy("message_format") helper.copy("force_json") helper.copy("ignore_empty_messages") # validate base config as it also contains default values # for options not present in the source config. + # validate message_format + valid_message_formats = {"markdown", "plaintext", "html"} + message_format = helper.base["message_format"] + if message_format not in valid_message_formats: + raise ValueError(f"Invalid message_format '{message_format}' specified! " + f"Must be one of: {', '.join(valid_message_formats)}") + # validate auth_type and auth_token valid_auth_types = {"Basic", "Bearer"} auth_type = helper.base["auth_type"] @@ -71,13 +78,6 @@ def do_update(self, helper: ConfigUpdateHelper) -> None: raise ValueError(f"Invalid auth_token '{auth_token}' specified! For HTTP basic auth, it must contain " "a username and a password, separated by a colon (:).") - # validate message_format - valid_message_formats = {"markdown", "plaintext", "html"} - message_format = helper.base["message_format"] - if message_format not in valid_message_formats: - raise ValueError(f"Invalid message_format '{message_format}' specified! " - f"Must be one of: {', '.join(valid_message_formats)}") - class WebhookPlugin(Plugin):