slack-ruby / slack-ruby-client

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

Do I really need to instantiate a listening app to fire off a DM to Slack? #384

Closed slithernix closed 3 years ago

slithernix commented 3 years ago

Hi, I'm trying to just create a tiny program for occasional use that allows developers to send DMs of arbitrary text to people. Just a simple script that sends a DM to a target. Do I really need to set up an app that listens, create event subscriptions, etc? This is just a one way, fire it off kind of thing and the example code I see all references setting up an actual two-way bot.

dblock commented 3 years ago

The samples are for those realtime apps because doing what you're trying to do is that simple. See https://github.com/slack-ruby/slack-ruby-client#web-client-examples for how to get started. You'll need to obtain a token from slack that lets you send DMs and then it's a 1-liner.

slithernix commented 3 years ago

The samples are for those realtime apps because doing what you're trying to do is that simple. See https://github.com/slack-ruby/slack-ruby-client#web-client-examples for how to get started. You'll need to obtain a token from slack that lets you send DMs and then it's a 1-liner.

Ok, but, it seems like Slack really doesn't want to use legacy tokens anymore. Then if I click on the link to slack-ruby-bot-server to show an OAuth example, it is like this:

SlackRubyBotServer.configure do |config|
  config.oauth_version = :v2
  config.oauth_scope = ['channels:read', 'chat:write']
end

Can I not do this simple thing AND use OAuth? I must use a simple token?

dblock commented 3 years ago

So it sound like it wants you to boot an entire app and do oauth and then you get a token to use? That seems wrong. As you said you don't want to have a multi-tenet application, you just want to post to a channel. I would do more research or ask someone at Slack about it before trying to go this route.

Otherwise, I've faced a similar problem in https://github.com/dblock/strava-ruby-client where it wanted to do the oauth dance to get a token. I worked around it by writing a command line client that would do it for me (https://github.com/dblock/strava-ruby-cli#authentication). That's the only other thing I can think of.