Skip to content

Commit

Permalink
SlackReporter with preformatted rich text
Browse files Browse the repository at this point in the history
  • Loading branch information
vimagick authored Nov 16, 2023
1 parent 74671c3 commit 7719c5d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/urlwatch/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def submit(self):

def submit_chunk(self, webhook_url, text):
logger.debug("Sending {} request with text: {}".format(self.__kind__, text))
post_data = {"text": text}
post_data = self.prepare_post_data(text)
result = requests.post(webhook_url, json=post_data)
try:
if result.status_code == requests.codes.ok:
Expand All @@ -715,12 +715,31 @@ def submit_chunk(self, webhook_url, text):
result.content))
return result

def prepare_post_data(self, text):
return {
"blocks": [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_preformatted",
"elements": [
{"type": "text", "text": text}
]
}
]
}
]
}


class MattermostReporter(SlackReporter):
"""Send a message to a Mattermost channel"""

__kind__ = 'mattermost'

def prepare_post_data(self, text):
return {"text": text}

class DiscordReporter(TextReporter):
"""Send a message to a Discord channel"""
Expand Down

0 comments on commit 7719c5d

Please sign in to comment.