Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
blueprintName:items.execution.name
};
}

console.log(items);
$scope.botName = items.name;
$scope.botParams = items.inputFormFields;
$scope.botEditParams = {};
Expand Down Expand Up @@ -292,6 +292,9 @@
}
reqBody.choiceParam = $scope.choiceParam;
}
} else if ($scope.botType === 'api') {
reqBody.data = $scope.botEditParams;
reqBody.flowId = items.flowId;
}
$scope.botExecuteMethod(items.id,reqBody);
} else if (type === 'blueprints') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<div ng-if="botType === 'blueprints' && originalBlueprintList.length===0" class="alert alert-info padding6 text-center" align="center">
No Matching Blueprint Found in the Database
</div>
<div ng-if="botType ==='script'" class="scriptExecution param-table bot-info-wrapper">
<div ng-if="botType ==='script' || botType ==='api'" class="scriptExecution param-table bot-info-wrapper">
<table class="table table-bordered">
<thead>
<tr class="paramRow">
Expand Down
104 changes: 104 additions & 0 deletions server/app/engine/bots/apiExecutor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright [2016] [Relevance Lab]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var logger = require('_pr/logger')(module);
var async = require("async");
var uuid = require('node-uuid');
var logsDao = require('_pr/model/dao/logsdao.js');
var noticeService = require('_pr/services/noticeService.js');
var auditQueue = require('_pr/config/global-data.js');
var request = require('request');
const errorType = 'apiExecutor';
var apiExecutor = module.exports = {};

apiExecutor.execute = function execute(botDetail,reqBody, auditTrail, userName,botHostDetails,callback) {
var actionLogId = uuid.v4();
var reqBodyObj = {
"inputs": reqBody.data
};
var botAuditTrailObj = {
botId: botDetail._id,
actionId: actionLogId
}
callback(null, botAuditTrailObj);
var serverUrl = "http://" + botHostDetails.hostIP + ':' + botHostDetails.hostPort; //currently hardcoded; will have to be made dynamic later
var executorUrl = '/bot/' + botDetail.id + '/exec';
var options = {
url: serverUrl + executorUrl,
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
},
json: true,
body: reqBodyObj
};

request.post(options, function (err, res, body) {
if(res){
if (res.statusCode === 200) {
var auditQueueDetails = {
userName: userName,
botId: botDetail.id,
bot_id: botDetail._id,
logRefId: [],
auditId: actionLogId,
instanceLog: '',
instanceIP: '',
auditTrailId: auditTrail._id,
remoteAuditId: res.body.ref,
link: res.body.link,
status: "pending",
serverUrl: serverUrl,
env: "local",
retryCount: 0
}
auditQueue.setAudit(auditQueueDetails);
return;
} else {
logger.error(err);
var logData = {
botId: botDetail._id,
botRefId: actionLogId,
err: true,
log: "Error in BOT Engine executor:",
timestamp: new Date().getTime(),
}
logsDao.insertLog(logData);
noticeService.updater(actionId,'log',logData);
var resultTaskExecution = {
"actionStatus": 'failed',
"status": 'failed',
"endedOn": new Date().getTime(),
"actionLogId": actionLogId
};
auditTrailService.updateAuditTrail('BOT', auditTrail._id, resultTaskExecution, function (err, data) {
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
noticeService.notice(userName, {
title: "API BOT Execution",
body: res.statusCode === 502?"Bot Enginge is not running":"Error in API executor"
}, "error", function (err, data) {
if (err) {
logger.error("Error in Notification Service, ", err);
}
return;
});
});
}
}
})
}
5 changes: 5 additions & 0 deletions server/app/model/bots/1.1/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ var BotSchema = new Schema ({
required: false,
trim: true
},
flowId: {
type: String,
required: false,
trim: true
},
lastExecutionStatus: {
type: String,
required: false,
Expand Down
Loading