Browse Source

Slack <!channel|desc> & <!channel> support added (#856)

pull/863/head
Chris Caron 2 years ago committed by GitHub
parent
commit
be174c374f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      apprise/plugins/NotifySlack.py
  2. 7
      test/test_plugin_slack.py

22
apprise/plugins/NotifySlack.py

@ -354,6 +354,13 @@ class NotifySlack(NotifyBase):
r'>': '&gt;',
}
# To notify a channel, one uses <!channel|channel>
self._re_channel_support = re.compile(
r'(?P<match>(?:<|\&lt;)?[ \t]*'
r'!(?P<channel>[^| \n]+)'
r'(?:[ \t]*\|[ \t]*(?:(?P<val>[^\n]+?)[ \t]*)?(?:>|\&gt;)'
r'|(?:>|\&gt;)))', re.IGNORECASE)
# The markdown in slack isn't [desc](url), it's <url|desc>
#
# To accomodate this, we need to ensure we don't escape URLs that match
@ -455,6 +462,21 @@ class NotifySlack(NotifyBase):
lambda x: self._re_formatting_map[x.group()], body,
)
# Support <!channel|desc>, <!channel> entries
for match in self._re_channel_support.findall(body):
# Swap back any ampersands previously updaated
channel = match[1].strip()
desc = match[2].strip()
# Update our string
body = re.sub(
re.escape(match[0]),
'<!{channel}|{desc}>'.format(
channel=channel, desc=desc)
if desc else '<!{channel}>'.format(channel=channel),
body,
re.IGNORECASE)
# Support <url|desc>, <url> entries
for match in self._re_url_support.findall(body):
# Swap back any ampersands previously updaated

7
test/test_plugin_slack.py

@ -680,6 +680,10 @@ def test_plugin_slack_markdown(mock_get, mock_post):
<https://slack.com?arg=val&arg2=val2|Slack Link>.
We also want to be able to support <https://slack.com> links without the
description.
Channel Testing
<!channelA>
<!channelA|Description>
""")
# Send our notification
@ -700,4 +704,5 @@ def test_plugin_slack_markdown(mock_get, mock_post):
"of it's\nmarkdown.\n\nThis one has arguments we want to preserve:"\
"\n <https://slack.com?arg=val&arg2=val2|Slack Link>.\n"\
"We also want to be able to support <https://slack.com> "\
"links without the\ndescription."
"links without the\ndescription."\
"\n\nChannel Testing\n<!channelA>\n<!channelA|Description>"

Loading…
Cancel
Save