Class: FlowChat::Messenger::Configuration
- Inherits:
-
Object
- Object
- FlowChat::Messenger::Configuration
- Includes:
- NamedConfiguration
- Defined in:
- lib/flow_chat/messenger/configuration.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
-
#name ⇒ Object
Returns the value of attribute name.
-
#page_id ⇒ Object
Returns the value of attribute page_id.
-
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
-
#verify_token ⇒ Object
Returns the value of attribute verify_token.
Class Method Summary collapse
Instance Method Summary collapse
-
#account_id ⇒ Object
The account this configuration speaks for.
- #api_base_url ⇒ Object
- #api_headers ⇒ Object
- #attachment_upload_url ⇒ Object
-
#initialize(name) ⇒ Configuration
constructor
A new instance of Configuration.
- #messages_url ⇒ Object
- #valid? ⇒ Boolean
-
#webhook_account_id ⇒ Object
The id an inbound webhook's entry.id names.
Methods included from NamedConfiguration
Constructor Details
#initialize(name) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flow_chat/messenger/configuration.rb', line 9 def initialize(name) @name = name @access_token = nil @page_id = nil @verify_token = nil @app_id = nil @app_secret = nil @skip_signature_validation = false FlowChat.logger.debug { "Messenger::Configuration: Initialized configuration with name: #{name || "anonymous"}" } register_as(name) if name.present? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def access_token @access_token end |
#app_id ⇒ Object
Returns the value of attribute app_id.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def app_id @app_id end |
#app_secret ⇒ Object
Returns the value of attribute app_secret.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def app_secret @app_secret end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def name @name end |
#page_id ⇒ Object
Returns the value of attribute page_id.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def page_id @page_id end |
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def skip_signature_validation @skip_signature_validation end |
#verify_token ⇒ Object
Returns the value of attribute verify_token.
6 7 8 |
# File 'lib/flow_chat/messenger/configuration.rb', line 6 def verify_token @verify_token end |
Class Method Details
.from_credentials ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flow_chat/messenger/configuration.rb', line 23 def self.from_credentials FlowChat.logger.info { "Messenger::Configuration: Loading configuration from credentials/environment" } config = new(nil) if defined?(Rails) && Rails.respond_to?(:application) && Rails.application&.credentials&.messenger FlowChat.logger.debug { "Messenger::Configuration: Loading from Rails credentials" } credentials = Rails.application.credentials.messenger config.access_token = credentials[:access_token] config.page_id = credentials[:page_id] config.verify_token = credentials[:verify_token] config.app_id = credentials[:app_id] config.app_secret = credentials[:app_secret] config.skip_signature_validation = credentials[:skip_signature_validation] || false else FlowChat.logger.debug { "Messenger::Configuration: Loading from environment variables" } config.access_token = ENV["MESSENGER_ACCESS_TOKEN"] config.page_id = ENV["MESSENGER_PAGE_ID"] config.verify_token = ENV["MESSENGER_VERIFY_TOKEN"] config.app_id = ENV["MESSENGER_APP_ID"] config.app_secret = ENV["MESSENGER_APP_SECRET"] config.skip_signature_validation = ENV["MESSENGER_SKIP_SIGNATURE_VALIDATION"] == "true" end if config.valid? FlowChat.logger.info { "Messenger::Configuration: Configuration loaded successfully - page_id: #{config.page_id}" } else FlowChat.logger.warn { "Messenger::Configuration: Incomplete configuration loaded - missing required fields" } end config end |
Instance Method Details
#account_id ⇒ Object
The account this configuration speaks for. Named generically, not page_id, so the shared gateway can check an inbound event's account without knowing which platform it holds.
71 72 73 |
# File 'lib/flow_chat/messenger/configuration.rb', line 71 def account_id page_id end |
#api_base_url ⇒ Object
91 92 93 |
# File 'lib/flow_chat/messenger/configuration.rb', line 91 def api_base_url FlowChat::Config.messenger.api_base_url end |
#api_headers ⇒ Object
95 96 97 98 99 100 |
# File 'lib/flow_chat/messenger/configuration.rb', line 95 def api_headers { "Authorization" => "Bearer #{access_token}", "Content-Type" => "application/json" } end |
#attachment_upload_url ⇒ Object
87 88 89 |
# File 'lib/flow_chat/messenger/configuration.rb', line 87 def "#{api_base_url}/#{page_id}/message_attachments" end |
#messages_url ⇒ Object
83 84 85 |
# File 'lib/flow_chat/messenger/configuration.rb', line 83 def "#{api_base_url}/#{page_id}/messages" end |
#valid? ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/flow_chat/messenger/configuration.rb', line 56 def valid? # Wrapped so a predicate answers true or false rather than nil, which # the bare && chain returns for a missing first field. Intercom and # Telegram already do this and pin it in their tests. is_valid = !!(access_token && !access_token.to_s.empty? && page_id && !page_id.to_s.empty? && verify_token && !verify_token.to_s.empty?) FlowChat.logger.debug { "Messenger::Configuration: Configuration valid: #{is_valid}" } is_valid end |
#webhook_account_id ⇒ Object
The id an inbound webhook's entry.id names. Messenger only ever handles
page, which names the Page, so this is the same id a send is
addressed to. Instagram's two differ, which is why the gateway asks for
this rather than reusing account_id.
79 80 81 |
# File 'lib/flow_chat/messenger/configuration.rb', line 79 def webhook_account_id account_id end |