fix(core.gbapp): Faster bot creation, fix on WhatsApp switcher.

This commit is contained in:
Rodrigo Rodriguez 2020-06-15 00:40:25 -03:00
parent cca148818e
commit 8c68332802
5 changed files with 65 additions and 70 deletions

View file

@ -539,7 +539,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return;
}
setTimeout(async () => {
try {
//tslint:disable-next-line:max-line-length
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${
@ -555,7 +555,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
} catch (error) {
reject(error);
}
}, 60000);
});
}

View file

@ -459,7 +459,7 @@ export class GBConversationalService {
public async routeNLP(step: GBDialogStep, min: GBMinInstance, text: string): Promise<boolean> {
if (min.instance.nlpAppId === null) {
if (min.instance.nlpAppId === null || min.instance.nlpAppId === undefined) {
return false;
}

View file

@ -170,7 +170,6 @@ export class GBDeployer implements IGBDeployer {
instance.nlpScore = 0.80; // TODO: Migrate to Excel Config.xlsx.
instance.searchScore = 0.45;
instance.whatsappServiceKey = bootInstance.whatsappServiceKey;
instance.whatsappBotKey = bootInstance.whatsappBotKey;
instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber;
instance.whatsappServiceUrl = bootInstance.whatsappServiceUrl;
@ -215,14 +214,12 @@ export class GBDeployer implements IGBDeployer {
instance.searchIndexer = bootInstance.searchIndexer;
instance.searchKey = bootInstance.searchKey;
instance.whatsappServiceKey = bootInstance.whatsappServiceKey;
instance.whatsappBotKey = bootInstance.whatsappBotKey;
instance.whatsappServiceNumber = bootInstance.whatsappServiceNumber;
instance.whatsappServiceUrl = bootInstance.whatsappServiceUrl;
instance.storageServer = bootInstance.storageServer;
instance.storageName = bootInstance.storageName;
instance.storageUsername = bootInstance.storageUsername;
instance.storagePassword = bootInstance.storagePassword;
instance.webchatKey = bootInstance.webchatKey;
instance.cloudLocation = bootInstance.cloudLocation;
instance.speechEndpoint = bootInstance.speechEndpoint;
instance.speechKey = bootInstance.speechKey;

View file

@ -461,7 +461,7 @@ export class GBMinService {
min.adminService = this.adminService;
min.deployService = this.deployer;
min.kbService = new KBService(this.core.sequelize);
min.instance = await this.core.loadInstanceByBotId(min.botId);
min.instance = instance;
min.cbMap = {};
min.scriptMap = {};
min.sandBoxMap = {};
@ -487,7 +487,7 @@ export class GBMinService {
new WhatsappDirectLine(
min,
min.botId,
min.instance.webchatKey,
min.instance.whatsappBotKey,
minBoot.instance.whatsappServiceKey,
minBoot.instance.whatsappServiceNumber,
minBoot.instance.whatsappServiceUrl
@ -690,15 +690,14 @@ export class GBMinService {
await step.beginDialog('/menu', JSON.parse(context.activity.text));
// Otherwise, continue to the active dialog in the stack.
} else {
if (step.activeDialog !== undefined) {
await step.continueDialog();
} else {
if (!await this.deployer.getStoragePackageByName(min.instance.instanceId, `${min.instance.botId}.gbkb`)) {
await step.context.sendActivity(`Oi, ainda não possuo pacotes de conhecimento publicados. Por favor, aguarde alguns segundos enquanto eu auto-publico alguns pacotes.`);
return await step.beginDialog('/publish', { confirm: true });
}
else {
if (step.activeDialog !== undefined) {
await step.continueDialog();
} else {
let query = context.activity.text;
@ -740,7 +739,6 @@ export class GBMinService {
}
}
}
}
public static async callVM(text: string, min: GBMinInstance, step: GBDialogStep) {
const mainMethod = text.toLowerCase();

View file

@ -58,7 +58,7 @@ export class WhatsappDirectLine extends GBService {
private directLineSecret: string;
private locale: string = 'pt-BR';
public conversationIds = {};
static conversationIds = {};
min: GBMinInstance;
constructor(
@ -130,7 +130,7 @@ export class WhatsappDirectLine extends GBService {
}
public async resetConversationId(number) {
this.conversationIds[number] = undefined;
WhatsappDirectLine.conversationIds[number] = undefined;
}
public async check() {
@ -200,7 +200,7 @@ export class WhatsappDirectLine extends GBService {
}
}
const conversationId = this.conversationIds[from];
const conversationId = WhatsappDirectLine.conversationIds[from];
let client = await this.directLineClient;
if (user.agentMode === "self") {
@ -254,12 +254,12 @@ export class WhatsappDirectLine extends GBService {
}
else if (user.agentMode === "bot" || user.agentMode === null) {
if (this.conversationIds[from] === undefined) {
if (WhatsappDirectLine.conversationIds[from] === undefined) {
GBLog.info(`GBWhatsapp: Starting new conversation on Bot.`);
const response = await client.Conversations.Conversations_StartConversation()
const response = await client.Conversations.Conversations_StartConversation();
const generatedConversationId = response.obj.conversationId;
this.conversationIds[from] = generatedConversationId;
WhatsappDirectLine.conversationIds[from] = generatedConversationId;
this.pollMessages(client, generatedConversationId, from, fromName);
this.inputMessage(client, generatedConversationId, text, from, fromName);