Skip to content

Instantly share code, notes, and snippets.

@hyuki
Last active June 12, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/f7cbff819db8fc7220020b3aa2492231 to your computer and use it in GitHub Desktop.
Save hyuki/f7cbff819db8fc7220020b3aa2492231 to your computer and use it in GitHub Desktop.
slack-poster - upload your files to #general channel.
#!/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