mirror of
https://github.com/caronc/apprise.git
synced 2025-01-07 14:39:51 +01:00
Slack <!channel|desc> & <!channel> support added (#856)
This commit is contained in:
parent
6144a79513
commit
be174c374f
@ -354,6 +354,13 @@ class NotifySlack(NotifyBase):
|
||||
r'>': '>',
|
||||
}
|
||||
|
||||
# To notify a channel, one uses <!channel|channel>
|
||||
self._re_channel_support = re.compile(
|
||||
r'(?P<match>(?:<|\<)?[ \t]*'
|
||||
r'!(?P<channel>[^| \n]+)'
|
||||
r'(?:[ \t]*\|[ \t]*(?:(?P<val>[^\n]+?)[ \t]*)?(?:>|\>)'
|
||||
r'|(?:>|\>)))', 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
|
||||
|
@ -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…
Reference in New Issue
Block a user