More logging on web-service calls and Promise replacement for forEach.
This commit is contained in:
parent
0ce8d48f09
commit
f62399c912
3 changed files with 82 additions and 67 deletions
|
@ -74,7 +74,7 @@ export class ConsoleDirectLine extends GBService {
|
||||||
|
|
||||||
// TODO: Remove *this* issue.
|
// TODO: Remove *this* issue.
|
||||||
let _this_ = this;
|
let _this_ = this;
|
||||||
directLineClient.then(function (client) {
|
directLineClient.then((client)=> {
|
||||||
client.Conversations.Conversations_StartConversation()
|
client.Conversations.Conversations_StartConversation()
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
return response.obj.conversationId;
|
return response.obj.conversationId;
|
||||||
|
@ -149,7 +149,7 @@ export class ConsoleDirectLine extends GBService {
|
||||||
// print other messages
|
// print other messages
|
||||||
activities.forEach(activity => {
|
activities.forEach(activity => {
|
||||||
console.log(activity.text);
|
console.log(activity.text);
|
||||||
});
|
}, this);
|
||||||
|
|
||||||
process.stdout.write('Command> ');
|
process.stdout.write('Command> ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Gets the authorization key for each instance from Bot Service.
|
// Gets the authorization key for each instance from Bot Service.
|
||||||
|
|
||||||
Promise.all(instances).then(async (instance: IGBInstance) => {
|
Promise.all(instances.map(async instance => {
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
url:
|
url:
|
||||||
|
@ -117,13 +117,22 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = await request(options);
|
let responseObject: any;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let response = await request(options);
|
||||||
|
responseObject = JSON.parse(response);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error calling Direct Line client, verify Bot endpoint on the cloud. Error is: ${error}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Serves the bot information object via http so clients can get
|
// Serves the bot information object via http so clients can get
|
||||||
// instance information stored on server.
|
// instance information stored on server.
|
||||||
|
|
||||||
let responseObject = JSON.parse(response);
|
|
||||||
server.get("/instances/:botId", (req, res) => {
|
server.get("/instances/:botId", (req, res) => {
|
||||||
|
|
||||||
|
logger.info('test');
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
// Returns the instance object to clients requesting bot info.
|
// Returns the instance object to clients requesting bot info.
|
||||||
|
@ -143,7 +152,14 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
response = await request(options);
|
let response: any;
|
||||||
|
try {
|
||||||
|
response = await request(options);
|
||||||
|
responseObject = JSON.parse(response);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error calling Speech to Text client. Error is: ${error}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
@ -202,11 +218,10 @@ export class GBMinService {
|
||||||
p["channel"].received(req, res);
|
p["channel"].received(req, res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}, this);
|
||||||
});
|
|
||||||
|
|
||||||
e.loadBot(min);
|
e.loadBot(min);
|
||||||
});
|
}, this);
|
||||||
|
|
||||||
|
|
||||||
// Serves individual URL for each bot conversational interface...
|
// Serves individual URL for each bot conversational interface...
|
||||||
|
@ -326,13 +341,13 @@ export class GBMinService {
|
||||||
// next();
|
// next();
|
||||||
|
|
||||||
// Specialized load for each min instance.
|
// Specialized load for each min instance.
|
||||||
});
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Performs package deployment in all .gbai or default. */
|
/** Performs package deployment in all .gbai or default. */
|
||||||
public deployPackages(core: IGBCoreService, server: any, appPackages: Array<IGBPackage>) {
|
public deployPackages(core: IGBCoreService, server: any, appPackages: Array<IGBPackage>) {
|
||||||
|
let _this = this;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let totalPackages = 0;
|
let totalPackages = 0;
|
||||||
|
@ -398,7 +413,7 @@ export class GBMinService {
|
||||||
} else {
|
} else {
|
||||||
appPackagesProcessed++;
|
appPackagesProcessed++;
|
||||||
}
|
}
|
||||||
});
|
}, _this);
|
||||||
|
|
||||||
|
|
||||||
WaitUntil()
|
WaitUntil()
|
||||||
|
@ -411,77 +426,76 @@ export class GBMinService {
|
||||||
.done(function (result) {
|
.done(function (result) {
|
||||||
logger.info(`App Package deployment done.`);
|
logger.info(`App Package deployment done.`);
|
||||||
|
|
||||||
core.syncDatabaseStructure(cb => {
|
core.syncDatabaseStructure();
|
||||||
|
|
||||||
/** Deploys all .gbot files first. */
|
/** Deploys all .gbot files first. */
|
||||||
|
|
||||||
botPackages.forEach(e => {
|
botPackages.forEach(e => {
|
||||||
logger.info(`Deploying bot: ${e}...`);
|
logger.info(`Deploying bot: ${e}...`);
|
||||||
this.deployer.deployBot(e, (data, err) => {
|
_this.deployer.deployBot(e);
|
||||||
logger.info(`Bot: ${e} deployed...`);
|
logger.info(`Bot: ${e} deployed...`);
|
||||||
});
|
}, _this);
|
||||||
});
|
|
||||||
|
|
||||||
/** Then all remaining generalPackages are loaded. */
|
/** Then all remaining generalPackages are loaded. */
|
||||||
|
|
||||||
generalPackages.forEach(filename => {
|
generalPackages.forEach(filename => {
|
||||||
|
|
||||||
let filenameOnly = Path.basename(filename);
|
let filenameOnly = Path.basename(filename);
|
||||||
logger.info(`Deploying package: ${filename}...`);
|
logger.info(`Deploying package: ${filename}...`);
|
||||||
|
|
||||||
/** Handles apps for general bots - .gbapp must stay out of deploy folder. */
|
/** Handles apps for general bots - .gbapp must stay out of deploy folder. */
|
||||||
|
|
||||||
if (Path.extname(filename) === ".gbapp" || Path.extname(filename) === ".gblib") {
|
if (Path.extname(filename) === ".gbapp" || Path.extname(filename) === ".gblib") {
|
||||||
|
|
||||||
|
|
||||||
/** Themes for bots. */
|
/** Themes for bots. */
|
||||||
|
|
||||||
} else if (Path.extname(filename) === ".gbtheme") {
|
} else if (Path.extname(filename) === ".gbtheme") {
|
||||||
server.use("/themes/" + filenameOnly, express.static(filename));
|
server.use("/themes/" + filenameOnly, express.static(filename));
|
||||||
logger.info(`Theme (.gbtheme) assets accessible at: ${"/themes/" + filenameOnly}.`);
|
logger.info(`Theme (.gbtheme) assets accessible at: ${"/themes/" + filenameOnly}.`);
|
||||||
|
|
||||||
|
|
||||||
/** Knowledge base for bots. */
|
/** Knowledge base for bots. */
|
||||||
|
|
||||||
} else if (Path.extname(filename) === ".gbkb") {
|
} else if (Path.extname(filename) === ".gbkb") {
|
||||||
server.use(
|
server.use(
|
||||||
"/kb/" + filenameOnly + "/subjects",
|
"/kb/" + filenameOnly + "/subjects",
|
||||||
express.static(UrlJoin(filename, "subjects"))
|
express.static(UrlJoin(filename, "subjects"))
|
||||||
);
|
);
|
||||||
logger.info(`KB (.gbkb) assets acessible at: ${"/kb/" + filenameOnly}.`);
|
logger.info(`KB (.gbkb) assets acessible at: ${"/kb/" + filenameOnly}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Path.extname(filename) === ".gbui" || filename.endsWith(".git")) {
|
else if (Path.extname(filename) === ".gbui" || filename.endsWith(".git")) {
|
||||||
// Already Handled
|
// Already Handled
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Unknown package format. */
|
/** Unknown package format. */
|
||||||
|
|
||||||
else {
|
else {
|
||||||
let err = new Error(`Package type not handled: ${filename}.`);
|
let err = new Error(`Package type not handled: ${filename}.`);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
totalPackages++;
|
totalPackages++;
|
||||||
});
|
|
||||||
|
|
||||||
WaitUntil()
|
|
||||||
.interval(1000)
|
|
||||||
.times(5)
|
|
||||||
.condition(function (cb) {
|
|
||||||
logger.info(`Waiting for package deployment...`);
|
|
||||||
cb(totalPackages == (generalPackages.length));
|
|
||||||
})
|
|
||||||
.done(function (result) {
|
|
||||||
if (botPackages.length === 0) {
|
|
||||||
logger.info(`The bot server is running empty: No bot instances have been found, at least one .gbot file must be deployed.`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logger.info(`Package deployment done.`);
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
WaitUntil()
|
||||||
|
.interval(1000)
|
||||||
|
.times(5)
|
||||||
|
.condition(function (cb) {
|
||||||
|
logger.info(`Waiting for package deployment...`);
|
||||||
|
cb(totalPackages == (generalPackages.length));
|
||||||
|
})
|
||||||
|
.done(function (result) {
|
||||||
|
if (botPackages.length === 0) {
|
||||||
|
logger.info(`The bot server is running empty: No bot instances have been found, at least one .gbot file must be deployed.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.info(`Package deployment done.`);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
reject(err)
|
reject(err)
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.1",
|
"async": "^2.6.1",
|
||||||
|
"async-promises": "^0.2.1",
|
||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"botbuilder": "^4.0.0-preview1.2",
|
"botbuilder": "^4.0.0-preview1.2",
|
||||||
"botbuilder-ai": "^4.0.0-preview1.2",
|
"botbuilder-ai": "^4.0.0-preview1.2",
|
||||||
|
@ -52,12 +53,12 @@
|
||||||
"sequelize": "^4.38.0",
|
"sequelize": "^4.38.0",
|
||||||
"sequelize-typescript": "^0.6.6",
|
"sequelize-typescript": "^0.6.6",
|
||||||
"sqlite3": "^4.0.2",
|
"sqlite3": "^4.0.2",
|
||||||
"swagger-client": "^3.8.15",
|
"swagger-client": "^3.8.19",
|
||||||
"tedious": "^2.6.4",
|
"tedious": "^2.6.4",
|
||||||
"url-join": "^4.0.0",
|
"url-join": "^4.0.0",
|
||||||
"wait-until": "^0.0.2",
|
"wait-until": "^0.0.2",
|
||||||
"walk-promise": "^0.2.0",
|
"walk-promise": "^0.2.0",
|
||||||
"winston": "^3.0.0"
|
"winston": "^3.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.1.4",
|
"@types/chai": "^4.1.4",
|
||||||
|
|
Loading…
Add table
Reference in a new issue