diff --git a/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml b/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml new file mode 100644 index 00000000000..56ab25f578e --- /dev/null +++ b/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml @@ -0,0 +1,2 @@ +bugfixes: + - slack - fail if Slack API response is not OK with error message (https://github.com/ansible-collections/community.general/pull/9198). diff --git a/plugins/modules/slack.py b/plugins/modules/slack.py index 41dd4f5dba2..58893b0f42c 100644 --- a/plugins/modules/slack.py +++ b/plugins/modules/slack.py @@ -76,7 +76,8 @@ message_id: description: - Optional. Message ID to edit, instead of posting a new message. - - If supplied O(channel) must be in form of C(C0xxxxxxx). use C({{ slack_response.channel_id }}) to get RV(ignore:channel_id) from previous task run. + - If supplied O(channel) must be in form of C(C0xxxxxxx). use C({{ slack_response.channel }}) to get RV(ignore:channel) from previous task run. + - The token needs history scope to get information on the message to edit (C(channels:history,groups:history,mpim:history,im:history)). - Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)). type: str version_added: 1.2.0 @@ -391,6 +392,8 @@ def get_slack_message(module, token, channel, ts): if info['status'] != 200: module.fail_json(msg="failed to get slack message") data = module.from_json(response.read()) + if data.get('ok') is False: + module.fail_json(msg="failed to get slack message: %s" % data) if len(data['messages']) < 1: module.fail_json(msg="no messages matching ts: %s" % ts) if len(data['messages']) > 1: