Created
November 8, 2014 14:58
-
-
Save eiel/8161dd7573d879eb4309 to your computer and use it in GitHub Desktop.
slack に投稿する。https://api.slack.com/methods/chat.postMessage
This file contains 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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'uri' | |
require 'net/http' | |
message = ARGV.join(" ") | |
host = `hostname -s` | |
if message.empty? | |
message = 'なにか終わったかも' | |
end | |
text = URI.escape(message) | |
token = ENV['SLACK_TOKEN'] | |
channel = "#random" | |
params = { | |
:text => message, | |
:token => token, | |
:channel => channel, | |
:username => host, | |
} | |
uri = URI::HTTPS.build(:host => "slack.com", :path => "/api/chat.postMessage") | |
uri.query = URI.encode_www_form(params) | |
Net::HTTP.get(uri) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment