fix(core.gbapp): Fix in Bot Analytics.
This commit is contained in:
parent
b268882225
commit
ca2de56b06
6 changed files with 36 additions and 43 deletions
|
@ -70,14 +70,14 @@ export class AnalyticsService {
|
||||||
public async createMessage(
|
public async createMessage(
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
conversation: GuaribasConversation,
|
conversation: GuaribasConversation,
|
||||||
user: GuaribasUser,
|
userId: number,
|
||||||
content: string
|
content: string
|
||||||
): Promise<GuaribasConversationMessage> {
|
): Promise<GuaribasConversationMessage> {
|
||||||
|
|
||||||
const message = GuaribasConversationMessage.build();
|
const message = GuaribasConversationMessage.build();
|
||||||
message.content = content;
|
message.content = content;
|
||||||
message.instanceId = instanceId;
|
message.instanceId = instanceId;
|
||||||
message.userId = user.userId;
|
message.userId = userId;
|
||||||
message.conversationId = conversation.conversationId;
|
message.conversationId = conversation.conversationId;
|
||||||
|
|
||||||
return await message.save();
|
return await message.save();
|
||||||
|
|
|
@ -43,6 +43,7 @@ import { GBServer } from '../../../src/app';
|
||||||
import { Readable } from 'stream'
|
import { Readable } from 'stream'
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||||
import { SecService } from '../../security.gblib/services/SecService';
|
import { SecService } from '../../security.gblib/services/SecService';
|
||||||
|
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService';
|
||||||
const urlJoin = require('url-join');
|
const urlJoin = require('url-join');
|
||||||
const PasswordGenerator = require("strict-password-generator").default;
|
const PasswordGenerator = require("strict-password-generator").default;
|
||||||
const Nexmo = require('nexmo');
|
const Nexmo = require('nexmo');
|
||||||
|
@ -593,26 +594,29 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendText(min, step, text) {
|
public async sendText(min, step, text) {
|
||||||
|
|
||||||
let sec = new SecService();
|
|
||||||
const member = step.context.activity.from;
|
const member = step.context.activity.from;
|
||||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
const user = await min.userProfile.get(step.context, {});
|
||||||
member.name, "", "web", member.name);
|
if (user) {
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
text = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
user.locale ? user.locale : 'pt'
|
user.systemUser.locale ? user.systemUser.locale : 'pt'
|
||||||
);
|
);
|
||||||
|
const analytics = new AnalyticsService();
|
||||||
|
|
||||||
if (!isNaN(member.id)) {
|
analytics.createMessage(min.instance.instanceId,
|
||||||
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
user.conversation, null,
|
||||||
}
|
text);
|
||||||
else {
|
|
||||||
await step.context.sendActivity(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!isNaN(member.id)) {
|
||||||
|
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await step.context.sendActivity(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,6 @@ export class GBDeployer implements IGBDeployer {
|
||||||
instance.searchIndexer
|
instance.searchIndexer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const connectionString = GBDeployer.getConnectionStringFromInstance(instance);
|
const connectionString = GBDeployer.getConnectionStringFromInstance(instance);
|
||||||
|
|
||||||
const dsName = 'gb';
|
const dsName = 'gb';
|
||||||
|
@ -468,10 +467,8 @@ export class GBDeployer implements IGBDeployer {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
GBLog.error(err);
|
GBLog.error(err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await search.createIndex(searchSchema, dsName);
|
await search.createIndex(searchSchema, dsName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ export class GBMinService {
|
||||||
let activeMin;
|
let activeMin;
|
||||||
if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") {
|
if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") {
|
||||||
let toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === text.toLowerCase())[0];
|
let toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === text.toLowerCase())[0];
|
||||||
if (!toSwitchMin){
|
if (!toSwitchMin) {
|
||||||
toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.activationCode.toLowerCase() === text.toLowerCase())[0];
|
toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.activationCode.toLowerCase() === text.toLowerCase())[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ export class GBMinService {
|
||||||
} else {
|
} else {
|
||||||
// User wants to switch bots.
|
// User wants to switch bots.
|
||||||
if (toSwitchMin !== undefined) {
|
if (toSwitchMin !== undefined) {
|
||||||
|
|
||||||
const instance = await this.core.loadInstanceByBotId(activeMin.botId);
|
const instance = await this.core.loadInstanceByBotId(activeMin.botId);
|
||||||
await sec.updateUserInstance(id, instance.instanceId);
|
await sec.updateUserInstance(id, instance.instanceId);
|
||||||
|
|
||||||
|
@ -554,10 +554,9 @@ export class GBMinService {
|
||||||
user.subjects = [];
|
user.subjects = [];
|
||||||
user.cb = undefined;
|
user.cb = undefined;
|
||||||
|
|
||||||
|
if (context.activity.from.id !== min.botId) {
|
||||||
if (context.activity.membersAdded !== undefined) {
|
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
const member = context.activity.membersAdded[0];
|
const member = context.activity.from;
|
||||||
|
|
||||||
const persistedUser = await sec.ensureUser(instance.instanceId, member.id,
|
const persistedUser = await sec.ensureUser(instance.instanceId, member.id,
|
||||||
member.name, "", "web", member.name);
|
member.name, "", "web", member.name);
|
||||||
|
@ -566,7 +565,6 @@ export class GBMinService {
|
||||||
|
|
||||||
user.systemUser = persistedUser;
|
user.systemUser = persistedUser;
|
||||||
user.conversation = await analytics.createConversation(persistedUser);
|
user.conversation = await analytics.createConversation(persistedUser);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await min.userProfile.set(step.context, user);
|
await min.userProfile.set(step.context, user);
|
||||||
|
@ -646,9 +644,11 @@ export class GBMinService {
|
||||||
|
|
||||||
const analytics = new AnalyticsService();
|
const analytics = new AnalyticsService();
|
||||||
const user = await min.userProfile.get(context, {});
|
const user = await min.userProfile.get(context, {});
|
||||||
analytics.createMessage(min.instance.instanceId,
|
if (user) {
|
||||||
user.conversation, user.systemUser,
|
analytics.createMessage(min.instance.instanceId,
|
||||||
context.activity.text);
|
user.conversation, user.systemUser.userId,
|
||||||
|
context.activity.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for global exit kewywords cancelling any active dialogs.
|
// Checks for global exit kewywords cancelling any active dialogs.
|
||||||
|
|
|
@ -203,6 +203,7 @@ export class AskDialog extends IGBDialog {
|
||||||
user2.isAsking = false;
|
user2.isAsking = false;
|
||||||
user2.lastQuestionId = resultsB.questionId;
|
user2.lastQuestionId = resultsB.questionId;
|
||||||
await min.userProfile.set(step.context, user2);
|
await min.userProfile.set(step.context, user2);
|
||||||
|
|
||||||
// Informs user that a broader search will be used.
|
// Informs user that a broader search will be used.
|
||||||
if (user2.subjects.length > 0) {
|
if (user2.subjects.length > 0) {
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].wider_answer);
|
await min.conversationalService.sendText(min, step, Messages[locale].wider_answer);
|
||||||
|
|
|
@ -533,15 +533,7 @@ export class KBService implements IGBKBService {
|
||||||
return await this.importKbTabularFile(urlJoin(file.root, file.name), instance.instanceId, packageId);
|
return await this.importKbTabularFile(urlJoin(file.root, file.name), instance.instanceId, packageId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
files = await walkPromise(urlJoin(localPath, 'tabular'));
|
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(files, async file => {
|
|
||||||
|
|
||||||
if (file !== null && file.name.endsWith('.xlsx')) {
|
|
||||||
return await this.importKbTabularFile(urlJoin(file.root, file.name), instance.instanceId, packageId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async importSubjectFile(packageId: number, filename: string, instance: IGBInstance): Promise<any> {
|
public async importSubjectFile(packageId: number, filename: string, instance: IGBInstance): Promise<any> {
|
||||||
|
@ -595,7 +587,6 @@ export class KBService implements IGBKBService {
|
||||||
* @param localPath Path to the .gbkb folder.
|
* @param localPath Path to the .gbkb folder.
|
||||||
*/
|
*/
|
||||||
public async deployKb(core: IGBCoreService, deployer: GBDeployer, localPath: string, min: GBMinInstance) {
|
public async deployKb(core: IGBCoreService, deployer: GBDeployer, localPath: string, min: GBMinInstance) {
|
||||||
const packageType = Path.extname(localPath);
|
|
||||||
const packageName = Path.basename(localPath);
|
const packageName = Path.basename(localPath);
|
||||||
GBLog.info(`[GBDeployer] Opening package: ${localPath}`);
|
GBLog.info(`[GBDeployer] Opening package: ${localPath}`);
|
||||||
|
|
||||||
|
@ -606,7 +597,7 @@ export class KBService implements IGBKBService {
|
||||||
await this.importKbPackage(localPath, p, instance);
|
await this.importKbPackage(localPath, p, instance);
|
||||||
deployer.mountGBKBAssets(packageName, localPath);
|
deployer.mountGBKBAssets(packageName, localPath);
|
||||||
|
|
||||||
deployer.rebuildIndex(instance, new AzureDeployerService(deployer).getKBSearchSchema(instance.searchIndex));
|
await deployer.rebuildIndex(instance, new AzureDeployerService(deployer).getKBSearchSchema(instance.searchIndex));
|
||||||
GBLog.info(`[GBDeployer] Finished import of ${localPath}`);
|
GBLog.info(`[GBDeployer] Finished import of ${localPath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue