Merge branch 'master' of https://github.com/GeneralBots/BotServer
This commit is contained in:
commit
0218a0c0f3
8 changed files with 17 additions and 16 deletions
|
@ -299,7 +299,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
if (!JSON.parse(res.bodyAsText).id) {
|
if (!JSON.parse(res.bodyAsText).id) {
|
||||||
throw res.bodyAsText;
|
throw res.bodyAsText;
|
||||||
}
|
}
|
||||||
GBLog.info(`Bot proxy updated at: ${endpoint}.`);
|
GBLog.info(`Bot updated at: ${endpoint}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteBot(botId: string, group) {
|
public async deleteBot(botId: string, group) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ export class SwitchBotDialog extends IGBDialog {
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let from = step.context.activity.from.id;
|
let from = step.context.activity.from.id;
|
||||||
const botId = step.result;
|
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 sec.updateUserInstance(from, instance.instanceId);
|
||||||
await step.context.sendActivity(`Opa, vamos lá!`);
|
await step.context.sendActivity(`Opa, vamos lá!`);
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ export class GBCoreService implements IGBCoreService {
|
||||||
/**
|
/**
|
||||||
* Loads just one Bot instance.
|
* Loads just one Bot instance.
|
||||||
*/
|
*/
|
||||||
public async loadInstanceByBotId(botId: string): Promise<IGBInstance> {
|
public async loadInstance(botId: string): Promise<IGBInstance> {
|
||||||
const options = { where: {} };
|
const options = { where: {} };
|
||||||
options.where = { botId: botId };
|
options.where = { botId: botId };
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let botId = GBConfigService.get('BOT_ID');
|
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.searchHost = bootInstance.searchHost;
|
||||||
instance.searchIndex = bootInstance.searchIndex;
|
instance.searchIndex = bootInstance.searchIndex;
|
||||||
|
|
|
@ -61,7 +61,7 @@ export class GBImporter {
|
||||||
if (botId === undefined) {
|
if (botId === undefined) {
|
||||||
botId = GBConfigService.get('BOT_ID');
|
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) {
|
if (instance != null && instance.botId === null) {
|
||||||
console.log(`Null BotId after load instance with botId: ${botId}.`);
|
console.log(`Null BotId after load instance with botId: ${botId}.`);
|
||||||
|
|
|
@ -147,7 +147,7 @@ export class GBMinService {
|
||||||
activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
|
activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
|
||||||
|
|
||||||
let sec = new SecService();
|
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);
|
let user = await sec.getUserFromSystemId(id);
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
|
@ -158,7 +158,7 @@ export class GBMinService {
|
||||||
// User wants to switch bots.
|
// User wants to switch bots.
|
||||||
if (toSwitchMin !== undefined) {
|
if (toSwitchMin !== undefined) {
|
||||||
const botId = text;
|
const botId = text;
|
||||||
const instance = await this.core.loadInstanceByBotId(botId);
|
const instance = await this.core.loadInstance(botId);
|
||||||
await sec.updateUserInstance(id, instance.instanceId);
|
await sec.updateUserInstance(id, instance.instanceId);
|
||||||
|
|
||||||
await (activeMin as any).whatsAppDirectLine.resetConversationId(id);
|
await (activeMin as any).whatsAppDirectLine.resetConversationId(id);
|
||||||
|
@ -184,13 +184,13 @@ export class GBMinService {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(
|
await CollectionUtil.asyncForEach(instances, async instance => {
|
||||||
instances.map(async instance => {
|
try{
|
||||||
// Gets the authorization key for each instance from Bot Service.
|
|
||||||
|
|
||||||
await this.mountBot(instance);
|
await this.mountBot(instance);
|
||||||
})
|
} catch (error) {
|
||||||
);
|
GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unmountBot(botId: string) {
|
public async unmountBot(botId: string) {
|
||||||
|
@ -300,7 +300,7 @@ export class GBMinService {
|
||||||
if (botId === '[default]' || botId === undefined) {
|
if (botId === '[default]' || botId === undefined) {
|
||||||
botId = GBConfigService.get('BOT_ID');
|
botId = GBConfigService.get('BOT_ID');
|
||||||
}
|
}
|
||||||
const instance = await this.core.loadInstanceByBotId(botId);
|
const instance = await this.core.loadInstance(botId);
|
||||||
if (instance !== null) {
|
if (instance !== null) {
|
||||||
const webchatTokenContainer = await this.getWebchatToken(instance);
|
const webchatTokenContainer = await this.getWebchatToken(instance);
|
||||||
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
|
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
|
||||||
|
@ -411,7 +411,7 @@ export class GBMinService {
|
||||||
min.adminService = this.adminService;
|
min.adminService = this.adminService;
|
||||||
min.deployService = this.deployer;
|
min.deployService = this.deployer;
|
||||||
min.kbService = new KBService(this.core.sequelize);
|
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.cbMap = {};
|
||||||
min.scriptMap = {};
|
min.scriptMap = {};
|
||||||
min.sandBoxMap = {};
|
min.sandBoxMap = {};
|
||||||
|
|
|
@ -560,7 +560,7 @@ export class KBService implements IGBKBService {
|
||||||
GBLog.info(`[GBDeployer] Opening package: ${localPath}`);
|
GBLog.info(`[GBDeployer] Opening package: ${localPath}`);
|
||||||
const packageObject = JSON.parse(Fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
|
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}`);
|
GBLog.info(`[GBDeployer] Importing: ${localPath}`);
|
||||||
const p = await deployer.deployPackageToStorage(instance.instanceId, packageName);
|
const p = await deployer.deployPackageToStorage(instance.instanceId, packageName);
|
||||||
await this.importKbPackage(localPath, p, instance);
|
await this.importKbPackage(localPath, p, instance);
|
||||||
|
|
|
@ -95,6 +95,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: urlJoin(this.whatsappServiceUrl, 'webhook'),
|
url: urlJoin(this.whatsappServiceUrl, 'webhook'),
|
||||||
|
timeout: 10000,
|
||||||
qs: {
|
qs: {
|
||||||
token: this.whatsappServiceKey,
|
token: this.whatsappServiceKey,
|
||||||
webhookUrl: `${GBServer.globals.publicAddress}/webhooks/whatsapp`,
|
webhookUrl: `${GBServer.globals.publicAddress}/webhooks/whatsapp`,
|
||||||
|
|
Loading…
Add table
Reference in a new issue