Interchangeable Webhook API
I can POST to the inbound Slack API endpoint via CURL, but it doesn't work with the bottom value when I try. I am assuming formatting is disabled. How can I fix this?
parms = {text: text_for_slack, channel: "#customer_sessions", username: "SessionBot", icon_emoji: ":raised_hands:"}
x = Net::HTTP.post_form(URI.parse(ENV['SessionSlackURL'].to_s), parms.to_s)
+3
source to share
1 answer
You can post using two methods (text from weak config for incoming webhook):
You have two options to send data to the Webhook url above: Send JSON string as payload parameter in POST request Send JSON string as body of POST request
json in the body.
require "net/http"
require "uri"
require "json"
parms = {
text: text_for_slack,
channel: "#customer_sessions",
username: "SessionBot",
icon_emoji: ":raised_hands:"
}
uri = URI.parse(ENV['SessionSlackURL'])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.body = parms.to_json
response = http.request(request)
json as parameter
parms_form = {
"payload" => {
text: text_for_slack,
channel: "#customer_sessions",
username: "SessionBot",
icon_emoji:":raised_hands:"
}.to_json
}
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(parms_form)
+11
source to share