Dialog being called again.
This commit is contained in:
parent
3118b45543
commit
9bd5995115
4 changed files with 146 additions and 142 deletions
|
@ -33,6 +33,7 @@
|
|||
"use strict";
|
||||
|
||||
const gBuilder = require("botbuilder");
|
||||
const {TextPrompt} = require("botbuilder-dialogs");
|
||||
const UrlJoin = require("url-join");
|
||||
const Path = require("path");
|
||||
const Fs = require("fs");
|
||||
|
@ -192,7 +193,6 @@ export class GBMinService {
|
|||
min.core = _this_.core;
|
||||
min.conversationalService = _this_.conversationalService;
|
||||
|
||||
|
||||
_this_.core.loadInstance(min.botId, (data, err) => {
|
||||
|
||||
min.instance = data;
|
||||
|
@ -230,6 +230,10 @@ export class GBMinService {
|
|||
`GeneralBots(${instance.engineName}) listening on: ${url}.`
|
||||
);
|
||||
|
||||
|
||||
|
||||
min.dialogs.add('textPrompt', new TextPrompt());
|
||||
|
||||
server.post(`/api/messages/${instance.botId}`, (req, res) => {
|
||||
|
||||
adapter.processActivity(req, res, async (context) => {
|
||||
|
@ -439,7 +443,7 @@ export class GBMinService {
|
|||
|
||||
} else if (Path.extname(filename) === ".gbtheme") {
|
||||
server.use("/themes/" + filenameOnly, express.static(filename));
|
||||
logger.trace(`Theme (.gbtheme) assets acessible at: ${"/themes/" + filenameOnly}.`);
|
||||
logger.trace(`Theme (.gbtheme) assets accessible at: ${"/themes/" + filenameOnly}.`);
|
||||
|
||||
|
||||
/** Knowledge base for bots. */
|
||||
|
|
|
@ -92,12 +92,11 @@ export class AskDialog extends IGBDialog {
|
|||
|
||||
// Searches KB for the first time.
|
||||
|
||||
service.ask(
|
||||
let resultsA = await service.ask(
|
||||
min.instance,
|
||||
text,
|
||||
min.instance.searchScore,
|
||||
user.subjects,
|
||||
async resultsA => {
|
||||
user.subjects);
|
||||
|
||||
// Stops any content on projector.
|
||||
|
||||
|
@ -127,12 +126,11 @@ export class AskDialog extends IGBDialog {
|
|||
|
||||
// Second time running Search, now with no filter.
|
||||
|
||||
service.ask(
|
||||
let resultsB = await service.ask(
|
||||
min.instance,
|
||||
text,
|
||||
min.instance.searchScore,
|
||||
null,
|
||||
async resultsB => {
|
||||
null);
|
||||
|
||||
// If there is some result, answer immediately.
|
||||
|
||||
|
@ -190,12 +188,8 @@ export class AskDialog extends IGBDialog {
|
|||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
|
|
@ -37,19 +37,19 @@ const Parse = require("csv-parse");
|
|||
const Async = require("async");
|
||||
const UrlJoin = require("url-join");
|
||||
const Walk = require("fs-walk");
|
||||
const WaitUntil = require("wait-until");
|
||||
const marked = require("marked");
|
||||
import { Sequelize } from "sequelize-typescript";
|
||||
import { GBConfigService } from './../../core.gbapp/services/GBConfigService';
|
||||
import { GuaribasQuestion, GuaribasAnswer, GuaribasSubject } from "../models";
|
||||
import { GBServiceCallback, IGBCoreService, IGBConversationalService, IGBInstance } from "botlib";
|
||||
import { AzureSearch } from "pragmatismo-io-framework";
|
||||
import { GBCoreService } from 'deploy/core.gbapp/services/GBCoreService';
|
||||
import { GBDeployer } from "../../core.gbapp/services/GBDeployer";
|
||||
import { GBConversationalService } from "../../core.gbapp/services/GBConversationalService";
|
||||
|
||||
import { GuaribasPackage } from "../../core.gbapp/models/GBModel";
|
||||
|
||||
export class KBServiceSearchResults {
|
||||
answer: GuaribasAnswer;
|
||||
questionId: number;
|
||||
}
|
||||
|
||||
export class KBService {
|
||||
|
||||
getAnswerById(
|
||||
|
@ -103,13 +103,14 @@ export class KBService {
|
|||
});
|
||||
}
|
||||
|
||||
ask(
|
||||
async ask(
|
||||
instance: IGBInstance,
|
||||
what: string,
|
||||
searchScore: number,
|
||||
subjects: GuaribasSubject[],
|
||||
cb: GBServiceCallback<any>
|
||||
) {
|
||||
subjects: GuaribasSubject[]
|
||||
): Promise<KBServiceSearchResults> {
|
||||
|
||||
return new Promise<KBServiceSearchResults>((resolve, reject) => {
|
||||
|
||||
// Builds search query.
|
||||
|
||||
|
@ -124,7 +125,7 @@ export class KBService {
|
|||
let text = KBService.getSubjectItemsSeparatedBySpaces(
|
||||
subjects
|
||||
);
|
||||
if (text){
|
||||
if (text) {
|
||||
what = `${what} ${text}`;
|
||||
}
|
||||
}
|
||||
|
@ -152,26 +153,31 @@ export class KBService {
|
|||
instance.instanceId,
|
||||
results[0].answerId,
|
||||
(answer, err) => {
|
||||
cb({ answer: answer, questionId: results[0].questionId }, null);
|
||||
if (err) { reject(err); } else {
|
||||
resolve({ answer: answer, questionId: results[0].questionId });
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
cb(null, null);
|
||||
resolve(null);
|
||||
}
|
||||
} else {
|
||||
cb(null, null);
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.getAnswerByText(instance.instanceId, what, (data, err) => {
|
||||
if (data) {
|
||||
cb({ answer: data.answer, questionId: data.question.questionId }, null);
|
||||
resolve({ answer: data.answer, questionId: data.question.questionId });
|
||||
}
|
||||
else {
|
||||
cb(null, err);
|
||||
if (err) { reject(err); } else {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSearchSchema(indexName) {
|
||||
|
|
Loading…
Add table
Reference in a new issue