Last active
October 2, 2016 00:20
-
-
Save MasayukiFukada/547946bfd698d8b12509b3c88f730e14 to your computer and use it in GitHub Desktop.
Webhookしたものを slack API にPOSTする Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'webrick' | |
| require 'json' | |
| require 'net/https' | |
| def apipost | |
| puts "apipost" | |
| uri = URI.parse("https://slack.com/api/chat.postMessage") | |
| http = Net::HTTP.new(uri.host, uri.port) | |
| http.use_ssl = true | |
| http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
| req = Net::HTTP::Post.new(uri.path) | |
| values = { | |
| 'token' => 'ここにキー', | |
| 'channel' => '#チャンネル', | |
| 'text' => '家テスト', | |
| 'icon_url' => 'http://piq.codeus.net/static/media/userpics/piq_132922_400x400.png', | |
| 'username' => '深田自宅bot', | |
| 'unfurl_links' => 'false' | |
| } | |
| req.set_form_data(values) | |
| res = http.request(req) | |
| end | |
| server = WEBrick::HTTPServer.new(Port: ARGV.first) | |
| server.mount_proc '/' do |req, res| | |
| result = JSON.parse(req.body) | |
| action = result["action"] | |
| comment = result["comment"] | |
| username = comment["user"]["login"] | |
| content = comment["body"] | |
| puts action + "しました: " + username + " = " + content | |
| apipost() | |
| end | |
| trap 'INT' do server.shutdown end | |
| server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment