From 011aeb064603c0339d953277913754ac14e6286f Mon Sep 17 00:00:00 2001 From: Richard Tuin Date: Sun, 31 Jul 2022 23:35:07 +0200 Subject: [PATCH] Slack: Add support for (some) groups (#5019) * Slack: Add support for (some) groups Some of the older private channels in the workspace I'm working in have channel ID's starting with `G0` and `GF` and this resulted to false positive `channel_not_found` errors. I've added these prefixes to the list to maintain as much backwards compatibility as possible. Ideally the auto-prefix of the channel name with `#` is dropped entirely, given the Channel ID's have become more dominant in the Slack API over the past years. * Add changelog fragment for slack channel prefix fix * Update changelogs/fragments/5019-slack-support-more-groups.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 3fe9592cf1505a78b243ed4552aba06423ee948b) --- changelogs/fragments/5019-slack-support-more-groups.yml | 2 ++ plugins/modules/notification/slack.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/5019-slack-support-more-groups.yml diff --git a/changelogs/fragments/5019-slack-support-more-groups.yml b/changelogs/fragments/5019-slack-support-more-groups.yml new file mode 100644 index 00000000000..184bab353a5 --- /dev/null +++ b/changelogs/fragments/5019-slack-support-more-groups.yml @@ -0,0 +1,2 @@ +bugfixes: + - slack - fix incorrect channel prefix ``#`` caused by incomplete pattern detection by adding ``G0`` and ``GF`` as channel ID patterns (https://github.com/ansible-collections/community.general/pull/5019). \ No newline at end of file diff --git a/plugins/modules/notification/slack.py b/plugins/modules/notification/slack.py index bdc839f9a89..f10d4003d64 100644 --- a/plugins/modules/notification/slack.py +++ b/plugins/modules/notification/slack.py @@ -293,7 +293,7 @@ def build_payload_for_slack(text, channel, thread_id, username, icon_url, icon_e # With a custom color we have to set the message as attachment, and explicitly turn markdown parsing on for it. payload = dict(attachments=[dict(text=escape_quotes(text), color=color, mrkdwn_in=["text"])]) if channel is not None: - if channel.startswith(('#', '@', 'C0')): + if channel.startswith(('#', '@', 'C0', 'GF', 'G0')): payload['channel'] = channel else: payload['channel'] = '#' + channel