slack-ruby / slack-ruby-client

A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
MIT License
1.19k stars 214 forks source link

`files_upload` does nothing #479

Open andres-haku opened 1 year ago

andres-haku commented 1 year ago

I have tried the chat_postMessage method, and it works perfectly. However, when using the file_uploads method, it returns an OK status but doesn't post anything in my Slack channel.

Then tried with curl and successfully posted my file in the Slack channel.

What am I doing wrong? Why does it work with chat_postMessage but does not with the file_uploads method? I have to assume that my config, token, app permissions, etc. Is working properly. Otherwise, I wouldn't be able to post text messages with chat_postMessage.

I followed the docs as much as possible and took a quick look at the endpoints/files.rb file of this gem and I can't seem to find where I'm falling short.

# Gemfile

gem 'slack-ruby-client', '~> 0.11.1'
gem 'faraday', '0.9.0'
slack_message_params = {
  channel: '#andres-test',
  as_user: true,
  file: Faraday::UploadIO.new("#{tmp_path}/test.txt", 'text/plain'),
  filename: 'test.txt',
  title: 'test',
  initial_comment: 'Attached test file'
}

@client.file_uploads(slack_message_params) # => OK status, but doesn't post anything
curl -F file=@/path/to/file -F "initial_comment=test" -F channels=andres-test -H "Authorization: Bearer xoxb-my-token" https://slack.com/api/files.upload

# works!
dblock commented 1 year ago

I assume file_uploads is just a typo? The correct name is files_upload.

The next problem I see is channel. The API requires channels, and takes a comma-separated list. Try changing that?

We should add patches that ensure that "either a file or content parameter" are provided (from the documentation), and add support for channel (singular), and channels (array of strings), so that the caller can mix and match. PRs welcome!