Migration to V4 is in progress. The Bot now can be loaded again.
This commit is contained in:
parent
4cc4e7236a
commit
3118b45543
6 changed files with 171 additions and 159 deletions
|
@ -58,7 +58,7 @@ export class GBConversationalService implements IGBConversationalService {
|
||||||
msg.value = value;
|
msg.value = value;
|
||||||
msg.type = "event";
|
msg.type = "event";
|
||||||
msg.name = name;
|
msg.name = name;
|
||||||
// TODO: dc.context.sendActivity(msg);
|
dc.context.sendActivity(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
async runNLP(
|
async runNLP(
|
||||||
|
|
|
@ -134,9 +134,11 @@ export class GBMinService {
|
||||||
(instance: IGBInstance, err) => {
|
(instance: IGBInstance, err) => {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
|
|
||||||
|
// TODO: Make dynamic: https://CHANGE.api.cognitive.microsoft.com/sts/v1.0
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
url:
|
url:
|
||||||
"https://api.cognitive.microsoft.com/sts/v1.0/issueToken",
|
"https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Ocp-Apim-Subscription-Key": instance.speechKey
|
"Ocp-Apim-Subscription-Key": instance.speechKey
|
||||||
|
@ -155,6 +157,10 @@ export class GBMinService {
|
||||||
conversationId: responseObject.conversationId
|
conversationId: responseObject.conversationId
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}).catch((reason) => {
|
||||||
|
let error = `Error loading Speech Service: ${reason}.`;
|
||||||
|
res.send(error);
|
||||||
|
logger.error(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let error = `Instance not found: ${botId}.`;
|
let error = `Instance not found: ${botId}.`;
|
||||||
|
@ -223,6 +229,7 @@ export class GBMinService {
|
||||||
logger.trace(
|
logger.trace(
|
||||||
`GeneralBots(${instance.engineName}) listening on: ${url}.`
|
`GeneralBots(${instance.engineName}) listening on: ${url}.`
|
||||||
);
|
);
|
||||||
|
|
||||||
server.post(`/api/messages/${instance.botId}`, (req, res) => {
|
server.post(`/api/messages/${instance.botId}`, (req, res) => {
|
||||||
|
|
||||||
adapter.processActivity(req, res, async (context) => {
|
adapter.processActivity(req, res, async (context) => {
|
||||||
|
@ -230,6 +237,18 @@ export class GBMinService {
|
||||||
const state = conversationState.get(context);
|
const state = conversationState.get(context);
|
||||||
const dc = min.dialogs.createContext(context, state);
|
const dc = min.dialogs.createContext(context, state);
|
||||||
|
|
||||||
|
const user = min.userState.get(dc.context);
|
||||||
|
if (!user.loaded) {
|
||||||
|
min.conversationalService.sendEvent(
|
||||||
|
dc,
|
||||||
|
"loadInstance",
|
||||||
|
min.instance // TODO: Send just necessary values.
|
||||||
|
);
|
||||||
|
|
||||||
|
user.loaded = true;
|
||||||
|
user.subjects = [];
|
||||||
|
}
|
||||||
|
|
||||||
if (context.activity.type === "conversationUpdate" &&
|
if (context.activity.type === "conversationUpdate" &&
|
||||||
context.activity.membersAdded.length > 0) {
|
context.activity.membersAdded.length > 0) {
|
||||||
|
|
||||||
|
@ -242,7 +261,7 @@ export class GBMinService {
|
||||||
|
|
||||||
if (!context.responded) {
|
if (!context.responded) {
|
||||||
await dc.begin('/');
|
await dc.begin('/');
|
||||||
}else if (context.activity.name === "whoAmI") {
|
} else if (context.activity.name === "whoAmI") {
|
||||||
dc.begin("/whoAmI");
|
dc.begin("/whoAmI");
|
||||||
} else if (context.activity.name === "showSubjects") {
|
} else if (context.activity.name === "showSubjects") {
|
||||||
dc.begin("/menu");
|
dc.begin("/menu");
|
||||||
|
@ -265,17 +284,6 @@ export class GBMinService {
|
||||||
await dc.continue();
|
await dc.continue();
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = min.userState.get(dc.context);
|
|
||||||
if (!user.loaded) {
|
|
||||||
// min.conversationalService.sendEvent(
|
|
||||||
// dc,
|
|
||||||
// "loadInstance",
|
|
||||||
// min.instance // TODO: Send a new thiner object.
|
|
||||||
// );
|
|
||||||
|
|
||||||
user.loaded = true;
|
|
||||||
user.subjects = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
appPackages.forEach(e => {
|
appPackages.forEach(e => {
|
||||||
e.onNewSession(min, dc);
|
e.onNewSession(min, dc);
|
||||||
|
|
|
@ -46,15 +46,13 @@
|
||||||
<style>
|
<style>
|
||||||
.loader {
|
.loader {
|
||||||
opacity: 0 !important;
|
opacity: 0 !important;
|
||||||
filter: opacity(0);
|
/* filter: opacity(0); Problem in recent Chrome 68+ */
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body style="background-color: lightgrey;">
|
<body style="background-color: lightgrey;">
|
||||||
<div id="root" class="loader"></div>
|
<div id="root"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -167,7 +167,7 @@ class GBUIApp extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let chat = <div />;
|
|
||||||
|
|
||||||
let playerComponent = "";
|
let playerComponent = "";
|
||||||
|
|
||||||
|
@ -234,6 +234,9 @@ class GBUIApp extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
let speechOptions;
|
let speechOptions;
|
||||||
|
let chat = <div />;
|
||||||
|
let gbCss =<div />;
|
||||||
|
|
||||||
|
|
||||||
let sideBar = (
|
let sideBar = (
|
||||||
<div className="sidebar">
|
<div className="sidebar">
|
||||||
|
@ -241,9 +244,9 @@ class GBUIApp extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (this.state.botConnection && this.state.instance) {
|
if (this.state.botConnection && this.state.instance) {
|
||||||
let token = this.state.instanceClient.speechToken;
|
let token = this.state.instanceClient.speechToken;
|
||||||
|
gbCss = <GBCss instance={this.state.instance} />;
|
||||||
|
|
||||||
function getToken() {
|
function getToken() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -251,7 +254,6 @@ class GBUIApp extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
speechOptions = {
|
speechOptions = {
|
||||||
speechRecognizer: new SpeechRecognizer({
|
speechRecognizer: new SpeechRecognizer({
|
||||||
locale: "pt-br",
|
locale: "pt-br",
|
||||||
|
@ -288,7 +290,7 @@ class GBUIApp extends React.Component {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<GBCss instance={this.state.instance} />
|
{gbCss}
|
||||||
{sideBar}
|
{sideBar}
|
||||||
<div className="player">{playerComponent}</div>
|
<div className="player">{playerComponent}</div>
|
||||||
{chat}
|
{chat}
|
||||||
|
|
|
@ -55,10 +55,14 @@ export class AskDialog extends IGBDialog {
|
||||||
|
|
||||||
min.dialogs.add("/answer", [
|
min.dialogs.add("/answer", [
|
||||||
async (dc, args) => {
|
async (dc, args) => {
|
||||||
const user = min.userState.get(dc.context);
|
|
||||||
|
|
||||||
|
// Initialize values.
|
||||||
|
|
||||||
|
const user = min.userState.get(dc.context);
|
||||||
let text = "";
|
let text = "";
|
||||||
|
|
||||||
|
// Handle extra text from FAQ.
|
||||||
|
|
||||||
if (args && args.query) {
|
if (args && args.query) {
|
||||||
text = args.query;
|
text = args.query;
|
||||||
} else if (args && args.fromFaq) {
|
} else if (args && args.fromFaq) {
|
||||||
|
@ -71,132 +75,130 @@ export class AskDialog extends IGBDialog {
|
||||||
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
||||||
}
|
}
|
||||||
|
|
||||||
await model.recognize(dc.context).then(res => {
|
// Spells check the input text before sending Search or NLP.
|
||||||
console.log(res);
|
|
||||||
}).catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// await min.conversationalService.runNLP(
|
// DISABLED:
|
||||||
// dc,
|
// AzureText.getSpelledText(
|
||||||
// min,
|
// min.instance.spellcheckerKey,
|
||||||
// text,
|
// text,
|
||||||
// (data, error) => {
|
// async (data, err) => {
|
||||||
|
// var data = res.text;
|
||||||
// if (!data) {
|
|
||||||
// let messages = [
|
|
||||||
// "Desculpe-me, não encontrei nada a respeito.",
|
|
||||||
// "Lamento... Não encontrei nada sobre isso. Vamos tentar novamente?",
|
|
||||||
// "Desculpe-me, não achei nada parecido. Poderia tentar escrever de outra forma?"
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
|
||||||
// dc.replace("/ask", { isReturning: true });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
// if (text === "") {
|
|
||||||
// dc.replace("/ask");
|
|
||||||
// } else {
|
|
||||||
// // AzureText.getSpelledText(
|
|
||||||
// // min.instance.spellcheckerKey,
|
|
||||||
// // text,
|
|
||||||
// // async (data, err) => {
|
|
||||||
// var data = text;
|
|
||||||
// if (data != text) {
|
// if (data != text) {
|
||||||
// logger.trace("Spelled Text: " + data);
|
// logger.trace("Spelled Text: " + data);
|
||||||
// text = data;
|
// text = data;
|
||||||
// }
|
// }
|
||||||
// user.lastQuestion = data;
|
|
||||||
|
|
||||||
// service.ask(
|
user.lastQuestion = text;
|
||||||
// min.instance,
|
|
||||||
// text,
|
|
||||||
// min.instance.searchScore,
|
|
||||||
// user.subjects,
|
|
||||||
// async resultsA => {
|
|
||||||
// min.conversationalService.sendEvent(dc, "stop", null);
|
|
||||||
|
|
||||||
// if (resultsA && resultsA.answer) {
|
// Searches KB for the first time.
|
||||||
// user.isAsking = false;
|
|
||||||
// service.sendAnswer(min.conversationalService,
|
|
||||||
// dc,
|
|
||||||
// resultsA.answer
|
|
||||||
// );
|
|
||||||
// user.lastQuestionId = resultsA.questionId;
|
|
||||||
|
|
||||||
// dc.replace("/ask", { isReturning: true });
|
service.ask(
|
||||||
// } else {
|
min.instance,
|
||||||
// //if (min.isAsking) {
|
text,
|
||||||
// // Second time with no filter.
|
min.instance.searchScore,
|
||||||
|
user.subjects,
|
||||||
|
async resultsA => {
|
||||||
|
|
||||||
// service.ask(
|
// Stops any content on projector.
|
||||||
// min.instance,
|
|
||||||
// text,
|
|
||||||
// min.instance.searchScore,
|
|
||||||
// null,
|
|
||||||
// async resultsB => {
|
|
||||||
// if (resultsB && resultsB.answer) {
|
|
||||||
// const user = min.userState.get(dc.context);
|
|
||||||
|
|
||||||
// user.isAsking = false;
|
min.conversationalService.sendEvent(dc, "stop", null);
|
||||||
|
|
||||||
// if (user.subjects.length > 0) {
|
// If there is some result, answer immediately.
|
||||||
// let subjectText =
|
|
||||||
// `${KBService.getSubjectItemsSeparatedBySpaces(
|
|
||||||
// user.subjects
|
|
||||||
// )}`;
|
|
||||||
|
|
||||||
// let messages = [
|
if (resultsA && resultsA.answer) {
|
||||||
// `Respondendo nao apenas sobre ${subjectText}... `,
|
|
||||||
// `Respondendo de modo mais abrangente...`,
|
|
||||||
// `Vou te responder de modo mais abrangente...
|
|
||||||
// Não apenas sobre ${subjectText}`
|
|
||||||
// ];
|
|
||||||
// dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
|
||||||
// }
|
|
||||||
// user.isAsking = false;
|
|
||||||
// service.sendAnswer(min.conversationalService,
|
|
||||||
// dc,
|
|
||||||
// resultsB.answer
|
|
||||||
// );
|
|
||||||
// dc.replace("/ask", { isReturning: true });
|
|
||||||
|
|
||||||
// user.lastQuestionId = resultsB.questionId;
|
// Saves some context info.
|
||||||
// } else {
|
|
||||||
|
|
||||||
// await min.conversationalService.runNLP(
|
user.isAsking = false;
|
||||||
// dc,
|
user.lastQuestionId = resultsA.questionId;
|
||||||
// min,
|
|
||||||
// text,
|
|
||||||
// (data, error) => {
|
|
||||||
|
|
||||||
// if (!data) {
|
// Sends the answer to all outputs, including projector.
|
||||||
// let messages = [
|
|
||||||
// "Desculpe-me, não encontrei nada a respeito.",
|
|
||||||
// "Lamento... Não encontrei nada sobre isso. Vamos tentar novamente?",
|
|
||||||
// "Desculpe-me, não achei nada parecido. Poderia tentar escrever de outra forma?"
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
service.sendAnswer(min.conversationalService,
|
||||||
// dc.replace("/ask", { isReturning: true });
|
dc,
|
||||||
// }
|
resultsA.answer
|
||||||
// }
|
);
|
||||||
// );
|
|
||||||
// }
|
// Goes to ask loop, again.
|
||||||
// }
|
|
||||||
// );
|
dc.replace("/ask", { isReturning: true });
|
||||||
// }
|
|
||||||
// }
|
} else {
|
||||||
// );
|
|
||||||
// }
|
// Second time running Search, now with no filter.
|
||||||
//); }
|
|
||||||
|
service.ask(
|
||||||
|
min.instance,
|
||||||
|
text,
|
||||||
|
min.instance.searchScore,
|
||||||
|
null,
|
||||||
|
async resultsB => {
|
||||||
|
|
||||||
|
// If there is some result, answer immediately.
|
||||||
|
|
||||||
|
if (resultsB && resultsB.answer) {
|
||||||
|
|
||||||
|
// Saves some context info.
|
||||||
|
|
||||||
|
const user = min.userState.get(dc.context);
|
||||||
|
user.isAsking = false;
|
||||||
|
user.lastQuestionId = resultsB.questionId;
|
||||||
|
|
||||||
|
// Inform user that a broader search will be used.
|
||||||
|
|
||||||
|
if (user.subjects.length > 0) {
|
||||||
|
let subjectText =
|
||||||
|
`${KBService.getSubjectItemsSeparatedBySpaces(
|
||||||
|
user.subjects
|
||||||
|
)}`;
|
||||||
|
let messages = [
|
||||||
|
`Respondendo nao apenas sobre ${subjectText}... `,
|
||||||
|
`Respondendo de modo mais abrangente...`,
|
||||||
|
`Vou te responder de modo mais abrangente...
|
||||||
|
Não apenas sobre ${subjectText}`
|
||||||
|
];
|
||||||
|
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sends the answer to all outputs, including projector.
|
||||||
|
|
||||||
|
service.sendAnswer(min.conversationalService,
|
||||||
|
dc,
|
||||||
|
resultsB.answer
|
||||||
|
);
|
||||||
|
dc.replace("/ask", { isReturning: true });
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
await min.conversationalService.runNLP(
|
||||||
|
dc,
|
||||||
|
min,
|
||||||
|
text,
|
||||||
|
(data, error) => {
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
let messages = [
|
||||||
|
"Desculpe-me, não encontrei nada a respeito.",
|
||||||
|
"Lamento... Não encontrei nada sobre isso. Vamos tentar novamente?",
|
||||||
|
"Desculpe-me, não achei nada parecido. Poderia tentar escrever de outra forma?"
|
||||||
|
];
|
||||||
|
|
||||||
|
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
||||||
|
dc.replace("/ask", { isReturning: true });
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
bot
|
|
||||||
min.dialogs.add("/ask", [
|
min.dialogs.add("/ask", [
|
||||||
async (dc, args) => {
|
async (dc, args) => {
|
||||||
const user = min.userState.get(dc.context);
|
const user = min.userState.get(dc.context);
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
|
"keyofStringsOnly": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
"mapRoot": "./dist/",
|
"mapRoot": "./dist/",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
|
Loading…
Add table
Reference in a new issue