Class: FlowChat::Ussd::Middleware::ChoiceMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/ussd/middleware/choice_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ChoiceMapper



5
6
7
8
# File 'lib/flow_chat/ussd/middleware/choice_mapper.rb', line 5

def initialize(app)
  @app = app
  FlowChat.logger.debug { "Ussd::ChoiceMapper: Initialized USSD choice mapping middleware" }
end

Instance Method Details

#call(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flow_chat/ussd/middleware/choice_mapper.rb', line 10

def call(context)
  @context = context
  @session = context.session

  session_id = context["session.id"]
  FlowChat.logger.debug { "Ussd::ChoiceMapper: Processing request for session #{session_id}" }

  if intercept?
    FlowChat.logger.info { "Ussd::ChoiceMapper: Intercepting request for choice resolution - session #{session_id}" }
    handle_choice_input
  end

  # Clear choice mapping state for new flows
  clear_choice_state_if_needed
  type, prompt, choices, media = @app.call(context)

  if choices.present?
    FlowChat.logger.debug { "Ussd::ChoiceMapper: Found choices, creating number mapping" }
    choices = create_numbered_mapping(choices)
  end

  [type, prompt, choices, media]
end