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

How to react to Slack Events? #138

Closed
sazzer opened this issue Jan 7, 2020 · 3 comments
Closed

How to react to Slack Events? #138

sazzer opened this issue Jan 7, 2020 · 3 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@sazzer
Copy link

sazzer commented Jan 7, 2020

I get the impression from the code that this library is capable of subscribing to, and receiving, events from the Slack API. For example, the MEMBER_JOINED_CHANNEL or MESSAGE events are invaluable to create an interactive bot.

However, I can't work out how to do this. I can't see any code that actually returns events, any way to subscribe to them, or anything like that.

What am I missing? Or is this future functionality?

Cheers

@lightbody
Copy link
Contributor

Hi there, I can probably shed some light: the short answer is, no, nothing in the library actually help you receive the initial callbacks from events you subscribe to or from interaction callbacks. You will need to stand up a web server to accept the POST payloads. This library is 95% an API to Slack's web services API (making outgoing requests).

However, there are some nice classes you can use to deserialize said payloads. Namely:

  • The body of an incoming event is JSON and can be parsed by Jackson into a SlackEventWrapper. Not every event type will parse to something useful (see SlackEventType) but many will and it's easy to patch this library to handle other events you're interested in.
  • The body of an incoming interaction is form encoded and includes two form fields: response_url and payload. The payload is itself JSON and can be parsed into a SlackInteractiveCallback. If you're using BlockKit (the preferred model these days), the subclass BlockActions will have all sorts of good stuff.

Another thing you may bump into is that this library doesn't currently help with two outgoing calls you may need make:

  • An API call to /oauth.v2.access, which finalizes the OAuth-like authentication and returns user- and bot-tokens.
  • API calls to the response_url that you receive on certain interactions. You'll need to submit the POST if you wish to update a message that a user interacted with. However, you can use the ChatPostMessageParams class to serialize the body of that payload.

I hope that helps. Good luck!

@szabowexler szabowexler added the question Further information is requested label Jan 8, 2020
@szabowexler
Copy link
Collaborator

Re: oauth.access, I think this ties into #98 (it's a gap in the API we support as of right now).

@szabowexler szabowexler added the good first issue Good for newcomers label Jan 28, 2020
@szabowexler
Copy link
Collaborator

I'm going to close this issue, since this seems well handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants