зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-08-28 15:26:18 +03:00
Сравнить коммиты
4 Коммитов
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
5bf98b419b | ||
|
|
8077ef9bcf | ||
|
|
5fef6fb43a | ||
|
|
07be01c07d |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,4 +1,14 @@
|
||||
# 0.7.0 Unreleased
|
||||
# 0.7.3
|
||||
|
||||
- Fixed issues with poller in production (#3)
|
||||
|
||||
# 0.7.2
|
||||
|
||||
- Bot API 2.1
|
||||
- Fixed possible crashes when payload type is not supported.
|
||||
Provides empty session when neither `from` nor `chat` is defined.
|
||||
|
||||
# 0.7.0
|
||||
|
||||
- New Bot API methods.
|
||||
- Helpers for inline keyboards, support for callback_query (with contextual actions).
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
namespace :telegram do
|
||||
namespace :bot do
|
||||
desc 'Run poller'
|
||||
task poller: :environment do
|
||||
console = ActiveSupport::Logger.new(STDERR)
|
||||
Rails.logger.extend ActiveSupport::Logger.broadcast console
|
||||
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
|
||||
|
||||
|
||||
@@ -71,11 +71,16 @@ module Telegram
|
||||
answerCallbackQuery
|
||||
answerInlineQuery
|
||||
forwardMessage
|
||||
getChat
|
||||
getChatAdministrators
|
||||
getChatMember
|
||||
getChatMembersCount
|
||||
getFile
|
||||
getMe
|
||||
getUpdates
|
||||
getUserProfilePhotos
|
||||
kickChatMember
|
||||
leaveChat
|
||||
sendAudio
|
||||
sendChatAction
|
||||
sendContact
|
||||
|
||||
@@ -14,9 +14,14 @@ module Telegram
|
||||
# It just tells routes helpers whether to add routed bots to
|
||||
# Bot::UpdatesPoller, so their config will be available by bot key in
|
||||
# Bot::UpdatesPoller.start.
|
||||
#
|
||||
# It's enabled by default in Rails dev environment and `rake telegram:bot:poller`
|
||||
# task. Use `BOT_POLLER_MODE=true` envvar to set it manually.
|
||||
def bot_poller_mode?
|
||||
return @bot_poller_mode if defined?(@bot_poller_mode)
|
||||
Rails.env.development? if defined?(Rails)
|
||||
@bot_poller_mode = ENV.fetch('BOT_POLLER_MODE') do
|
||||
Rails.env.development? if defined?(Rails)
|
||||
end
|
||||
end
|
||||
|
||||
# Hash of bots made with bots_config.
|
||||
|
||||
@@ -50,7 +50,7 @@ module Telegram
|
||||
# ControllerClass.new(bot, from: telegram_user, chat: telegram_chat).
|
||||
# process(:help, *args)
|
||||
#
|
||||
class UpdatesController < AbstractController::Base
|
||||
class UpdatesController < AbstractController::Base # rubocop:disable ClassLength
|
||||
abstract!
|
||||
|
||||
require 'telegram/bot/updates_controller/session'
|
||||
@@ -84,6 +84,7 @@ module Telegram
|
||||
inline_query
|
||||
chosen_inline_result
|
||||
callback_query
|
||||
edited_message
|
||||
).freeze
|
||||
CMD_REGEX = %r{\A/([a-z\d_]{,31})(@(\S+))?(\s|$)}i
|
||||
CONFLICT_CMD_REGEX = Regexp.new("^(#{PAYLOAD_TYPES.join('|')}|\\d)")
|
||||
@@ -180,6 +181,11 @@ module Telegram
|
||||
[true, cmd, args] if cmd
|
||||
end
|
||||
|
||||
# It doesn't extract commands from edited messages. Just process
|
||||
# them as usual ones.
|
||||
def action_for_edited_message
|
||||
end
|
||||
|
||||
def action_for_inline_query
|
||||
[false, payload_type, [payload['query'], payload['offset']]]
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Telegram
|
||||
module Bot
|
||||
VERSION = '0.7.0'.freeze
|
||||
VERSION = '0.7.3'.freeze
|
||||
|
||||
def self.gem_version
|
||||
Gem::Version.new VERSION
|
||||
|
||||
@@ -102,6 +102,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
it { should eq [false, payload_type, payload.values_at(:data)] }
|
||||
end
|
||||
|
||||
context 'when payload is edited_message' do
|
||||
let(:payload_type) { 'edited_message' }
|
||||
it { should eq [false, payload_type, [payload]] }
|
||||
end
|
||||
|
||||
context 'when payload is not supported' do
|
||||
let(:payload_type) { '_unsupported_' }
|
||||
it { should eq [false, :unsupported_payload_type, []] }
|
||||
|
||||
Ссылка в новой задаче
Block a user