module Telegram::Bot::Tasks
Public Instance Methods
close()
click to toggle source
# File lib/telegram/bot/tasks.rb, line 39 def close each_bot do |key, bot| say("Closing #{key}...") bot.close end end
delete_webhook()
click to toggle source
# File lib/telegram/bot/tasks.rb, line 25 def delete_webhook each_bot do |key, bot| say("Deleting webhook for #{key}...") bot.delete_webhook(drop_pending_updates: drop_pending_updates) end end
log_out()
click to toggle source
# File lib/telegram/bot/tasks.rb, line 32 def log_out each_bot do |key, bot| say("Logging out #{key}...") bot.log_out end end
set_webhook()
click to toggle source
# File lib/telegram/bot/tasks.rb, line 8 def set_webhook routes = Rails.application.routes.url_helpers cert_file = ENV['CERT'] cert = File.open(cert_file) if cert_file each_bot do |key, bot| route_name = RoutesHelper.route_name_for_bot(bot) url = routes.send("#{route_name}_url") say("Setting webhook for #{key}...") bot.set_webhook( url: url, certificate: cert, ip_address: ENV['IP_ADDRESS'], drop_pending_updates: drop_pending_updates, ) end end
Private Instance Methods
drop_pending_updates()
click to toggle source
# File lib/telegram/bot/tasks.rb, line 58 def drop_pending_updates ENV['DROP_PENDING_UPDATES'].try!(:downcase) == 'true' end
each_bot(&block)
click to toggle source
# File lib/telegram/bot/tasks.rb, line 52 def each_bot(&block) id = ENV['BOT'].try!(:to_sym) bots = id ? {id => Client.by_id(id)} : Telegram.bots bots.each { |key, bot| bot.async(false) { block[key, bot] } } end
say(text)
click to toggle source
# File lib/telegram/bot/tasks.rb, line 48 def say(text) puts(text) unless Rails.env.test? # rubocop:disable Rails/Output end