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

Fail if Slack API response is not OK with error message #9198

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -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).
Aohzan marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 4 additions & 1 deletion plugins/modules/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (channels:history,groups:history,mpim:history,im:history).
Aohzan marked this conversation as resolved.
Show resolved Hide resolved
- Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)).
type: str
version_added: 1.2.0
Expand Down Expand Up @@ -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:
Expand Down