Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/slackify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ def reset
def configure
yield(configuration)
end

def logger
@configuration.logger
end
end
end
3 changes: 2 additions & 1 deletion lib/slackify/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/slackify/handlers/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/slackify/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down