Sha256: 10e9bd5579806560d9d2cef800dc116baf0226ebf0a5e0990406610ad43a619a

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

namespace :telegram do
  namespace :bot do
    desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \
      'Use LOG_TO_STDOUT to enable/disable broadcasting.'
    task :poller do
      ENV['BOT_POLLER_MODE'] = 'true'
      Rake::Task['environment'].invoke
      if ENV.fetch('LOG_TO_STDOUT') { Rails.env.development? }.present?
        console = ActiveSupport::Logger.new(STDERR)
        Rails.logger.extend ActiveSupport::Logger.broadcast console
      end
      Telegram::Bot::UpdatesPoller.start(ENV['BOT'].try!(:to_sym) || :default)
    end

    desc 'Set webhook urls for all bots'
    task set_webhook: :environment do
      routes = Rails.application.routes.url_helpers
      cert_file = ENV['CERT']
      cert = File.open(cert_file) if cert_file
      Telegram.bots.each do |key, bot|
        route_name = Telegram::Bot::RoutesHelper.route_name_for_bot(bot)
        url = routes.send("#{route_name}_url")
        puts "Setting webhook for #{key}..."
        bot.async(false) { bot.set_webhook(url: url, certificate: cert) }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
telegram-bot-0.14.4 lib/tasks/telegram-bot.rake
telegram-bot-0.14.3 lib/tasks/telegram-bot.rake
telegram-bot-0.14.2 lib/tasks/telegram-bot.rake
telegram-bot-0.14.1 lib/tasks/telegram-bot.rake
telegram-bot-0.14.0 lib/tasks/telegram-bot.rake
telegram-bot-0.13.1 lib/tasks/telegram-bot.rake
telegram-bot-0.13.0 lib/tasks/telegram-bot.rake
telegram-bot-0.12.4 lib/tasks/telegram-bot.rake
telegram-bot-0.12.3 lib/tasks/telegram-bot.rake
telegram-bot-0.12.1 lib/tasks/telegram-bot.rake