Class: FlowChat::Telegram::Middleware::ChoiceMapper
- Inherits:
-
Object
- Object
- FlowChat::Telegram::Middleware::ChoiceMapper
- Defined in:
- lib/flow_chat/telegram/middleware/choice_mapper.rb
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(app) ⇒ ChoiceMapper
constructor
A new instance of ChoiceMapper.
Constructor Details
#initialize(app) ⇒ ChoiceMapper
Returns a new instance of ChoiceMapper.
5 6 7 |
# File 'lib/flow_chat/telegram/middleware/choice_mapper.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(context) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/flow_chat/telegram/middleware/choice_mapper.rb', line 9 def call(context) input = context.input # Check if input matches a stored choice key (for validation/logging) if context.session && input.present? choices = context.session.get("telegram_choices") if choices&.key?(input) FlowChat.logger.debug { "ChoiceMapper: Input '#{input}' is a valid choice key" } end end response = @app.call(context) # Store choices in session for validation if response _, _, choices, _ = response if choices.is_a?(Hash) context.session&.set("telegram_choices", choices) end end response end |