Class: FlowChat::Ussd::Middleware::Executor

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Executor

Returns a new instance of Executor.



5
6
7
# File 'lib/flow_chat/ussd/middleware/executor.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
# File 'lib/flow_chat/ussd/middleware/executor.rb', line 9

def call(context)
  ussd_app = build_ussd_app context
  flow = context.flow.new ussd_app
  flow.send context["flow.action"]
rescue FlowChat::Interrupt::Prompt => e
  [:prompt, e.prompt, e.choices]
rescue FlowChat::Interrupt::Terminate => e
  context.session.destroy
  [:terminate, e.prompt, nil]
end