Class: Legion::Gaia::Channels::Teams::WebhookHandler
- Inherits:
-
Object
- Object
- Legion::Gaia::Channels::Teams::WebhookHandler
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/gaia/channels/teams/webhook_handler.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #handle(request_body:, auth_header: nil) ⇒ Object
-
#initialize(adapter) ⇒ WebhookHandler
constructor
A new instance of WebhookHandler.
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
#adapter ⇒ Object (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 (activity) when 'conversationUpdate' then handle_conversation_update(activity) when 'invoke' then handle_invoke(activity) else handle_other(activity) end end |