@@ -37,9 +37,9 @@ def validate_actions(actions)
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?
3939 raise WitException . new "The \' say\' action should take 2 arguments: session_id, msg. #{ learn_more } " if k == :say and v . arity != 2
40- raise WitException . new "The \' merge\' action should take 2 arguments: context, entities. #{ learn_more } " if k == :merge and v . arity != 2
41- raise WitException . new "The \' error\' action should take 2 arguments: session_id, msg . #{ learn_more } " if k == :error and v . arity != 2
42- raise WitException . new "The '#{ k } ' action should take 1 argument: context. #{ learn_more } " if k != :say and k != :merge and k != :error and v . arity != 1
40+ 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
42+ 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
4545end
@@ -78,7 +78,7 @@ def converse(session_id, msg, context={})
7878 req @access_token , Net ::HTTP ::Post , '/converse' , params , context
7979 end
8080
81- def run_actions ( session_id , message , context = { } , max_steps = DEFAULT_MAX_STEPS )
81+ def run_actions_ ( session_id , message , context , max_steps , user_message )
8282 raise WitException . new 'max iterations reached' unless max_steps > 0
8383
8484 rst = converse session_id , message , context
@@ -95,7 +95,7 @@ def run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
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 context , rst [ 'entities' ]
98+ context = @actions [ :merge ] . call session_id , context , rst [ 'entities' ] , user_message
9999 if context . nil?
100100 logger . warn 'missing context - did you forget to return it?'
101101 context = { }
@@ -104,18 +104,24 @@ def run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
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 context
107+ context = @actions [ action ] . call session_id , context
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 , 'unknown action: error'
115+ @actions [ :error ] . call session_id , context
116116 else
117117 raise WitException . new "unknown type: #{ type } "
118118 end
119119 return run_actions session_id , nil , context , max_steps - 1
120120 end
121+
122+ def run_actions ( session_id , message , context = { } , max_steps = DEFAULT_MAX_STEPS )
123+ return run_actions_ session_id , message , context , max_steps , message
124+ end
125+
126+ private :run_actions_
121127end
0 commit comments