Created
October 25, 2017 20:13
-
-
Save m-kind/bc1495cf4b15901877b69bda449606d0 to your computer and use it in GitHub Desktop.
basic routing functionality for slack-ruby-bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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