fix(core.gbapp): Faster bot creation, fix on WhatsApp switcher.
This commit is contained in:
parent
cca148818e
commit
8c68332802
5 changed files with 65 additions and 70 deletions
|
@ -522,7 +522,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
|||
msaAppId: appId,
|
||||
msaAppPassword: appPassword,
|
||||
enabledChannels: ['webchat', "skype"],//, "facebook"],
|
||||
configuredChannels: ['webchat' , "skype"]//, "facebook"]
|
||||
configuredChannels: ['webchat', "skype"]//, "facebook"]
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -539,23 +539,23 @@ 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=${
|
||||
this.apiVersion
|
||||
}`;
|
||||
url = urlJoin(baseUrl, query);
|
||||
req = AzureDeployerService.createRequestObject(url, accessToken, 'POST', JSON.stringify(parameters));
|
||||
const resChannel = await httpClient.sendRequest(req);
|
||||
const key = JSON.parse(resChannel.bodyAsText).properties.properties.sites[0].key;
|
||||
instance.webchatKey = key;
|
||||
instance.whatsappBotKey = key;
|
||||
resolve(instance);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}, 60000);
|
||||
|
||||
try {
|
||||
//tslint:disable-next-line:max-line-length
|
||||
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${
|
||||
this.apiVersion
|
||||
}`;
|
||||
url = urlJoin(baseUrl, query);
|
||||
req = AzureDeployerService.createRequestObject(url, accessToken, 'POST', JSON.stringify(parameters));
|
||||
const resChannel = await httpClient.sendRequest(req);
|
||||
const key = JSON.parse(resChannel.bodyAsText).properties.properties.sites[0].key;
|
||||
instance.webchatKey = key;
|
||||
instance.whatsappBotKey = key;
|
||||
resolve(instance);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,54 +690,52 @@ export class GBMinService {
|
|||
await step.beginDialog('/menu', JSON.parse(context.activity.text));
|
||||
// Otherwise, continue to the active dialog in the stack.
|
||||
} 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 });
|
||||
}
|
||||
|
||||
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 {
|
||||
let query = context.activity.text;
|
||||
|
||||
let query = context.activity.text;
|
||||
|
||||
const translatorEnabled = () => {
|
||||
if (min.instance.params) {
|
||||
const params = JSON.parse(min.instance.params);
|
||||
return params?params['Enable Worldwide Translator'] === "TRUE": false;
|
||||
}
|
||||
return false;
|
||||
} // TODO: Encapsulate.
|
||||
|
||||
let locale = 'pt';
|
||||
if (process.env.TRANSLATOR_DISABLED !== "true" || translatorEnabled()) {
|
||||
const minBoot = GBServer.globals.minBoot as any; // TODO: Switch keys automatically to master/per bot.
|
||||
locale = await AzureText.getLocale(minBoot.instance.textAnalyticsKey ?
|
||||
minBoot.instance.textAnalyticsKey : minBoot.instance.textAnalyticsKey,
|
||||
minBoot.instance.textAnalyticsEndpoint ?
|
||||
minBoot.instance.textAnalyticsEndpoint : minBoot.instance.textAnalyticsEndpoint, query);
|
||||
const translatorEnabled = () => {
|
||||
if (min.instance.params) {
|
||||
const params = JSON.parse(min.instance.params);
|
||||
return params ? params['Enable Worldwide Translator'] === "TRUE" : false;
|
||||
}
|
||||
return false;
|
||||
} // TODO: Encapsulate.
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
user.locale = locale;
|
||||
await user.save();
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
query = await min.conversationalService.translate(min,
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
query,
|
||||
'pt');
|
||||
GBLog.info(`Translated text: ${query}.`)
|
||||
|
||||
await step.beginDialog('/answer', {
|
||||
query: query
|
||||
});
|
||||
let locale = 'pt';
|
||||
if (process.env.TRANSLATOR_DISABLED !== "true" || translatorEnabled()) {
|
||||
const minBoot = GBServer.globals.minBoot as any; // TODO: Switch keys automatically to master/per bot.
|
||||
locale = await AzureText.getLocale(minBoot.instance.textAnalyticsKey ?
|
||||
minBoot.instance.textAnalyticsKey : minBoot.instance.textAnalyticsKey,
|
||||
minBoot.instance.textAnalyticsEndpoint ?
|
||||
minBoot.instance.textAnalyticsEndpoint : minBoot.instance.textAnalyticsEndpoint, query);
|
||||
}
|
||||
|
||||
let sec = new SecService();
|
||||
const member = step.context.activity.from;
|
||||
|
||||
const user = await sec.ensureUser(min.instance.instanceId, member.id,
|
||||
member.name, "", "web", member.name);
|
||||
user.locale = locale;
|
||||
await user.save();
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
query = await min.conversationalService.translate(min,
|
||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||
query,
|
||||
'pt');
|
||||
GBLog.info(`Translated text: ${query}.`)
|
||||
|
||||
await step.beginDialog('/answer', {
|
||||
query: query
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue