Class: FlowChat::Telegram::Configuration
- Inherits:
-
Object
- Object
- FlowChat::Telegram::Configuration
- Defined in:
- lib/flow_chat/telegram/configuration.rb
Constant Summary collapse
- @@configurations =
{}
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
- .clear_all! ⇒ Object
- .configuration_names ⇒ Object
- .exists?(name) ⇒ Boolean
- .from_credentials ⇒ Object
- .get(name) ⇒ Object
- .register(name, config) ⇒ Object
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.
- #register_as(name) ⇒ Object
- #send_message_url ⇒ Object
- #set_webhook_url ⇒ Object
- #valid? ⇒ Boolean
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.
4 5 6 |
# File 'lib/flow_chat/telegram/configuration.rb', line 4 def bot_token @bot_token end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/flow_chat/telegram/configuration.rb', line 4 def name @name end |
#secret_token ⇒ Object
Returns the value of attribute secret_token.
4 5 6 |
# File 'lib/flow_chat/telegram/configuration.rb', line 4 def secret_token @secret_token end |
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
4 5 6 |
# File 'lib/flow_chat/telegram/configuration.rb', line 4 def skip_signature_validation @skip_signature_validation end |
Class Method Details
.clear_all! ⇒ Object
74 75 76 77 |
# File 'lib/flow_chat/telegram/configuration.rb', line 74 def self.clear_all! FlowChat.logger.debug { "Telegram::Configuration: Clearing all registered configurations" } @@configurations.clear end |
.configuration_names ⇒ Object
68 69 70 71 72 |
# File 'lib/flow_chat/telegram/configuration.rb', line 68 def self.configuration_names names = @@configurations.keys FlowChat.logger.debug { "Telegram::Configuration: Available configurations: #{names}" } names end |
.exists?(name) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/flow_chat/telegram/configuration.rb', line 62 def self.exists?(name) exists = @@configurations.key?(name.to_sym) FlowChat.logger.debug { "Telegram::Configuration: Configuration '#{name}' exists: #{exists}" } exists end |
.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 |
.get(name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/flow_chat/telegram/configuration.rb', line 51 def self.get(name) config = @@configurations[name.to_sym] if config FlowChat.logger.debug { "Telegram::Configuration: Retrieved configuration '#{name}'" } config else FlowChat.logger.error { "Telegram::Configuration: Configuration '#{name}' not found" } raise ArgumentError, "Telegram configuration '#{name}' not found" end end |
Instance Method Details
#api_base_url ⇒ Object
92 93 94 95 |
# File 'lib/flow_chat/telegram/configuration.rb', line 92 def api_base_url return nil unless bot_token "https://api.telegram.org/bot#{bot_token}" end |
#bot_id ⇒ Object
97 98 99 |
# File 'lib/flow_chat/telegram/configuration.rb', line 97 def bot_id bot_token&.split(":")&.first end |
#delete_webhook_url ⇒ Object
113 114 115 |
# File 'lib/flow_chat/telegram/configuration.rb', line 113 def delete_webhook_url "#{api_base_url}/deleteWebhook" end |
#get_webhook_info_url ⇒ Object
109 110 111 |
# File 'lib/flow_chat/telegram/configuration.rb', line 109 def get_webhook_info_url "#{api_base_url}/getWebhookInfo" end |
#register_as(name) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/flow_chat/telegram/configuration.rb', line 79 def register_as(name) FlowChat.logger.debug { "Telegram::Configuration: Registering configuration as '#{name}'" } @name = name.to_sym self.class.register(@name, self) self end |
#send_message_url ⇒ Object
101 102 103 |
# File 'lib/flow_chat/telegram/configuration.rb', line 101 def "#{api_base_url}/sendMessage" end |
#set_webhook_url ⇒ Object
105 106 107 |
# File 'lib/flow_chat/telegram/configuration.rb', line 105 def set_webhook_url "#{api_base_url}/setWebhook" end |