Skip to content

Commit

Permalink
Merge pull request #197 from treydock/slack-post
Browse files Browse the repository at this point in the history
(#196) Fix Slack integration to use POST
  • Loading branch information
ripienaar authored Jul 1, 2024
2 parents 0eb3b5c + 93f503e commit ff25583
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 ff25583

Please sign in to comment.