ruby-on-rails – Slack Incoming Webhook API

ruby-on-rails – Slack Incoming Webhook API,第1张

概述我可以通过CURL POST到Slack传入的API端点,但是当尝试使用下面的它不能正常工作时.如果关闭,我假设格式化.我怎样才能解决这个问题? parms = {text: text_for_slack, channel: "#customer_sessions", username: "SessionBot", icon_emoji: ":raised_hands:"}x = Net::HT 我可以通过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,icon_emoji: ":raised_hands:"}uri = URI.parse(ENV['SessionSlackURL'])http = Net::http.new(uri.host,uri.port)http.use_ssl = truerequest = Net::http::Post.new(uri.request_uri)request.body = parms.to_Jsonresponse = http.request(request)

Json作为参数

parms_form = {     "payload" => {        text: text_for_slack,icon_emoji:":raised_hands:"        }.to_Json    }request = Net::http::Post.new(uri.request_uri)request.set_form_data(parms_form)
总结

以上是内存溢出为你收集整理的ruby-on-rails – Slack Incoming Webhook API全部内容,希望文章能够帮你解决ruby-on-rails – Slack Incoming Webhook API所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1244741.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存