Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use the Client for the web server #63

Closed
klaustopher opened this issue Mar 29, 2016 · 9 comments
Closed

Re-use the Client for the web server #63

klaustopher opened this issue Mar 29, 2016 · 9 comments
Labels

Comments

@klaustopher
Copy link

Hey,

I have been playing around with the framework over the weekend and I want to implement a bot that listens to chat but also has some webhooks (i.e. hook it up to GitHub to react to events that happen with our pull-requests). I set it up like you did in the tutorial and everything worked when I stayed within the Slack world ...

But when I wanted to send something to the chat room from the web server I ran into an issue. The client property on the SlackMathbot::Bot is private and I cannot access it from the sinatra app. In #20 and #31 you basically suggest to use Slack::Web::Client.new directly... But since my bot already has a connection to the server open, I don't really see why it should be needed to create another connection to the Slack server.

Am I just missing a way to access the client directly?

@dblock
Copy link
Collaborator

dblock commented Mar 29, 2016

In theory I think there's no harm exposing client, outside of the bot, you might want to test it with .send(:client) and if that works feel free to PR a change. You might want to reach into client.web_client if you need the web one that was used to open the connection in the first place.

Also, generally, I'm interested in expanding slack-ruby-bot with support for web hooks and such, maybe merging parts or all of https://github.com/dblock/slack-bot-server or turning the latter into a framework (see slack-ruby/slack-ruby-bot-server#3).

@klaustopher
Copy link
Author

Ok, good, I thought I was really missing something when looking at the code. The "hack" with send(:client) is what I ended up doing, but it felt so ugly that I had to wash my hands after writing this code 😂

I'll take a look at the referenced issues. I think there's something missing between "Running a bot that only replies to chat" and "Running a full slack integration available to others" ;)

@dblock
Copy link
Collaborator

dblock commented Jun 22, 2016

@klaustopher I think https://github.com/dblock/slack-ruby-bot-server is the beginning of the answer for the missing link.

@klaustopher
Copy link
Author

@dblock Thanks, this looks good. I'll definitely take a look ;)

@dblock
Copy link
Collaborator

dblock commented Jul 1, 2016

This is related to https://github.com/dblock/slack-ruby-bot-server/issues/6.

I think we should either expose client as is, or delegate calls to it. Thoughts? PRs?

@CanisHelix
Copy link

Has there been any progress on exposing client? I have a bot running very nicely, but I'd like the ability to have the bot message users after a specific rails api call too. I'm not familiar with the send(:client) hack mentioned above, could someone elaborate a bit?

@kstole
Copy link
Collaborator

kstole commented Jul 13, 2017

This issue seems to revolve around the same discussion as supporting slash commands and webhooks.

I'm also extremely interested in this and I ran into the same issues as @klaustopher. I was previously using Lita, which includes a built-in web server, but this library is much nicer for working with Slack so it would be nice if it could also include a web server.

I'm not a Ruby expert. @dblock do you think it makes more sense to look into slack-ruby-bot-server or to try the hacky .send(:client)? @klaustopher do you have any sample code you could share for your .send(:client) solution?

@dblock
Copy link
Collaborator

dblock commented Jul 13, 2017

See my comment above for client, but generally I would like native webhook support in slack-ruby-bot-server.

@dblock
Copy link
Collaborator

dblock commented Jul 20, 2020

Slash commands and webhooks require a web server. I've released https://github.com/slack-ruby/slack-ruby-bot-server-events that has full support for those.

@dblock dblock closed this as completed Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants