Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slack: add CP channel prefix #5249

Merged
merged 10 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/5249-add-new-channel-prefix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- slack - fix message update for channels which start with ``CP``. When ``message-id`` was passed it failed for channels which started with ``CP`` because the ``#`` symbol was added before the ``channel_id`` (https://github.com/ansible-collections/community.general/pull/5249).
7 changes: 5 additions & 2 deletions plugins/modules/notification/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
message_id:
description:
- Optional. Message ID to edit, instead of posting a new message.
Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)).
- If supplied I(channel_id) must be in form of C(C0xxxxxxx). use C({{ slack_response.channel_id }}) to get I(channel_id) from previous task run.
- Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)).
type: str
version_added: 1.2.0
username:
Expand Down Expand Up @@ -234,6 +235,8 @@
- name: Edit message
community.general.slack:
token: thetoken/generatedby/slack
# The 'channel' option does not accept the channel name. It must use the 'channel_id',
# which can be retrieved for example from 'slack_response' from the previous task.
channel: "{{ slack_response.channel }}"
msg: Deployment complete!
message_id: "{{ slack_response.ts }}"
Expand Down Expand Up @@ -294,7 +297,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', 'GF', 'G0')):
if channel.startswith(('#', '@', 'C0', 'GF', 'G0', 'CP')):
payload['channel'] = channel
else:
payload['channel'] = '#' + channel
Expand Down