@@ -251,14 +251,20 @@ function conversationParseRequest(req, res, next) {
251251              server_response : body , 
252252              query : req . body . q 
253253            } ) ; 
254-           //Update conversation table with updated conversation response from rasa ... 
255-           db . run ( 'update conversations set conversation = ? where conversation_id = ?' ,  [ body ,  req . body . conversation_id ] ,  function ( err )  { 
256-             if  ( err )  { 
257-               logger . winston . error ( "Error updating the record" ) ; 
258-             }  else  { 
259-               sendOutput ( 200 ,  res ,  body ) ; 
260-             } 
261-           } ) ; 
254+             //Maybe we should run this before the DB update and save both to the DB at the same time and then return both responses to the client 
255+             request ( {  method : 'POST' ,  uri : global . rasa_endpoint  +  "/conversations/"  +  req . body . conversation_id  +  "/predict" ,  body : JSON . stringify ( req . body )  } , 
256+             function  ( err ,  response ,  predict_body )  { 
257+               //console.log(body); 
258+               //Update conversation table with updated conversation response from rasa ... 
259+               db . run ( 'update conversations set conversation = ? where conversation_id = ?' ,  [ predict_body ,  req . body . conversation_id ] ,  function ( err )  { 
260+                 if  ( err )  { 
261+                   logger . winston . error ( "Error updating the record" ) ; 
262+                 }  else  { 
263+                   
264+                   sendOutput ( 200 ,  res ,  predict_body ) ; 
265+                 } 
266+               } ) ; 
267+             } ) ; 
262268        }  catch  ( err )  { 
263269          logger . winston . error ( err ) ; 
264270          sendOutput ( 500 ,  res ,  '{"error" : '  +  err  +  "}" ) ; 
@@ -290,6 +296,7 @@ function restartRasaCoreConversation(req, res, next) {
290296        if  ( err )  { 
291297          logger . winston . error ( "Error updating the record" ) ; 
292298        }  else  { 
299+           //Predict the next action? 
293300          sendOutput ( 200 ,  res ,  body ) ; 
294301        } 
295302      } ) ; 
0 commit comments