1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

slack: add CP channel prefix (#5249)

* 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 <felix@fontein.de>

* Update plugins/modules/notification/slack.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/notification/slack.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/notification/slack.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/5249-add-new-channel-prefix.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Денис Сперанский <d_speranskiy@head-point.ru>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
sprnza 2022-09-12 21:32:14 +03:00 committed by GitHub
parent 19e4b7d3ab
commit b5d311a171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -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).

View file

@ -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