зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-06 19:15:50 +03:00
Fixed set_webhook rake task
Этот коммит содержится в:
@@ -12,9 +12,10 @@ namespace :telegram do
|
|||||||
routes = Rails.application.routes.url_helpers
|
routes = Rails.application.routes.url_helpers
|
||||||
cert_file = ENV['CERT']
|
cert_file = ENV['CERT']
|
||||||
cert = File.open(cert_file) if cert_file
|
cert = File.open(cert_file) if cert_file
|
||||||
Telegram.bots.each_value do |bot|
|
Telegram.bots.each do |key, bot|
|
||||||
route_name = Telegram::RoutesHelper.route_name_for_bot(bot)
|
route_name = Telegram::Bot::RoutesHelper.route_name_for_bot(bot)
|
||||||
url = routes.send("#{route_name}_url")
|
url = routes.send("#{route_name}_url")
|
||||||
|
puts "Setting webhook for #{key}..."
|
||||||
bot.set_webhook(url: url, certificate: cert)
|
bot.set_webhook(url: url, certificate: cert)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ module Telegram
|
|||||||
name && "#{name}_telegram_webhook"
|
name && "#{name}_telegram_webhook"
|
||||||
end || 'telegram_webhook'
|
end || 'telegram_webhook'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Replaces colon with underscore so rails don't treat it as
|
||||||
|
# route parameter.
|
||||||
|
def escape_token(token)
|
||||||
|
token.tr(':', '_')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# # Create routes for all Telegram.bots to use same controller:
|
# # Create routes for all Telegram.bots to use same controller:
|
||||||
@@ -50,7 +56,7 @@ module Telegram
|
|||||||
as: RoutesHelper.route_name_for_bot(bot),
|
as: RoutesHelper.route_name_for_bot(bot),
|
||||||
format: false,
|
format: false,
|
||||||
}.merge!(options).merge!(bot_options || {})
|
}.merge!(options).merge!(bot_options || {})
|
||||||
post("telegram/#{bot.token}", params)
|
post("telegram/#{RoutesHelper.escape_token bot.token}", params)
|
||||||
UpdatesPoller.add(bot, controller) if Telegram.bot_poller_mode?
|
UpdatesPoller.add(bot, controller) if Telegram.bot_poller_mode?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user