gpt4 book ai didi

ruby-on-rails - Slack 传入 Webhook API

转载 作者:行者123 更新时间:2023-12-04 06:26:28 24 4
gpt4 key购买 nike

我可以通过 CURL POST 到 Slack 传入的 API 端点,但是当尝试使用下面的时它不起作用。如果关闭,我假设格式。我怎样才能解决这个问题?

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)

关于ruby-on-rails - Slack 传入 Webhook API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30910950/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com