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.type = "event";
|
||||
msg.name = name;
|
||||
// TODO: dc.context.sendActivity(msg);
|
||||
dc.context.sendActivity(msg);
|
||||
}
|
||||
|
||||
async runNLP(
|
||||
|
|
|
@ -134,9 +134,11 @@ export class GBMinService {
|
|||
(instance: IGBInstance, err) => {
|
||||
if (instance) {
|
||||
|
||||
// TODO: Make dynamic: https://CHANGE.api.cognitive.microsoft.com/sts/v1.0
|
||||
|
||||
let options = {
|
||||
url:
|
||||
"https://api.cognitive.microsoft.com/sts/v1.0/issueToken",
|
||||
"https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Ocp-Apim-Subscription-Key": instance.speechKey
|
||||
|
@ -155,6 +157,10 @@ export class GBMinService {
|
|||
conversationId: responseObject.conversationId
|
||||
})
|
||||
);
|
||||
}).catch((reason) => {
|
||||
let error = `Error loading Speech Service: ${reason}.`;
|
||||
res.send(error);
|
||||
logger.error(error);
|
||||
});
|
||||
} else {
|
||||
let error = `Instance not found: ${botId}.`;
|
||||
|
@ -223,6 +229,7 @@ export class GBMinService {
|
|||
logger.trace(
|
||||
`GeneralBots(${instance.engineName}) listening on: ${url}.`
|
||||
);
|
||||
|
||||
server.post(`/api/messages/${instance.botId}`, (req, res) => {
|
||||
|
||||
adapter.processActivity(req, res, async (context) => {
|
||||
|
@ -230,6 +237,18 @@ export class GBMinService {
|
|||
const state = conversationState.get(context);
|
||||
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" &&
|
||||
context.activity.membersAdded.length > 0) {
|
||||
|
||||
|
@ -242,7 +261,7 @@ export class GBMinService {
|
|||
|
||||
if (!context.responded) {
|
||||
await dc.begin('/');
|
||||
}else if (context.activity.name === "whoAmI") {
|
||||
} else if (context.activity.name === "whoAmI") {
|
||||
dc.begin("/whoAmI");
|
||||
} else if (context.activity.name === "showSubjects") {
|
||||
dc.begin("/menu");
|
||||
|
@ -265,17 +284,6 @@ export class GBMinService {
|
|||
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 => {
|
||||
e.onNewSession(min, dc);
|
||||
|
|
|
@ -34,27 +34,25 @@
|
|||
<html lang="pt-br" style="width:100%;height:100%">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="./css/botchat.css" />
|
||||
<link rel="stylesheet" type="text/css" href="./css/pragmatismo.css" />
|
||||
<script src="./js/botchat.js"></script>
|
||||
<title>General Bots Community Edition | pragmatismo.io</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="./css/botchat.css" />
|
||||
<link rel="stylesheet" type="text/css" href="./css/pragmatismo.css" />
|
||||
<script src="./js/botchat.js"></script>
|
||||
<title>General Bots Community Edition | pragmatismo.io</title>
|
||||
|
||||
<style>
|
||||
.loader {
|
||||
opacity: 0 !important;
|
||||
filter: opacity(0);
|
||||
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.loader {
|
||||
opacity: 0 !important;
|
||||
/* filter: opacity(0); Problem in recent Chrome 68+ */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body style="background-color: lightgrey;">
|
||||
<div id="root" class="loader"></div>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
|
@ -145,7 +145,7 @@ class GBUIApp extends React.Component {
|
|||
.subscribe(activity => {
|
||||
_this_.setState({ instance: activity.value });
|
||||
});
|
||||
|
||||
|
||||
botConnection.activity$
|
||||
.filter(activity => activity.type === "event" && activity.name === "stop")
|
||||
.subscribe(activity => {
|
||||
|
@ -167,7 +167,7 @@ class GBUIApp extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
let chat = <div />;
|
||||
|
||||
|
||||
let playerComponent = "";
|
||||
|
||||
|
@ -234,16 +234,19 @@ class GBUIApp extends React.Component {
|
|||
}
|
||||
|
||||
let speechOptions;
|
||||
let chat = <div />;
|
||||
let gbCss =<div />;
|
||||
|
||||
|
||||
let sideBar = (
|
||||
<div className="sidebar">
|
||||
<SidebarMenu chat={this.chat} instance={this.state.instance} />
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (this.state.botConnection && this.state.instance) {
|
||||
let token = this.state.instanceClient.speechToken;
|
||||
gbCss = <GBCss instance={this.state.instance} />;
|
||||
|
||||
function getToken() {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -251,7 +254,6 @@ class GBUIApp extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
speechOptions = {
|
||||
speechRecognizer: new SpeechRecognizer({
|
||||
locale: "pt-br",
|
||||
|
@ -288,7 +290,7 @@ class GBUIApp extends React.Component {
|
|||
|
||||
return (
|
||||
<div>
|
||||
<GBCss instance={this.state.instance} />
|
||||
{gbCss}
|
||||
{sideBar}
|
||||
<div className="player">{playerComponent}</div>
|
||||
{chat}
|
||||
|
|
|
@ -50,15 +50,19 @@ export class AskDialog extends IGBDialog {
|
|||
appId: min.instance.nlpAppId,
|
||||
subscriptionKey: min.instance.nlpSubscriptionKey,
|
||||
serviceEndpoint: min.instance.nlpServerUrl
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
min.dialogs.add("/answer", [
|
||||
async (dc, args) => {
|
||||
const user = min.userState.get(dc.context);
|
||||
|
||||
// Initialize values.
|
||||
|
||||
const user = min.userState.get(dc.context);
|
||||
let text = "";
|
||||
|
||||
// Handle extra text from FAQ.
|
||||
|
||||
if (args && args.query) {
|
||||
text = args.query;
|
||||
} else if (args && args.fromFaq) {
|
||||
|
@ -71,132 +75,130 @@ export class AskDialog extends IGBDialog {
|
|||
dc.context.sendActivity(messages[0]); // TODO: Handle rnd.
|
||||
}
|
||||
|
||||
await model.recognize(dc.context).then(res => {
|
||||
console.log(res);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
// Spells check the input text before sending Search or NLP.
|
||||
|
||||
// await min.conversationalService.runNLP(
|
||||
// dc,
|
||||
// min,
|
||||
// DISABLED:
|
||||
// AzureText.getSpelledText(
|
||||
// min.instance.spellcheckerKey,
|
||||
// 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 });
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
// if (text === "") {
|
||||
// dc.replace("/ask");
|
||||
// } else {
|
||||
// // AzureText.getSpelledText(
|
||||
// // min.instance.spellcheckerKey,
|
||||
// // text,
|
||||
// // async (data, err) => {
|
||||
// var data = text;
|
||||
// if (data != text) {
|
||||
// logger.trace("Spelled Text: " + data);
|
||||
// text = data;
|
||||
// }
|
||||
// user.lastQuestion = data;
|
||||
|
||||
// service.ask(
|
||||
// min.instance,
|
||||
// text,
|
||||
// min.instance.searchScore,
|
||||
// user.subjects,
|
||||
// async resultsA => {
|
||||
// min.conversationalService.sendEvent(dc, "stop", null);
|
||||
|
||||
// if (resultsA && resultsA.answer) {
|
||||
// user.isAsking = false;
|
||||
// service.sendAnswer(min.conversationalService,
|
||||
// dc,
|
||||
// resultsA.answer
|
||||
// );
|
||||
// user.lastQuestionId = resultsA.questionId;
|
||||
|
||||
// dc.replace("/ask", { isReturning: true });
|
||||
// } else {
|
||||
// //if (min.isAsking) {
|
||||
// // Second time with no filter.
|
||||
|
||||
// service.ask(
|
||||
// min.instance,
|
||||
// text,
|
||||
// min.instance.searchScore,
|
||||
// null,
|
||||
// async resultsB => {
|
||||
// if (resultsB && resultsB.answer) {
|
||||
// const user = min.userState.get(dc.context);
|
||||
|
||||
// user.isAsking = false;
|
||||
|
||||
// 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.
|
||||
// }
|
||||
// user.isAsking = false;
|
||||
// service.sendAnswer(min.conversationalService,
|
||||
// dc,
|
||||
// resultsB.answer
|
||||
// );
|
||||
// dc.replace("/ask", { isReturning: true });
|
||||
|
||||
// user.lastQuestionId = resultsB.questionId;
|
||||
// } 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 });
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// async (data, err) => {
|
||||
// var data = res.text;
|
||||
// if (data != text) {
|
||||
// logger.trace("Spelled Text: " + data);
|
||||
// text = data;
|
||||
// }
|
||||
//); }
|
||||
|
||||
user.lastQuestion = text;
|
||||
|
||||
// Searches KB for the first time.
|
||||
|
||||
service.ask(
|
||||
min.instance,
|
||||
text,
|
||||
min.instance.searchScore,
|
||||
user.subjects,
|
||||
async resultsA => {
|
||||
|
||||
// Stops any content on projector.
|
||||
|
||||
min.conversationalService.sendEvent(dc, "stop", null);
|
||||
|
||||
// If there is some result, answer immediately.
|
||||
|
||||
if (resultsA && resultsA.answer) {
|
||||
|
||||
// Saves some context info.
|
||||
|
||||
user.isAsking = false;
|
||||
user.lastQuestionId = resultsA.questionId;
|
||||
|
||||
// Sends the answer to all outputs, including projector.
|
||||
|
||||
service.sendAnswer(min.conversationalService,
|
||||
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", [
|
||||
async (dc, args) => {
|
||||
const user = min.userState.get(dc.context);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
"declaration": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"keyofStringsOnly": true,
|
||||
"skipLibCheck": true,
|
||||
"mapRoot": "./dist/",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
|
|
Loading…
Add table
Reference in a new issue