slack-ruby / slack-ruby-bot-server-events

Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
MIT License
71 stars 10 forks source link

Handle multiple events in a single configure block #16

Open Altonymous opened 2 years ago

Altonymous commented 2 years ago

Could you give me an overview of where I could find the code that sets up event collection?

I looked through the code and couldn't figure out how it's being done. I think it would be great to be able to pass in multiple events that are similar in type.

Example

SlackRubyBotServer::Events.configure do |config|
  config.on :event, ['event_callback', ['pin_added', 'pin_removed']] do |event|

Right now I'm handling it like this..

SlackRubyBotServer::Events.configure do |config|
  config.on :event, ['event_callback'] do |event|
    event_type = event[:event][:type]

    case event_type
    when 'pin_added', 'pin_removed'
      # Do Pin Stuff
    when 'reaction_added', 'reaction_removed'
      # Do Reaction Stuff
    else
      # Do Log & Error Handling Stuff
    end

    { ok: true }
  end
end
dblock commented 2 years ago

This belongs in slack-ruby-bot-server-events, the code is here. I'll transfer the issue, this is a good idea.