Last active
June 12, 2018 06:21
-
-
Save hyuki/f7cbff819db8fc7220020b3aa2492231 to your computer and use it in GitHub Desktop.
slack-poster - upload your files to #general channel.
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 | |
# See https://api.slack.com/methods/files.upload | |
# See https://qiita.com/ykhirao/items/3b19ee6a1458cfb4ba21 | |
# Set your env var: SLACK_POSTER_TOKEN. | |
# $ grep SLACK_POSTER_TOKEN ~/.bash_profile | |
# export SLACK_POSTER_TOKEN=xxxx-9999999999-999999999999-ZZZZZZZZZZZZZZZZZZZZZZZZ | |
require 'json' | |
require 'slack/poster' | |
def main | |
if ARGV.length == 0 | |
puts "Usage: slack-poster filename.png ... " | |
puts "Post filename.png ... to your slack channel." | |
abort | |
end | |
ARGV.each do |filename| | |
json = `curl -F file=@#{filename} -F channels=#general -F token=#{ENV['SLACK_POSTER_TOKEN']} https://slack.com/api/files.upload` | |
result = JSON.parse(json) | |
if !result["ok"] | |
abort("ERROR") | |
else | |
puts result["file"]["permalink"] | |
end | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cf. https://api.slack.com/methods/files.upload
cf. https://qiita.com/ykhirao/items/3b19ee6a1458cfb4ba21