From b5d311a171334187e8b0292342517da93d1aa5f0 Mon Sep 17 00:00:00 2001 From: sprnza Date: Mon, 12 Sep 2022 21:32:14 +0300 Subject: [PATCH] slack: add CP channel prefix (#5249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add CP channel prefix * changelog added * altered docs * added description for docs change * fix line length * Update plugins/modules/notification/slack.py Co-authored-by: Felix Fontein * Update plugins/modules/notification/slack.py Co-authored-by: Felix Fontein * Update plugins/modules/notification/slack.py Co-authored-by: Felix Fontein * Update plugins/modules/notification/slack.py Co-authored-by: Felix Fontein * Update changelogs/fragments/5249-add-new-channel-prefix.yml Co-authored-by: Felix Fontein Co-authored-by: Денис Сперанский Co-authored-by: Felix Fontein --- changelogs/fragments/5249-add-new-channel-prefix.yml | 2 ++ plugins/modules/notification/slack.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/5249-add-new-channel-prefix.yml diff --git a/changelogs/fragments/5249-add-new-channel-prefix.yml b/changelogs/fragments/5249-add-new-channel-prefix.yml new file mode 100644 index 0000000000..9740e3a186 --- /dev/null +++ b/changelogs/fragments/5249-add-new-channel-prefix.yml @@ -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). diff --git a/plugins/modules/notification/slack.py b/plugins/modules/notification/slack.py index 154a8ccffd..46602a5d16 100644 --- a/plugins/modules/notification/slack.py +++ b/plugins/modules/notification/slack.py @@ -69,7 +69,8 @@ options: 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: @@ -234,6 +235,8 @@ EXAMPLES = """ - 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 }}" @@ -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