Module: Telegram::Bottable

Included in:
Telegram
Defined in:
lib/telegram/bottable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bot_poller_mode=(value) ⇒ Object (writeonly)

Keep this setting here, so we can avoid loading Bot::UpdatesPoller when polling is disabled.



8
9
10
# File 'lib/telegram/bottable.rb', line 8

def bot_poller_mode=(value)
  @bot_poller_mode = value
end

#bots_configObject

Returns config for .bots method. By default uses ‘telegram` section from `secrets.yml` merging `telegram` at `:default` key.

Can be overwritten with .bots_config=



32
33
34
35
36
37
38
39
# File 'lib/telegram/bottable.rb', line 32

def bots_config
  return @bots_config if @bots_config
  telegram_config = Rails.application.secrets[:telegram]
  (telegram_config['bots'] || {}).symbolize_keys.tap do |config|
    default = telegram_config['bot']
    config[:default] = default if default
  end
end

Instance Method Details

#botObject

Default bot.



24
25
26
# File 'lib/telegram/bottable.rb', line 24

def bot
  @bot ||= bots[:default]
end

#bot_poller_mode?Boolean

It just tells routes helpers whether to add routed bots to Bot::UpdatesPoller, so their config will be available by bot key in Bot::UpdatesPoller.start.

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/telegram/bottable.rb', line 13

def bot_poller_mode?
  return @bot_poller_mode if defined?(@bot_poller_mode)
  Rails.env.development? if defined?(Rails)
end

#botsObject

Hash of bots made with bots_config.



19
20
21
# File 'lib/telegram/bottable.rb', line 19

def bots
  @bots ||= bots_config.transform_values(&Bot.method(:wrap))
end