diff --git a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts index 79126196..f51b6485 100644 --- a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts +++ b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts @@ -299,7 +299,7 @@ export class AzureDeployerService implements IGBInstallationDeployer { if (!JSON.parse(res.bodyAsText).id) { throw res.bodyAsText; } - GBLog.info(`Bot proxy updated at: ${endpoint}.`); + GBLog.info(`Bot updated at: ${endpoint}.`); } public async deleteBot(botId: string, group) { diff --git a/packages/core.gbapp/dialogs/SwitchBot.ts b/packages/core.gbapp/dialogs/SwitchBot.ts index 27185ff4..f907658d 100644 --- a/packages/core.gbapp/dialogs/SwitchBot.ts +++ b/packages/core.gbapp/dialogs/SwitchBot.ts @@ -64,7 +64,7 @@ export class SwitchBotDialog extends IGBDialog { let sec = new SecService(); let from = step.context.activity.from.id; const botId = step.result; - const instance = await min.core.loadInstanceByBotId(botId); + const instance = await min.core.loadInstance(botId); await sec.updateUserInstance(from, instance.instanceId); await step.context.sendActivity(`Opa, vamos lá!`); diff --git a/packages/core.gbapp/services/GBCoreService.ts b/packages/core.gbapp/services/GBCoreService.ts index 67fdae47..e6b22cc4 100644 --- a/packages/core.gbapp/services/GBCoreService.ts +++ b/packages/core.gbapp/services/GBCoreService.ts @@ -233,7 +233,7 @@ export class GBCoreService implements IGBCoreService { /** * Loads just one Bot instance. */ - public async loadInstanceByBotId(botId: string): Promise { + public async loadInstance(botId: string): Promise { const options = { where: {} }; options.where = { botId: botId }; diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index d0a1bdfc..7294b3bf 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -213,7 +213,7 @@ export class GBDeployer implements IGBDeployer { } else { let botId = GBConfigService.get('BOT_ID'); - let bootInstance = await this.core.loadInstanceByBotId(botId); + let bootInstance = await this.core.loadInstance(botId); instance.searchHost = bootInstance.searchHost; instance.searchIndex = bootInstance.searchIndex; diff --git a/packages/core.gbapp/services/GBImporterService.ts b/packages/core.gbapp/services/GBImporterService.ts index 9dbcb18e..204db1df 100644 --- a/packages/core.gbapp/services/GBImporterService.ts +++ b/packages/core.gbapp/services/GBImporterService.ts @@ -61,7 +61,7 @@ export class GBImporter { if (botId === undefined) { botId = GBConfigService.get('BOT_ID'); } - const instance = await this.core.loadInstanceByBotId(botId); + const instance = await this.core.loadInstance(botId); if (instance != null && instance.botId === null) { console.log(`Null BotId after load instance with botId: ${botId}.`); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 01a0f43c..e43200c8 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -147,7 +147,7 @@ export class GBMinService { activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; let sec = new SecService(); - const instance = await this.core.loadInstanceByBotId(activeMin.botId); + const instance = await this.core.loadInstance(activeMin.botId); let user = await sec.getUserFromSystemId(id); if (user === null) { @@ -158,7 +158,7 @@ export class GBMinService { // User wants to switch bots. if (toSwitchMin !== undefined) { const botId = text; - const instance = await this.core.loadInstanceByBotId(botId); + const instance = await this.core.loadInstance(botId); await sec.updateUserInstance(id, instance.instanceId); await (activeMin as any).whatsAppDirectLine.resetConversationId(id); @@ -184,13 +184,13 @@ export class GBMinService { }); - await Promise.all( - instances.map(async instance => { - // Gets the authorization key for each instance from Bot Service. - + await CollectionUtil.asyncForEach(instances, async instance => { + try{ await this.mountBot(instance); - }) - ); + } catch (error) { + GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}`); + } + }); } public async unmountBot(botId: string) { @@ -298,7 +298,7 @@ export class GBMinService { if (botId === '[default]' || botId === undefined) { botId = GBConfigService.get('BOT_ID'); } - const instance = await this.core.loadInstanceByBotId(botId); + const instance = await this.core.loadInstance(botId); if (instance !== null) { const webchatTokenContainer = await this.getWebchatToken(instance); const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null; @@ -409,7 +409,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 = await this.core.loadInstance(min.botId); min.cbMap = {}; min.scriptMap = {}; min.sandBoxMap = {}; diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 9751e122..c82df06f 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -560,7 +560,7 @@ export class KBService implements IGBKBService { GBLog.info(`[GBDeployer] Opening package: ${localPath}`); const packageObject = JSON.parse(Fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8')); - const instance = await core.loadInstanceByBotId(packageObject.botId); + const instance = await core.loadInstance(packageObject.botId); GBLog.info(`[GBDeployer] Importing: ${localPath}`); const p = await deployer.deployPackageToStorage(instance.instanceId, packageName); await this.importKbPackage(localPath, p, instance); diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 526cfa8c..d545f748 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -95,6 +95,7 @@ export class WhatsappDirectLine extends GBService { const options = { method: 'POST', url: urlJoin(this.whatsappServiceUrl, 'webhook'), + timeout: 10000, qs: { token: this.whatsappServiceKey, webhookUrl: `${GBServer.globals.publicAddress}/webhooks/whatsapp`,