class Telegram::BotManager::Application

Public Class Methods

new(configuration) click to toggle source
# File lib/telegram/bot_manager/application.rb, line 7
def initialize(configuration)
  @configuration = configuration
  @bot = @configuration.bot

  configure
  configuration_message if BotManager.configuration.show_config_message
end

Public Instance Methods

configure() click to toggle source
# File lib/telegram/bot_manager/application.rb, line 15
def configure
rescue => exception
  handle_exception(exception)
end
run() click to toggle source
# File lib/telegram/bot_manager/application.rb, line 20
def run
  startup_message

  Telegram::Bot::UpdatesPoller.start(
    @bot,
    controller
  )
rescue => exception
  handle_exception(exception)
end

Private Instance Methods

configuration_message() click to toggle source
# File lib/telegram/bot_manager/application.rb, line 37
      def configuration_message
        puts <<~INFO
        Application is initialized and configured
        =========================================================
        Configuration

        App name: #{@configuration.app_name.to_s.bold.cyan}
        Telegram bot username: #{@configuration.bot.username}
        Locale: #{@configuration.locale}
        =========================================================\n
        INFO
      end
controller() click to toggle source
# File lib/telegram/bot_manager/application.rb, line 33
def controller
  raise "Implement method #{__method__} in your app file"
end
handle_exception(exception) click to toggle source
# File lib/telegram/bot_manager/application.rb, line 54
def handle_exception(exception)
  puts "[#{@configuration.app_name}] Application raised exception...".bold.red
  raise exception
end
startup_message() click to toggle source
# File lib/telegram/bot_manager/application.rb, line 50
def startup_message
  puts "[#{@configuration.app_name}] Application is listening messages...".bold.green
end