Class: FlowChat::Meta::MessagingGateway
- Inherits:
-
Object
- Object
- FlowChat::Meta::MessagingGateway
- Defined in:
- lib/flow_chat/meta/messaging_gateway.rb
Overview
Direct Known Subclasses
Instagram::Gateway::SendApi, FlowChat::Messenger::Gateway::SendApi
Constant Summary
Constants included from Instrumentation
Instrumentation::DELIVERED_MESSAGE_ID_KEY, Instrumentation::DELIVERY_DURATION_KEY
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Attributes included from GatewayAsyncSupport
Class Method Summary collapse
Instance Method Summary collapse
- #call(context) ⇒ Object
- #client_class ⇒ Object
- #configuration_class ⇒ Object
-
#expected_webhook_object ⇒ Object
Meta names the subscription this delivery came from.
-
#gateway_name ⇒ Object
--- Hooks each platform overrides ---.
-
#initialize(app, config = nil) ⇒ MessagingGateway
constructor
A new instance of MessagingGateway.
- #renderer_class ⇒ Object
Methods included from GatewayIdentity
#configuration_error_class, #log_tag, #platform, #platform_label
Methods included from GatewayAsyncSupport
#async_supported?, #enqueue_async_job, #extract_body_for_background, #extract_headers_for_background, #extract_host, #extract_path, #extract_remote_ip, #in_background?, #should_enqueue_async?, #side_events_already_published?
Methods included from Instrumentation
#elapsed_ms_since, #inbound_message?, #instrument, instrument, report_api_error, #report_delivery_failure, #report_delivery_success, #report_to_app, #report_to_subscribers
Constructor Details
#initialize(app, config = nil) ⇒ MessagingGateway
Returns a new instance of MessagingGateway.
17 18 19 20 21 22 23 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 17 def initialize(app, config = nil) @app = app @config = config || configuration_class.from_credentials @client = client_class.new(@config) FlowChat.logger.info { "#{log_tag}: Initialized #{platform} gateway for account #{@config.account_id}" } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 15 def client @client end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
15 16 17 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 15 def context @context end |
Class Method Details
.configure_middleware_stack(builder, custom_middleware) ⇒ Object
42 43 44 45 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 42 def self.configure_middleware_stack(builder, custom_middleware) builder.use custom_middleware builder.use choice_mapper_class end |
Instance Method Details
#call(context) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 25 def call(context) @context = context @controller = context.controller request = @controller.request unless in_background? if request.get? && request.params["hub.mode"] == "subscribe" return handle_verification(context) end end return handle_webhook(context) if request.post? FlowChat.logger.warn { "#{log_tag}: Invalid request method or parameters - returning bad request" } @controller.head :bad_request end |
#client_class ⇒ Object
57 58 59 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 57 def client_class raise NotImplementedError end |
#configuration_class ⇒ Object
53 54 55 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 53 def configuration_class raise NotImplementedError end |
#expected_webhook_object ⇒ Object
Meta names the subscription this delivery came from. Messenger uses "page". Instagram's value depends on how the app is set up, so each platform states its own rather than sharing a guess.
68 69 70 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 68 def expected_webhook_object "page" end |
#gateway_name ⇒ Object
--- Hooks each platform overrides ---
49 50 51 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 49 def gateway_name raise NotImplementedError end |
#renderer_class ⇒ Object
61 62 63 |
# File 'lib/flow_chat/meta/messaging_gateway.rb', line 61 def renderer_class raise NotImplementedError end |