@@ -36,9 +36,9 @@ def validate_actions(actions)
3636 actions . each_pair do |k , v |
3737 raise WitException . new "The '#{ k } ' action name should be a symbol" unless k . is_a? Symbol
3838 raise WitException . new "The '#{ k } ' action should be a lambda function" unless v . respond_to? :call and v . lambda?
39- raise WitException . new "The \' say\' action should take 2 arguments: session_id, msg. #{ learn_more } " if k == :say and v . arity != 2
39+ raise WitException . new "The \' say\' action should take 3 arguments: session_id, context, msg. #{ learn_more } " if k == :say and v . arity != 3
4040 raise WitException . new "The \' merge\' action should take 4 arguments: session_id, context, entities, msg. #{ learn_more } " if k == :merge and v . arity != 4
41- raise WitException . new "The \' error\' action should take 2 arguments: session_id, context. #{ learn_more } " if k == :error and v . arity != 2
41+ raise WitException . new "The \' error\' action should take 3 arguments: session_id, context, error . #{ learn_more } " if k == :error and v . arity != 3
4242 raise WitException . new "The '#{ k } ' action should take 2 arguments: session_id, context. #{ learn_more } " if k != :say and k != :merge and k != :error and v . arity != 2
4343 end
4444 return actions
@@ -91,11 +91,11 @@ def run_actions_(session_id, message, context, max_steps, user_message)
9191 raise WitException . new 'unknown action: say' unless @actions . has_key? :say
9292 msg = rst [ 'msg' ]
9393 logger . info "Executing say with: #{ msg } "
94- @actions [ :say ] . call session_id , msg
94+ @actions [ :say ] . call session_id , context . clone , msg
9595 elsif type == 'merge'
9696 raise WitException . new 'unknown action: merge' unless @actions . has_key? :merge
9797 logger . info 'Executing merge'
98- context = @actions [ :merge ] . call session_id , context , rst [ 'entities' ] , user_message
98+ context = @actions [ :merge ] . call session_id , context . clone , rst [ 'entities' ] , user_message
9999 if context . nil?
100100 logger . warn 'missing context - did you forget to return it?'
101101 context = { }
@@ -104,15 +104,15 @@ def run_actions_(session_id, message, context, max_steps, user_message)
104104 action = rst [ 'action' ] . to_sym
105105 raise WitException . new "unknown action: #{ action } " unless @actions . has_key? action
106106 logger . info "Executing action #{ action } "
107- context = @actions [ action ] . call session_id , context
107+ context = @actions [ action ] . call session_id , context . clone
108108 if context . nil?
109109 logger . warn 'missing context - did you forget to return it?'
110110 context = { }
111111 end
112112 elsif type == 'error'
113113 raise WitException . new 'unknown action: error' unless @actions . has_key? :error
114114 logger . info 'Executing error'
115- @actions [ :error ] . call session_id , context
115+ @actions [ :error ] . call session_id , context . clone , WitException . new ( 'Oops, I don\'t know what to do.' )
116116 else
117117 raise WitException . new "unknown type: #{ type } "
118118 end
0 commit comments