7
2

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 で Slack 通知サンプル

Posted at

いつも忘れるのでメモしておきます。

script.rb
require "net/http"
require "json"
puts "start script.rb 🌝"
SLACK_URL = "https://hooks.slack.com/services/***/***"

def talk_to_slack
  params = {
    text: "ruby",
  }
  notify_to_slack(params)
end

def notify_to_slack(params)
  uri = URI.parse(SLACK_URL)
  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
end

talk_to_slack
7
2
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
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?