Class: Legion::Gaia::Channels::Teams::WebhookHandler

Inherits:
Object
  • Object
show all
Includes:
Logging::Helper
Defined in:
lib/legion/gaia/channels/teams/webhook_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ WebhookHandler

Returns a new instance of WebhookHandler.



14
15
16
# File 'lib/legion/gaia/channels/teams/webhook_handler.rb', line 14

def initialize(adapter)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



12
13
14
# File 'lib/legion/gaia/channels/teams/webhook_handler.rb', line 12

def adapter
  @adapter
end

Instance Method Details

#handle(request_body:, auth_header: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/gaia/channels/teams/webhook_handler.rb', line 18

def handle(request_body:, auth_header: nil)
  activity = parse_activity(request_body)
  return error_response(:invalid_payload, 'Could not parse activity') unless activity

  if adapter.app_id && auth_header
    token = extract_bearer_token(auth_header)
    validation = adapter.validate_inbound(token)
    return error_response(:auth_failed, validation[:error]) unless validation[:valid]
  end

  activity_type = activity['type'] || activity[:type]
  log.info("WebhookHandler received activity_type=#{activity_type}")
  case activity_type
  when 'message' then handle_message(activity)
  when 'conversationUpdate' then handle_conversation_update(activity)
  when 'invoke' then handle_invoke(activity)
  else handle_other(activity)
  end
end