20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby でWebhook にPOST する方法

Posted at
require 'net/http'
require 'uri'
require 'json'

uri  = URI.parse('Webhook URL を指定する')
params = { text: 'POST したいメッセージ' }
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start do
  request = Net::HTTP::Post.new(uri.path)
  request.set_form_data(payload: params.to_json)
  http.request(request)
end

メソッド化しておくと、何か通知するときに便利。

Slack Incoming Webhooks

params に指定するハッシュデータは公式ドキュメントを参考に設定すればOK
https://api.slack.com/incoming-webhooks

20
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?