LoginSignup
2
3

More than 5 years have passed since last update.

SlackのWebHookにPOSTするためだけの最小限のRubyスクリプト

Last updated at Posted at 2019-01-31

本体

https://WEBHOOKURL だけ書き換えてください。

sendslak.rb
require 'net/http'
require 'uri'
require 'json'

body = STDIN.read

uri = URI.parse('https://WEBHOOKURL')
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/json'
request.body = JSON.dump('text' => body)

Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

使い方

bash
echo hello | ruby sendslak.rb

ポイント

  • あちこちで使うから、標準モジュールのみで動くruby
  • プログラムの中に組み込むのがイヤなので、標準入出力を介してやることで、いろんなコマンドの出力結果をSlackに送れる
2
3
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
2
3