Module: Telegram::Bot::UpdatesController::MessageContext

Extended by:
ActiveSupport::Concern
Includes:
Session
Defined in:
lib/telegram/bot/updates_controller/message_context.rb

Overview

Allows to store context in session and treat next message according to this context.

It provides ‘save_context` method to store method name to be used as action for next update:

def set_location!(*)
  save_context(:set_location_from_message)
  respond_with :message, text: 'Where are you?'
end

def set_location_from_message(city = nil, *)
  # update
end

# OR
# This will support both `/set_location city_name`, and `/set_location`
# with subsequent refinement.
def set_location!(city = nil, *)
  if city
    # update
  else
    save_context(:set_location!)
    respond_with :message, text: 'Where are you?'
  end
end

Instance Method Summary collapse

Methods included from Session

#process_action

Instance Method Details

#cancel!Object

Action to clear context.



37
38
39
# File 'lib/telegram/bot/updates_controller/message_context.rb', line 37

def cancel!
  # Context is already cleared in action_for_message
end