Skip to content

Commit

Permalink
Slack: Add support for (some) groups (#5019)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 3fe9592)
  • Loading branch information
rtuin authored and patchback[bot] committed Jul 31, 2022
1 parent 083bd49 commit 011aeb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/5019-slack-support-more-groups.yml
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion plugins/modules/notification/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 011aeb0

Please sign in to comment.