1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 17:55:52 +03:00

Сравнить коммиты

..

4 Коммитов

Автор SHA1 Сообщение Дата
Max Melentiev
2a511abe16 fixed middleware's response 2016-02-29 14:22:36 +06:00
Max Melentiev
0f5f426d55 v0.4.1 2016-02-29 14:08:31 +06:00
Max Melentiev
e6dea5096f Properly included ActiveRecord::Railties::ControllerRuntime 2016-02-29 14:07:11 +06:00
Max Melentiev
c06ba2af5c Fixed set_webhook rake task 2016-02-29 14:06:11 +06:00
6 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@@ -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

Просмотреть файл

@@ -15,7 +15,7 @@ module Telegram
def call(env) def call(env)
update = env['action_dispatch.request.request_parameters'] update = env['action_dispatch.request.request_parameters']
controller.dispatch(bot, update) controller.dispatch(bot, update)
[200, {}, ''] [200, {}, ['']]
end end
def inspect def inspect

Просмотреть файл

@@ -25,7 +25,8 @@ module Telegram
initializer 'telegram.bot.updates_controller.add_ar_runtime' do initializer 'telegram.bot.updates_controller.add_ar_runtime' do
ActiveSupport.on_load('telegram.bot.updates_controller') do ActiveSupport.on_load('telegram.bot.updates_controller') do
if defined?(ActiveRecord::Railties::ControllerRuntime) if defined?(ActiveRecord::Railties::ControllerRuntime)
include ActiveRecord::Railties::ControllerRuntime prepend ActiveRecord::Railties::ControllerRuntime
extend ActiveRecord::Railties::ControllerRuntime::ClassMethods
end end
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

Просмотреть файл

@@ -1,6 +1,6 @@
module Telegram module Telegram
module Bot module Bot
VERSION = '0.4.0'.freeze VERSION = '0.4.2'.freeze
def self.gem_version def self.gem_version
Gem::Version.new VERSION Gem::Version.new VERSION

Просмотреть файл

@@ -13,6 +13,6 @@ RSpec.describe Telegram::Bot::Middleware do
subject subject
end end
it { should eq [200, {}, ''] } it { should eq [200, {}, ['']] }
end end
end end