Skip to content

Instantly share code, notes, and snippets.

@m-kind
Created October 25, 2017 20:13
Show Gist options
  • Save m-kind/bc1495cf4b15901877b69bda449606d0 to your computer and use it in GitHub Desktop.
Save m-kind/bc1495cf4b15901877b69bda449606d0 to your computer and use it in GitHub Desktop.
basic routing functionality for slack-ruby-bot
class SlackRouter
def self.draw(&block)
instance_eval(&block)
end
def self.route(path, service)
case path
when String
SlackRubyBot.command path do |client, data, match|
service.(client, data, match)
end
when Regexp
SlackRubyBot.match path do |client, data, match|
service.(client, data, match)
end
end
end
end
SlackRouter.draw do
route /\Ahelp\s+me/, ->(client, data, match){ YourService.method(client, data, match) }
route 'how', ->(client, data, match){ YourOtherService.method(client, data, match) }
SlackRubyBot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment