зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-08 20:05:51 +03:00
Client.wrap supports symbols
Этот коммит содержится в:
@@ -19,6 +19,9 @@ module Telegram
|
|||||||
when Hash then
|
when Hash then
|
||||||
input = input.stringify_keys
|
input = input.stringify_keys
|
||||||
new input['token'], input['username']
|
new input['token'], input['username']
|
||||||
|
when Symbol
|
||||||
|
Telegram.bots[input] or
|
||||||
|
raise "Bot #{input} not configured, check Telegram.bots_config."
|
||||||
else
|
else
|
||||||
new(input)
|
new(input)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ module Telegram
|
|||||||
# # You can override this options or specify others:
|
# # You can override this options or specify others:
|
||||||
# telegram_webhooks TelegramController, as: :my_webhook
|
# telegram_webhooks TelegramController, as: :my_webhook
|
||||||
# telegram_webhooks bot => [TelegramChatController, as: :chat_webhook],
|
# telegram_webhooks bot => [TelegramChatController, as: :chat_webhook],
|
||||||
# other_bot => [TelegramAuctionController,
|
# other_bot => TelegramAuctionController,
|
||||||
|
# admin_chat: TelegramAdminChatController
|
||||||
|
#
|
||||||
def telegram_webhooks(controllers, bots = nil, **options)
|
def telegram_webhooks(controllers, bots = nil, **options)
|
||||||
unless controllers.is_a?(Hash)
|
unless controllers.is_a?(Hash)
|
||||||
bots = bots ? Array.wrap(bots) : Telegram.bots.values
|
bots = bots ? Array.wrap(bots) : Telegram.bots.values
|
||||||
|
|||||||
@@ -33,6 +33,17 @@ RSpec.describe Telegram::Bot::Client do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when input is a Symbol' do
|
||||||
|
let(:input) { :bot_1 }
|
||||||
|
before { allow(Telegram).to receive(:bots) { {bot_1: instance} } }
|
||||||
|
it { should eq Telegram.bots[:bot_1] }
|
||||||
|
|
||||||
|
context 'and there is no such bot' do
|
||||||
|
let(:input) { :invalid }
|
||||||
|
it { expect { subject }.to raise_error(/not configured/) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when input is an array' do
|
context 'when input is an array' do
|
||||||
let!(:input) { ['other_token', instance, token: token, username: username] }
|
let!(:input) { ['other_token', instance, token: token, username: username] }
|
||||||
let(:result_2) { double(:result_2) }
|
let(:result_2) { double(:result_2) }
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ RSpec.describe Telegram::Bot::RoutesHelper do
|
|||||||
{
|
{
|
||||||
bot => controller,
|
bot => controller,
|
||||||
'custom_token' => [other_controller, as: :custom_route, option: :other_val],
|
'custom_token' => [other_controller, as: :custom_route, option: :other_val],
|
||||||
|
other: controller,
|
||||||
},
|
},
|
||||||
option: :val,
|
option: :val,
|
||||||
]
|
]
|
||||||
@@ -90,7 +91,8 @@ RSpec.describe Telegram::Bot::RoutesHelper do
|
|||||||
other_controller,
|
other_controller,
|
||||||
:custom_route,
|
:custom_route,
|
||||||
option: :other_val,
|
option: :other_val,
|
||||||
]
|
],
|
||||||
|
[Telegram.bots[:other], controller, 'other_telegram_webhook', option: :val]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user