fix(core.gbapp): /publish command fixed.

This commit is contained in:
Rodrigo Rodriguez 2020-05-23 11:10:06 -03:00
parent b741fb6bb5
commit 7bc83b8b60
3 changed files with 20 additions and 27 deletions

View file

@ -178,10 +178,10 @@ export class AdminDialog extends IGBDialog {
if (AdminDialog.isIntentYes(locale, step.result)) { if (AdminDialog.isIntentYes(locale, step.result)) {
let from = step.context.activity.from.id; let from = step.context.activity.from.id;
let canPublish = process.env.SECURITY_CAN_PUBLISH? let canPublish = process.env.SECURITY_CAN_PUBLISH ?
AdminDialog.canSendBroadcast(from): AdminDialog.canSendBroadcast(from) :
true; // TODO: Disable all can publish from web.
if (canPublish) { if (canPublish) {
@ -193,14 +193,9 @@ export class AdminDialog extends IGBDialog {
let args = step.activeDialog.state.options.args.split(' '); let args = step.activeDialog.state.options.args.split(' ');
let filename = args[0]; let filename = args[0];
const packages = []; const packages = [];
if (filename === null) { if (filename === null || filename === "") {
await min.conversationalService.sendText(min, step, `Starting publishing for all bot packages...`); await min.conversationalService.sendText(min, step, `Starting publishing for ${botId}.gbkb...`);
packages.push(`${botId}.gbkb`); packages.push(`${botId}.gbkb`);
packages.push(`${botId}.gbdialog`);
packages.push(`${botId}.gbot`);
packages.push(`${botId}.gbtheme`);
packages.push(`${botId}.gbapp`);
packages.push(`${botId}.gblib`);
} else { } else {
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`); await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
packages.push(filename); packages.push(filename);
@ -213,15 +208,11 @@ export class AdminDialog extends IGBDialog {
const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`; const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;
if (await (deployer as any).getStoragePackageByName(min.instance.instanceId, if (await (deployer as any).getStoragePackageByName(min.instance.instanceId,
packageName) !== null) { // TODO: Move to interface. packageName) !== null) {
const cmd2 = `undeployPackage ${packageName}`; const cmd2 = `undeployPackage ${packageName}`;
await GBAdminService.undeployPackageCommand(cmd2, min); await GBAdminService.undeployPackageCommand(cmd2, min);
} }
await GBAdminService.deployPackageCommand(min, cmd1, deployer); await GBAdminService.deployPackageCommand(min, cmd1, deployer);
if (packageName.endsWith('.gbkb')) {
await min.conversationalService.sendText(min, step, 'Rebuilding my own index, wait a minute, please...');
await GBAdminService.rebuildIndexPackageCommand(min, deployer);
}
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`); await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
}); });
} catch (error) { } catch (error) {
@ -250,6 +241,7 @@ export class AdminDialog extends IGBDialog {
* @param phone Phone number to check (eg.: +5521900002233) * @param phone Phone number to check (eg.: +5521900002233)
*/ */
public static canSendBroadcast(phone: string): Boolean { public static canSendBroadcast(phone: string): Boolean {
return true; // TODO: REMOVE THIS.
const list = process.env.SECURITY_CAN_PUBLISH.split(';'); const list = process.env.SECURITY_CAN_PUBLISH.split(';');
return list.includes(phone); return list.includes(phone);
} }

View file

@ -396,14 +396,6 @@ export class GBDeployer implements IGBDeployer {
} }
} }
try {
await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString);
} catch (err) {
GBLog.error(err);
throw err;
}
try { try {
await search.deleteIndex(); await search.deleteIndex();
} catch (err) { } catch (err) {
@ -412,6 +404,15 @@ export class GBDeployer implements IGBDeployer {
throw err; throw err;
} }
} }
try {
await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString);
} catch (err) {
GBLog.error(err);
throw err;
}
await search.createIndex(searchSchema, dsName); await search.createIndex(searchSchema, dsName);
} }

View file

@ -144,8 +144,8 @@ export class GBMinService {
} }
let activeMin; let activeMin;
if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") { if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") {
// TODO: Active in two modes.
const toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.activationCode === text)[0]; const toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId === text)[0];
activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
let sec = new SecService(); let sec = new SecService();
@ -168,7 +168,7 @@ export class GBMinService {
res.end(); res.end();
} }
else { else {
activeMin = GBServer.globals.minInstances.filter(p => p.instance.instanceId === user.instanceId)[0];; activeMin = GBServer.globals.minInstances.filter(p => p.instance.instanceId === user.instanceId)[0];
if (activeMin === undefined) { if (activeMin === undefined) {
activeMin = GBServer.globals.minBoot; activeMin = GBServer.globals.minBoot;
await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `O outro Bot que você estava falando(${user.instanceId}), não está mais disponível. Agora você está falando comigo, ${activeMin.instance.title}...`); await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `O outro Bot que você estava falando(${user.instanceId}), não está mais disponível. Agora você está falando comigo, ${activeMin.instance.title}...`);