Skip to content

Commit

Permalink
Merge pull request #4 from ryanlerch/no-empty-messages
Browse files Browse the repository at this point in the history
Only send the message if there is a message
  • Loading branch information
jkhsjdhjs authored Jan 4, 2024
2 parents 7415356 + ed7e239 commit 35beaad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Otherwise it will be sent as Markdown.
### `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.

### `ignore_empty_messages`
This setting takes a boolean and specifies whether a message should be sent if the message is empty. If `false` (the default) a message will be send for every
successful message consumed by the webhook. If `true` if the template generates an empty message, no message is sent to the matrix client.



## Formatting
Expand Down
1 change: 1 addition & 0 deletions base-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ auth_type:
auth_token:
markdown: false
force_json: false
ignore_empty_messages: false
6 changes: 6 additions & 0 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("auth_token")
helper.copy("markdown")
helper.copy("force_json")
helper.copy("ignore_empty_messages")


class WebhookPlugin(Plugin):
Expand Down Expand Up @@ -128,6 +129,11 @@ def unauthorized(text):
if isinstance(message, Response):
return message

if self.config["ignore_empty_messages"] and not message:
self.log.info(f"Not Sending message to room. {req} was successfully processed, "
f"but the template generated an empty message.")
return Response()

self.log.info(f"Sending message to room {room}: {message}")
try:
await (self.client.send_markdown if self.config["markdown"] else self.client.send_text)(room, message)
Expand Down

0 comments on commit 35beaad

Please sign in to comment.