Class: FlowChat::Whatsapp::Gateway::CloudApi
- Inherits:
-
Object
- Object
- FlowChat::Whatsapp::Gateway::CloudApi
- Includes:
- Instrumentation
- Defined in:
- lib/flow_chat/whatsapp/gateway/cloud_api.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Expose client for out-of-band messaging.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(app, config = nil) ⇒ CloudApi
constructor
A new instance of CloudApi.
Methods included from Instrumentation
Constructor Details
#initialize(app, config = nil) ⇒ CloudApi
Returns a new instance of CloudApi.
16 17 18 19 20 21 22 23 |
# File 'lib/flow_chat/whatsapp/gateway/cloud_api.rb', line 16 def initialize(app, config = nil) @app = app @config = config || FlowChat::Whatsapp::Configuration.from_credentials @client = FlowChat::Whatsapp::Client.new(@config) FlowChat.logger.info { "CloudApi: Initialized WhatsApp Cloud API gateway with phone_number_id: #{@config.phone_number_id}" } FlowChat.logger.debug { "CloudApi: Gateway configuration - API base URL: #{FlowChat::Config.whatsapp.api_base_url}" } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Expose client for out-of-band messaging
49 50 51 |
# File 'lib/flow_chat/whatsapp/gateway/cloud_api.rb', line 49 def client @client end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
14 15 16 |
# File 'lib/flow_chat/whatsapp/gateway/cloud_api.rb', line 14 def context @context end |
Instance Method Details
#call(context) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flow_chat/whatsapp/gateway/cloud_api.rb', line 25 def call(context) @context = context controller = context.controller request = controller.request FlowChat.logger.debug { "CloudApi: Processing #{request.request_method} request to #{request.path}" } # Handle webhook verification if request.get? && request.params["hub.mode"] == "subscribe" FlowChat.logger.info { "CloudApi: Handling webhook verification request" } return handle_verification(context) end # Handle webhook messages if request.post? FlowChat.logger.info { "CloudApi: Handling webhook message" } return handle_webhook(context) end FlowChat.logger.warn { "CloudApi: Invalid request method or parameters - returning bad request" } controller.head :bad_request end |