Module: SlackRubyBotServer::Events::Config
Constant Summary collapse
- ATTRIBUTES =
%i[ signing_secret signature_expires_in callbacks ].freeze
Instance Method Summary collapse
Instance Method Details
#on(type, *values, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/slack-ruby-bot-server-events/config.rb', line 26 def on(type, *values, &block) value_key = values.compact.join('/') if values.any? key = [type.to_s, value_key].compact.join('/') callbacks[key] << block end |
#reset! ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/slack-ruby-bot-server-events/config.rb', line 16 def reset! self.callbacks = Hash.new { |h, k| h[k] = [] } self.signing_secret = ENV['SLACK_SIGNING_SECRET'] self.signature_expires_in = 5 * 60 on :event, 'url_verification' do |event| { challenge: event[:challenge] } end end |
#run_callbacks(type, value, args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slack-ruby-bot-server-events/config.rb', line 32 def run_callbacks(type, value, args) callbacks = [] keys = ([type.to_s] + Array(value)).compact # more specific callbacks first while keys.any? callbacks += self.callbacks[keys.join('/')] keys.pop end return nil unless callbacks&.any? callbacks.each do |c| rc = c.call(args || value) return rc if rc end nil end |