Skip to content

Commit

Permalink
(#196) Fix Slack integration to use POST
Browse files Browse the repository at this point in the history
The API docs for chat.postMessage show the request should use POST and the token should be passed using a header as bearer token

Fixes #196
  • Loading branch information
treydock committed Jun 26, 2024
1 parent 0eb3b5c commit 93f503e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/mcollective/util/playbook/tasks/slack_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,21 @@ def to_execution_result(results)

def run
https = choria.https(:target => "slack.com", :port => 443)
path = "/api/chat.postMessage?token=%s&username=%s&channel=%s&icon_url=%s&attachments=%s" % [
CGI.escape(@token),
CGI.escape(@username),
CGI.escape(@channel),
CGI.escape(@icon),
CGI.escape(attachments.to_json)
]
path = "/api/chat.postMessage"
headers = {
"Content-type" => "application/json; charset=utf-8",
"Authorization" => "Bearer %s" % @token
}
params = {
"username" => @username,
"channel" => @channel,
"icon_url" => @icon,
"attachments" => attachments,
}
post = choria.http_post(path, headers)
post.body = params.to_json

resp, data = https.request(choria.http_get(path))
resp, data = https.request(post)
data = JSON.parse(data || resp.body)

if resp.code == "200" && data["ok"]
Expand Down

0 comments on commit 93f503e

Please sign in to comment.