-5

I'm trying to use the slack-ruby-client gem. Ive made a Slack app and have all the client id, secret, etc. But i cant work out what i am supposed to do with them. In that gem it has the following: how to send a message.

Slack.configure do |config|
 config.token = SLACK_VERIFICATION_TOKEN
 raise 'Missing SLACK_VERIFICATION_TOKEN' unless config.token
end
client = Slack::Web::Client.new
client.auth_test
client.chat_postMessage(channel: '#channel_name', text: 'Hello World', as_user: true)

but this complains:

Slack::Web::Api::Errors::InvalidAuth: invalid_auth

which makes sense as i haven't done the auth with the id and secret. But how do i actually do that?

asked Nov 7, 2025 at 10:00
1
  • Thanks - forgive my ignorance but that seems to be about running an oauth server whereas i just need a client to communicate with slack. I might be really missing the point though. Would you mind explaining? Commented Nov 7, 2025 at 14:59

1 Answer 1

-1

It turns out that the Invalid Auth wasn't about the API key/secret at all, and that i didn't need them. What i needed to do was to set up the Slack app properly within my company's Slack workspace. That app has permission to write messages and upload files, and i add it into the channels i want it to be able to post to. Then, it generates a token (starting with "xoxb-") and that's what i'm using for SLACK_VERIFICATION_TOKEN. That was the only constant that i needed.

So the error really was just that i hadn't set the app/bot up properly. I think the first time I did it was the top level app token but i really needed to token for the bot that it contains, or something along those lines, after the app had been added to my workspace.

This is how i send the attachment, after i got the basic messaging working:


#files_upload_v2 uses the ID of the channel, not the name: this can be seen in the url
#if you're on the web version: eg the #yustudio channel is https://app.slack.com/client/T02BU43AG/G01NASDQTVK4
#the channel id is the last part, "G01NASDQTVK4"
channel_id = "G01NASDQTVK4"
string = "Here is the attachment"
options = {:attachment => "/path/to/myfile.json"}
upload_options = {
 filename: File.basename(options[:attachment]), # this is used for the file title, unless a :title option is provided
 content: File.read(options[:attachment]), # the contents of the file
 channels: [channel_id], # channel IDs to share the file to
 title: string
}
if options[:comment].not_blank?
 upload_options[:initial_comment] = options[:comment]
end
client.files_upload_v2(upload_options)
answered Nov 8, 2025 at 16:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.