Class: ChatSDK::Webhook::Endpoint
- Inherits:
-
Object
- Object
- ChatSDK::Webhook::Endpoint
- Defined in:
- lib/chat_sdk/webhook/endpoint.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(chat:, adapter:, adapter_name:) ⇒ Endpoint
constructor
A new instance of Endpoint.
Constructor Details
#initialize(chat:, adapter:, adapter_name:) ⇒ Endpoint
Returns a new instance of Endpoint.
8 9 10 11 12 |
# File 'lib/chat_sdk/webhook/endpoint.rb', line 8 def initialize(chat:, adapter:, adapter_name:) @chat = chat @adapter = adapter @adapter_name = adapter_name end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/chat_sdk/webhook/endpoint.rb', line 6 def adapter @adapter end |
#adapter_name ⇒ Object (readonly)
Returns the value of attribute adapter_name.
6 7 8 |
# File 'lib/chat_sdk/webhook/endpoint.rb', line 6 def adapter_name @adapter_name end |
#chat ⇒ Object (readonly)
Returns the value of attribute chat.
6 7 8 |
# File 'lib/chat_sdk/webhook/endpoint.rb', line 6 def chat @chat end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/chat_sdk/webhook/endpoint.rb', line 14 def call(env) request = Rack::Request.new(env) if defined?(Rack) adapter.verify_request!(request || env) ack = adapter.ack_response(request || env) return ack if ack events = adapter.parse_events(request || env) events.each { |event| chat.dispatch(event, adapter_name: adapter_name) } [200, {"content-type" => "text/plain"}, [""]] rescue ChatSDK::SignatureVerificationError => e ChatSDK::Log.warn("Signature verification failed: #{e.}") [401, {"content-type" => "text/plain"}, ["Unauthorized"]] rescue => e ChatSDK::Log.error("Webhook error: #{e.}") [200, {"content-type" => "text/plain"}, [""]] end |