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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,27 +34,25 @@
 | 
				
			||||||
<html lang="pt-br" style="width:100%;height:100%">
 | 
					<html lang="pt-br" style="width:100%;height:100%">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<head>
 | 
					<head>
 | 
				
			||||||
    <meta charset="utf-8">
 | 
					  <meta charset="utf-8">
 | 
				
			||||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
					  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
				
			||||||
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 | 
					  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 | 
				
			||||||
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
 | 
					  <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/botchat.css" />
 | 
				
			||||||
    <link rel="stylesheet" type="text/css" href="./css/pragmatismo.css" />
 | 
					  <link rel="stylesheet" type="text/css" href="./css/pragmatismo.css" />
 | 
				
			||||||
    <script src="./js/botchat.js"></script>
 | 
					  <script src="./js/botchat.js"></script>
 | 
				
			||||||
    <title>General Bots Community Edition | pragmatismo.io</title>
 | 
					  <title>General Bots Community Edition | pragmatismo.io</title>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <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>
 | 
				
			||||||
| 
						 | 
					@ -145,7 +145,7 @@ class GBUIApp extends React.Component {
 | 
				
			||||||
      .subscribe(activity => {
 | 
					      .subscribe(activity => {
 | 
				
			||||||
        _this_.setState({ instance: activity.value });
 | 
					        _this_.setState({ instance: activity.value });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
    botConnection.activity$
 | 
					    botConnection.activity$
 | 
				
			||||||
      .filter(activity => activity.type === "event" && activity.name === "stop")
 | 
					      .filter(activity => activity.type === "event" && activity.name === "stop")
 | 
				
			||||||
      .subscribe(activity => {
 | 
					      .subscribe(activity => {
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ class GBUIApp extends React.Component {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    let chat = <div />;
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let playerComponent = "";
 | 
					    let playerComponent = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,16 +234,19 @@ 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">
 | 
				
			||||||
        <SidebarMenu chat={this.chat} instance={this.state.instance} />
 | 
					        <SidebarMenu chat={this.chat} instance={this.state.instance} />
 | 
				
			||||||
      </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}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,15 +50,19 @@ export class AskDialog extends IGBDialog {
 | 
				
			||||||
      appId: min.instance.nlpAppId,
 | 
					      appId: min.instance.nlpAppId,
 | 
				
			||||||
      subscriptionKey: min.instance.nlpSubscriptionKey,
 | 
					      subscriptionKey: min.instance.nlpSubscriptionKey,
 | 
				
			||||||
      serviceEndpoint: min.instance.nlpServerUrl
 | 
					      serviceEndpoint: min.instance.nlpServerUrl
 | 
				
			||||||
  });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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) {
 | 
					        // if (data != text) {
 | 
				
			||||||
        //       let messages = [
 | 
					        //   logger.trace("Spelled Text: " + data);
 | 
				
			||||||
        //         "Desculpe-me, não encontrei nada a respeito.",
 | 
					        //   text = data;
 | 
				
			||||||
        //         "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 });
 | 
					 | 
				
			||||||
        //                   }
 | 
					 | 
				
			||||||
        //                 }
 | 
					 | 
				
			||||||
        //               );
 | 
					 | 
				
			||||||
        //             }
 | 
					 | 
				
			||||||
        //           }
 | 
					 | 
				
			||||||
        //         );
 | 
					 | 
				
			||||||
        //       }
 | 
					 | 
				
			||||||
        //     }
 | 
					 | 
				
			||||||
        //   );
 | 
					 | 
				
			||||||
        // }
 | 
					        // }
 | 
				
			||||||
        //);        }
 | 
					
 | 
				
			||||||
 | 
					        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", [
 | 
					    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