Skip to content

Instantly share code, notes, and snippets.

@neerajkumar
Created December 15, 2017 05:56
Show Gist options
  • Save neerajkumar/1ac6c7b6ff93b4e15f2eda082fafcf4d to your computer and use it in GitHub Desktop.
Save neerajkumar/1ac6c7b6ff93b4e15f2eda082fafcf4d to your computer and use it in GitHub Desktop.
A ruby script to upload any file on any slack channel.
require 'rest-client'
require 'json'
require 'byebug'
def upload
options = {
# Slack channel webhook integration token
token: '123456789-xxxaaaddffggbbb',
file: File.new("error_hotels.csv", 'rb'),
filename: "error_hotels.csv",
title: "Error Hotels",
# Slack Channel access token
channels: 'D4CJJRAH5'
}
res = RestClient.post 'https://slack.com/api/files.upload', options
byebug
# Return the uploaded file's ID
JSON.parse(res.body)["file"]["id"]
end
upload()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment