class Slackify::Configuration
Where the configuration for Slackify
lives
Attributes
approved_bot_ids[RW]
custom_event_type_handlers[R]
custom_message_subtype_handlers[R]
handlers[RW]
slack_bot_token[R]
slack_client[RW]
slack_secret_token[RW]
unhandled_handler[R]
Public Class Methods
new()
click to toggle source
# File lib/slackify/configuration.rb, line 11 def initialize @slack_bot_token = nil @slack_secret_token = nil @handlers = generate_handlers @slack_client = nil @custom_message_subtype_handlers = {} @custom_event_type_handlers = {} @unhandled_handler = Handlers::UnhandledHandler @approved_bot_ids = [] end
Public Instance Methods
custom_event_type_handlers=(event_type_hash)
click to toggle source
Set a handler for a event type That handler will have to implement `self.handle_event(params)` see api.slack.com/events
# File lib/slackify/configuration.rb, line 52 def custom_event_type_handlers=(event_type_hash) @custom_event_type_handlers = event_type_hash.with_indifferent_access end
custom_message_subtype_handlers=(event_subtype_hash)
click to toggle source
Set a handler for a specific message subtype That handler will have to implement `self.handle_event(params)` see api.slack.com/events/message
# File lib/slackify/configuration.rb, line 45 def custom_message_subtype_handlers=(event_subtype_hash) @custom_message_subtype_handlers = event_subtype_hash.with_indifferent_access end
remove_unhandled_handler()
click to toggle source
Remove unhandled handler. The bot will not reply if the message doesn't match any regex
# File lib/slackify/configuration.rb, line 32 def remove_unhandled_handler @unhandled_handler = nil end
slack_bot_token=(token)
click to toggle source
Set the token that we will use to connect to slack
# File lib/slackify/configuration.rb, line 37 def slack_bot_token=(token) @slack_bot_token = token @slack_client = Slack::Web::Client.new(token: token).freeze end
unhandled_handler=(handler)
click to toggle source
Set your own unhandled handler
# File lib/slackify/configuration.rb, line 23 def unhandled_handler=(handler) raise HandlerNotSupported, "#{handler.class} is not a subclass of Slackify::Handlers::Base" unless handler < Handlers::Base @unhandled_handler = handler end
Private Instance Methods
generate_handlers()
click to toggle source
Convert a hash to a list of lambda functions that will be called to handle the user messages
# File lib/slackify/configuration.rb, line 60 def generate_handlers generated_handlers = [] read_handlers_yaml.each do |handler_hash| handler = Handlers::Factory.for(handler_hash) generated_handlers << handler end generated_handlers end
read_handlers_yaml()
click to toggle source
Reads the config/handlers.yml configuration
# File lib/slackify/configuration.rb, line 71 def read_handlers_yaml raise 'config/handlers.yml does not exist' unless File.exist?("#{Rails.root}/config/handlers.yml") YAML.load_file("#{Rails.root}/config/handlers.yml") || [] end