Skip to content

Commit 43d83fa

Browse files
committed
- Additional support for chats
1 parent b702140 commit 43d83fa

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

server/routes/rasa_router.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

web/src/app/components/chat/chat.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ function ChatController($scope, $rootScope, $interval, $http, Rasa_Version, Sett
5050
$scope.selected_conversation = selected_conversation;
5151
if (selected_conversation.conversation) {
5252
var conversation = JSON.parse(selected_conversation.conversation);
53-
if (conversation && conversation.events) {
54-
$scope.transactions = conversation.events;
53+
if (conversation && conversation.tracker.events) {
54+
$scope.transactions = conversation.tracker.events;
5555
}
5656
$scope.loadConversationStory(selected_conversation.conversation_id);
5757
}
@@ -85,9 +85,9 @@ function ChatController($scope, $rootScope, $interval, $http, Rasa_Version, Sett
8585
$scope.test_text = "";
8686
$('.write_msg').focus();
8787
$http.post(appConfig.api_endpoint_v2 + '/rasa/conversations/messages', JSON.stringify(reqMessage)).then(function (response) {
88-
if (response.data && response.data.events) {
88+
if (response.data && response.data.tracker) {
8989
$scope.selected_conversation.conversation = JSON.stringify(response.data);
90-
$scope.transactions = response.data.events;
90+
$scope.transactions = response.data.tracker.events;
9191
$scope.loadConversationStory($scope.selected_conversation.conversation_id);
9292
scrollToMessage();
9393
}

0 commit comments

Comments
 (0)