Class: SlackBot::Events::Middleware::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_bot/events/middleware/message_handler.rb

Instance Method Summary collapse

Instance Method Details

#call(schema:, websocket:, listener:, **params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slack_bot/events/middleware/message_handler.rb', line 7

def call(schema:, websocket:, listener:, **params)
  if SlackBot::Events.config.acknowledge_on_receive?
    acknowledge!(websocket: websocket, schema: schema)
  end

  yield

  listener[:on_success]&.call(schema) if listener

  if SlackBot::Events.config.acknowledge_on_success? || SlackBot::Events.config.acknowledge_on_complete?
    acknowledge!(websocket: websocket, schema: schema)
  end
rescue StandardError => error
  Events.logger.error do
    "#{listener[:handler]} returned #{error.class} => #{error.message}. #{error.backtrace[0...10]}"
  end

  begin
    listener[:on_failure]&.call(schema, error) if listener
  rescue StandardError => on_failure_error
     Events.logger.error("Failure occured during on_failure block. #{on_failure_error}")
  end

  if SlackBot::Events.config.acknowledge_on_complete?
    acknowledge!(websocket: websocket, schema: schema)
  elsif SlackBot::Events.config.acknowledge_on_success?
    Events.logger.debug do
      "Envelope acknowledgment skipped. Ackowledgment on success only. Slack may send a duplicate message"
    end
  end
end