diff --git a/lib/slackify.rb b/lib/slackify.rb index b304cde..006ab53 100644 --- a/lib/slackify.rb +++ b/lib/slackify.rb @@ -20,5 +20,9 @@ def reset def configure yield(configuration) end + + def logger + @configuration.logger + end end end diff --git a/lib/slackify/configuration.rb b/lib/slackify/configuration.rb index 9d65946..753a3fe 100644 --- a/lib/slackify/configuration.rb +++ b/lib/slackify/configuration.rb @@ -6,7 +6,7 @@ module Slackify # Where the configuration for Slackify lives class Configuration attr_reader :custom_message_subtype_handlers, :slack_bot_token, :unhandled_handler, :custom_event_type_handlers - attr_accessor :handlers, :slack_secret_token, :slack_client, :whitelisted_bot_ids + attr_accessor :handlers, :slack_secret_token, :slack_client, :whitelisted_bot_ids, :logger def initialize @slack_bot_token = nil @@ -17,6 +17,7 @@ def initialize @custom_event_type_handlers = {} @unhandled_handler = Handlers::UnhandledHandler @whitelisted_bot_ids = [] + @logger = Rails.logger end # Set your own unhandled handler diff --git a/lib/slackify/handlers/factory.rb b/lib/slackify/handlers/factory.rb index e91b96f..b89d885 100644 --- a/lib/slackify/handlers/factory.rb +++ b/lib/slackify/handlers/factory.rb @@ -16,6 +16,8 @@ def self.for(configuration) built_command.regex = command['regex'] built_command.handler = handler.name.camelize.constantize.method(command['action']) built_command.description = command['description'] + built_command.friendly_name = "#{handler.name}##{command['action']}" + handler.commands << built_command.freeze end diff --git a/lib/slackify/router.rb b/lib/slackify/router.rb index fc726fe..85360f6 100644 --- a/lib/slackify/router.rb +++ b/lib/slackify/router.rb @@ -18,11 +18,16 @@ def matching_command(message) # Call command based on message string def call_command(message, params) command = matching_command(message) + if command.nil? + Slackify.logger.info("[Slackify] no handler matched message: #{message}") return unless Slackify.configuration.unhandled_handler Slackify.configuration.unhandled_handler.unhandled(params) + else + Slackify.logger.info("[Slackify] message being routed to handler: #{command.friendly_name}") + new_params = params.merge(command_arguments: command.regex.match(message).named_captures) command.handler.call(new_params) end