From a55c677833e8490a234c380c30c4a1034cff4d58 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 13 May 2018 16:35:57 -0300 Subject: [PATCH] Minor fixes in imports and exact match question processing. --- deploy/admin.gbapp/dialogs/AdminDialog.ts | 2 +- deploy/core.gbapp/dialogs/WelcomeDialog.ts | 2 +- deploy/kb.gbapp/services/KBService.ts | 38 +++++++++++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/deploy/admin.gbapp/dialogs/AdminDialog.ts b/deploy/admin.gbapp/dialogs/AdminDialog.ts index 0ba4decf..c6d94414 100644 --- a/deploy/admin.gbapp/dialogs/AdminDialog.ts +++ b/deploy/admin.gbapp/dialogs/AdminDialog.ts @@ -33,7 +33,7 @@ "use strict"; -import { UrlJoin } from "urljoin"; +const UrlJoin = require("url-join"); import { AzureSearch } from "pragmatismo-io-framework"; import { Prompts, Session, UniversalBot } from 'botbuilder'; import { GBMinInstance } from "botlib"; diff --git a/deploy/core.gbapp/dialogs/WelcomeDialog.ts b/deploy/core.gbapp/dialogs/WelcomeDialog.ts index 80e09ed8..61f2486a 100644 --- a/deploy/core.gbapp/dialogs/WelcomeDialog.ts +++ b/deploy/core.gbapp/dialogs/WelcomeDialog.ts @@ -52,7 +52,7 @@ export class WelcomeDialog extends IGBDialog { date < 12 ? "bom dia" : date < 18 ? "boa tarde" : "boa noite"; session.sendTyping(); - let msgs = [`Oi, ${msg}..`, `Oi!`, `Olá, ${msg}`, `Olá!`]; + let msgs = [`Oi, ${msg}.`, `Oi!`, `Olá, ${msg}`, `Olá!`]; session.endDialog(msgs); } diff --git a/deploy/kb.gbapp/services/KBService.ts b/deploy/kb.gbapp/services/KBService.ts index ba3ff9d4..91b78293 100644 --- a/deploy/kb.gbapp/services/KBService.ts +++ b/deploy/kb.gbapp/services/KBService.ts @@ -40,6 +40,12 @@ 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"; @@ -74,17 +80,22 @@ export class KBService { GuaribasQuestion.findOne({ where: { instanceId: instanceId, - content: `${text.trim()}?` + content: { $like: `%${text.trim()}%` } } }).then((question: GuaribasQuestion) => { - GuaribasAnswer.findAll({ - where: { - instanceId: instanceId, - answerId: question.answerId - } - }).then((answer: GuaribasAnswer[]) => { - cb({ question: question, answer: answer[0] }, null); - }); + if (question) { + GuaribasAnswer.findAll({ + where: { + instanceId: instanceId, + answerId: question.answerId + } + }).then((answer: GuaribasAnswer[]) => { + cb({ question: question, answer: answer[0] }, null); + }); + } + else { + cb(null, null); + } }); } @@ -125,7 +136,7 @@ export class KBService { var _this = this; - if (instance.searchKey) { + if (instance.searchKey && GBConfigService.get("DATABASE_DIALECT") == "mssql") { let service = new AzureSearch( instance.searchKey, instance.searchHost, @@ -154,7 +165,12 @@ export class KBService { }); } else { this.getAnswerByText(instance.instanceId, what, (data, err) => { - cb({ answer: data.answer, questionId: data.question.questionId }, null); + if (data) { + cb({ answer: data.answer, questionId: data.question.questionId }, null); + } + else { + cb(null, err); + } }); } }