lib/telegram/bot/updates_controller.rb in telegram-bot-0.9.0.alpha2 vs lib/telegram/bot/updates_controller.rb in telegram-bot-0.9.0
- old
+ new
@@ -48,18 +48,18 @@
# There is also ability to run action without update:
#
# ControllerClass.new(bot, from: telegram_user, chat: telegram_chat).
# process(:help, *args)
#
- class UpdatesController < AbstractController::Base # rubocop:disable ClassLength
+ class UpdatesController < AbstractController::Base
abstract!
require 'telegram/bot/updates_controller/session'
require 'telegram/bot/updates_controller/log_subscriber'
require 'telegram/bot/updates_controller/instrumentation'
require 'telegram/bot/updates_controller/reply_helpers'
- autoload :CallbackQueyContext, 'telegram/bot/updates_controller/callback_query_context'
+ autoload :CallbackQueryContext, 'telegram/bot/updates_controller/callback_query_context'
autoload :MessageContext, 'telegram/bot/updates_controller/message_context'
include AbstractController::Callbacks
# Redefine callbacks with default terminator.
if ActiveSupport::VERSION::MAJOR >= 5
@@ -138,13 +138,15 @@
payload_data = [item, type] if item
end
@_payload, @_payload_type = payload_data
end
- # Accessor to `'chat'` field of payload. Can be overriden with `chat` option
- # for #initialize.
+ # Accessor to `'chat'` field of payload. Also tries `'chat'` in `'message'`
+ # when there is no such field in payload.
+ #
+ # Can be overriden with `chat` option for #initialize.
def chat
- @_chat ||= payload && payload['chat']
+ @_chat ||= payload.try! { |x| x['chat'] || x['message'] && x['message']['chat'] }
end
# Accessor to `'from'` field of payload. Can be overriden with `from` option
# for #initialize.
def from