我可以通过CURL POST到Slack传入的API端点,但是当尝试使用下面的它不能正常工作时.如果关闭,我假设格式化.我怎样才能解决这个问题? parms = {text: text_for_slack, channel: "#customer_sessions", use
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)
您可以使用两种方法发布(来自传入webhook的松弛配置文本):
You have two options for sending data to the Webhook URL above:
Send a JSON string as the payload parameter in a POST request
Send a JSON string as the body of a POST request
json在体内.
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作为参数
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)
