Class: Stealth::Services::Facebook::MessageHandler

Inherits:
BaseMessageHandler show all
Defined in:
lib/stealth/services/facebook/message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, headers:) ⇒ MessageHandler

Returns a new instance of MessageHandler.



15
16
17
18
# File 'lib/stealth/services/facebook/message_handler.rb', line 15

def initialize(params:, headers:)
  @params = params
  @headers = headers
end

Instance Attribute Details

#facebook_messageObject (readonly)

Returns the value of attribute facebook_message.



13
14
15
# File 'lib/stealth/services/facebook/message_handler.rb', line 13

def facebook_message
  @facebook_message
end

#headersObject (readonly)

Returns the value of attribute headers.



13
14
15
# File 'lib/stealth/services/facebook/message_handler.rb', line 13

def headers
  @headers
end

#paramsObject (readonly)

Returns the value of attribute params.



13
14
15
# File 'lib/stealth/services/facebook/message_handler.rb', line 13

def params
  @params
end

#service_messageObject (readonly)

Returns the value of attribute service_message.



13
14
15
# File 'lib/stealth/services/facebook/message_handler.rb', line 13

def service_message
  @service_message
end

Instance Method Details

#coordinateObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stealth/services/facebook/message_handler.rb', line 20

def coordinate
  if facebook_is_validating_webhook?
    respond_with_validation
  else
    # Queue the request processing so we can respond quickly to FB
    # and also keep track of this message
    Stealth::Services::HandleMessageJob.perform_async('facebook', params, {})

    # Relay our acceptance
    [200, 'OK']
  end
end

#processObject



33
34
35
36
37
38
39
40
41
# File 'lib/stealth/services/facebook/message_handler.rb', line 33

def process
  @service_message = ServiceMessage.new(service: 'facebook')
  @facebook_message = params['entry'].first['messaging'].first
  service_message.sender_id = get_sender_id
  service_message.timestamp = get_timestamp
  process_facebook_event

  service_message
end