Class: FlowChat::Telegram::Configuration
- Inherits:
-
Object
- Object
- FlowChat::Telegram::Configuration
- Includes:
- NamedConfiguration
- Defined in:
- lib/flow_chat/telegram/configuration.rb
Instance Attribute Summary collapse
-
#bot_token ⇒ Object
Returns the value of attribute bot_token.
-
#name ⇒ Object
Returns the value of attribute name.
-
#secret_token ⇒ Object
Returns the value of attribute secret_token.
-
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
Class Method Summary collapse
Instance Method Summary collapse
- #api_base_url ⇒ Object
- #bot_id ⇒ Object
- #delete_webhook_url ⇒ Object
- #get_webhook_info_url ⇒ Object
-
#initialize(name) ⇒ Configuration
constructor
A new instance of Configuration.
- #send_message_url ⇒ Object
- #set_webhook_url ⇒ Object
- #valid? ⇒ Boolean
Methods included from NamedConfiguration
Constructor Details
#initialize(name) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/flow_chat/telegram/configuration.rb', line 8 def initialize(name) @name = name @bot_token = nil @secret_token = nil @skip_signature_validation = false FlowChat.logger.debug { "Telegram::Configuration: Initialized configuration with name: #{name || "anonymous"}" } register_as(name) if name.present? end |
Instance Attribute Details
#bot_token ⇒ Object
Returns the value of attribute bot_token.
6 7 8 |
# File 'lib/flow_chat/telegram/configuration.rb', line 6 def bot_token @bot_token end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/flow_chat/telegram/configuration.rb', line 6 def name @name end |
#secret_token ⇒ Object
Returns the value of attribute secret_token.
6 7 8 |
# File 'lib/flow_chat/telegram/configuration.rb', line 6 def secret_token @secret_token end |
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
6 7 8 |
# File 'lib/flow_chat/telegram/configuration.rb', line 6 def skip_signature_validation @skip_signature_validation end |
Class Method Details
.from_credentials ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flow_chat/telegram/configuration.rb', line 19 def self.from_credentials FlowChat.logger.info { "Telegram::Configuration: Loading configuration from credentials/environment" } config = new(nil) if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.credentials.telegram FlowChat.logger.debug { "Telegram::Configuration: Loading from Rails credentials" } credentials = Rails.application.credentials.telegram config.bot_token = credentials[:bot_token] config.secret_token = credentials[:secret_token] config.skip_signature_validation = credentials[:skip_signature_validation] || false else FlowChat.logger.debug { "Telegram::Configuration: Loading from environment variables" } config.bot_token = ENV["TELEGRAM_BOT_TOKEN"] config.secret_token = ENV["TELEGRAM_SECRET_TOKEN"] config.skip_signature_validation = ENV["TELEGRAM_SKIP_SIGNATURE_VALIDATION"] == "true" end if config.valid? FlowChat.logger.info { "Telegram::Configuration: Configuration loaded successfully" } else FlowChat.logger.warn { "Telegram::Configuration: Incomplete configuration loaded - missing required fields" } end config end |
Instance Method Details
#api_base_url ⇒ Object
52 53 54 55 |
# File 'lib/flow_chat/telegram/configuration.rb', line 52 def api_base_url return nil unless bot_token "https://api.telegram.org/bot#{bot_token}" end |
#bot_id ⇒ Object
57 58 59 |
# File 'lib/flow_chat/telegram/configuration.rb', line 57 def bot_id bot_token&.split(":")&.first end |
#delete_webhook_url ⇒ Object
73 74 75 |
# File 'lib/flow_chat/telegram/configuration.rb', line 73 def delete_webhook_url "#{api_base_url}/deleteWebhook" end |
#get_webhook_info_url ⇒ Object
69 70 71 |
# File 'lib/flow_chat/telegram/configuration.rb', line 69 def get_webhook_info_url "#{api_base_url}/getWebhookInfo" end |
#send_message_url ⇒ Object
61 62 63 |
# File 'lib/flow_chat/telegram/configuration.rb', line 61 def "#{api_base_url}/sendMessage" end |
#set_webhook_url ⇒ Object
65 66 67 |
# File 'lib/flow_chat/telegram/configuration.rb', line 65 def set_webhook_url "#{api_base_url}/setWebhook" end |