@@ -4,17 +4,18 @@ class Controller < ApplicationController
44 include Stealth ::Controller ::InterruptDetect
55 include Stealth ::Controller ::DevJumps
66 include Stealth ::Controller ::Replies
7- include Stealth ::Controller ::IntentClassifier
7+ include Stealth ::Controller ::IntentClassifier
88
99 attr_reader :current_message , :current_service , :current_session_id
10- attr_accessor :nlp_result , :pos
10+ attr_accessor :nlp_result , :pos , :current_session , :previous_session
1111
1212 def initialize ( service_event :, pos : nil )
1313 super ( )
1414 @current_message = service_event
1515 @current_service = service_event . service
1616 @current_session_id = service_event . sender_id
17- # @nlp_result = service_event.nlp_result
17+ @current_session = Stealth ::Session . new ( id : current_session_id )
18+ @previous_session = Stealth ::Session . new ( id : current_session_id , type : :previous )
1819 @pos = pos
1920 @progressed = false
2021 end
@@ -31,72 +32,6 @@ def progressed?
3132 @progressed
3233 end
3334
34- # def flow_controller
35- # @flow_controller ||= begin
36- # flow_controller = [current_session.flow_string, 'controller'].join('_').classify.constantize
37- # flow_controller.new(service_message: @current_message, pos: @pos)
38- # end
39- # end
40-
41- def current_session
42- @current_session ||= Stealth ::Session . new ( id : current_session_id )
43- end
44-
45- def previous_session
46- @previous_session ||= Stealth ::Session . new (
47- id : current_session_id ,
48- type : :previous
49- )
50- end
51-
52- # def action(action: nil)
53- # begin
54- # # Grab a mutual exclusion lock on the session
55- # lock_session!(
56- # session_slug: Session.slugify(
57- # flow: current_session.flow_string,
58- # state: current_session.state_string
59- # )
60- # )
61-
62- # @action_name = action
63- # @action_name ||= current_session.state_string
64-
65- # # Check if the user needs to be redirected
66- # if current_session.flow.current_state.redirects_to.present?
67- # Stealth::Logger.l(
68- # topic: "redirect",
69- # message: "From #{current_session.session} to #{current_session.flow.current_state.redirects_to.session}"
70- # )
71- # step_to(session: current_session.flow.current_state.redirects_to, pos: @pos)
72- # return
73- # end
74-
75- # run_callbacks :action do
76- # begin
77- # flow_controller.send(@action_name)
78- # unless flow_controller.progressed?
79- # run_catch_all(reason: 'Did not send replies, update session, or step')
80- # end
81- # rescue Stealth::Errors::Halted
82- # Stealth::Logger.l(
83- # topic: "session",
84- # message: "User #{current_session_id}: session halted."
85- # )
86- # rescue StandardError => e
87- # if e.class == Stealth::Errors::UnrecognizedMessage
88- # run_unrecognized_message(err: e)
89- # else
90- # run_catch_all(err: e)
91- # end
92- # end
93- # end
94- # ensure
95- # # Release mutual exclusion lock on the session
96- # release_lock!
97- # end
98- # end
99-
10035 def step_to_in ( delay , session : nil , flow : nil , state : nil , slug : nil )
10136 if interrupt_detected?
10237 run_interrupt_action
@@ -151,7 +86,13 @@ def step_to(session: nil, flow: nil, state: nil, slug: nil, pos: nil, locals: ni
15186 state : state ,
15287 slug : slug
15388 )
154- step ( flow : flow , state : state , pos : pos , locals : locals )
89+ current_session . locals = locals
90+
91+ # Workaround for update_session_to.
92+ if previous_session . before_update_session_to_locals . present?
93+ current_session . locals = previous_session . before_update_session_to_locals
94+ end
95+ step ( flow : flow , state : state , pos : pos )
15596 end
15697
15798 def update_session_to ( session : nil , flow : nil , state : nil , slug : nil , locals : nil )
@@ -166,8 +107,8 @@ def update_session_to(session: nil, flow: nil, state: nil, slug: nil, locals: ni
166107 state : state ,
167108 slug : slug
168109 )
169-
170- update_session ( flow : flow , state : state , locals : locals )
110+ current_session . before_update_session_to_locals = locals
111+ update_session ( flow : flow , state : state )
171112 end
172113
173114 def set_back_to ( session : nil , flow : nil , state : nil , slug : nil )
@@ -212,15 +153,10 @@ def halt!
212153
213154 private
214155
215- def update_session ( flow :, state :, locals : nil )
156+ def update_session ( flow :, state :)
216157 @progressed = :updated_session
217- @current_session = Session . new ( id : current_session_id )
218-
219- unless current_session . flow_string == flow . to_s && current_session . state_string == state . to_s
220- @current_session . locals = locals
221- @current_session . set_session ( new_flow : flow , new_state : state )
222- end
223158
159+ current_session . set_session ( new_flow : flow , new_state : state )
224160 end
225161
226162 def store_back_to_session ( flow :, state :)
@@ -231,16 +167,12 @@ def store_back_to_session(flow:, state:)
231167 back_to_session . set_session ( new_flow : flow , new_state : state )
232168 end
233169
234- def step ( flow :, state :, pos : nil , locals : nil )
235- update_session ( flow : flow , state : state , locals : locals )
170+ def step ( flow :, state :, pos : nil )
171+ update_session ( flow : flow , state : state )
236172 Stealth . trigger_flow ( flow , state , @current_message )
237173
238174 @progressed = :stepped
239- # @flow_controller = nil
240- # @current_flow = current_session.flow
241175 @pos = pos
242-
243- # flow_controller.action(action: state)
244176 end
245177
246178 def get_flow_and_state ( session : nil , flow : nil , state : nil , slug : nil )
@@ -258,10 +190,6 @@ def get_flow_and_state(session: nil, flow: nil, state: nil, slug: nil)
258190 end
259191
260192 if flow . present?
261- # Deprecated
262- # if state.blank?
263- # state = FlowMap.flow_spec[flow.to_sym].states.keys.first.to_s
264- # end
265193
266194 if state . blank?
267195 # Access the existing FlowManager instance that has the registered flows
0 commit comments