Skip to content

Commit

Permalink
fix(core.gbapp): /publish command fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 23, 2020
1 parent b741fb6 commit 7bc83b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
24 changes: 8 additions & 16 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ export class AdminDialog extends IGBDialog {
if (AdminDialog.isIntentYes(locale, step.result)) {

let from = step.context.activity.from.id;
let canPublish = process.env.SECURITY_CAN_PUBLISH?
AdminDialog.canSendBroadcast(from):
true; // TODO: Disable all can publish from web.

let canPublish = process.env.SECURITY_CAN_PUBLISH ?
AdminDialog.canSendBroadcast(from) :


if (canPublish) {

Expand All @@ -193,14 +193,9 @@ export class AdminDialog extends IGBDialog {
let args = step.activeDialog.state.options.args.split(' ');
let filename = args[0];
const packages = [];
if (filename === null) {
await min.conversationalService.sendText(min, step, `Starting publishing for all bot packages...`);
if (filename === null || filename === "") {
await min.conversationalService.sendText(min, step, `Starting publishing for ${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 {
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
packages.push(filename);
Expand All @@ -213,15 +208,11 @@ export class AdminDialog extends IGBDialog {
const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;

if (await (deployer as any).getStoragePackageByName(min.instance.instanceId,
packageName) !== null) { // TODO: Move to interface.
packageName) !== null) {
const cmd2 = `undeployPackage ${packageName}`;
await GBAdminService.undeployPackageCommand(cmd2, min);
}
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}.`);
});
} catch (error) {
Expand Down Expand Up @@ -250,6 +241,7 @@ export class AdminDialog extends IGBDialog {
* @param phone Phone number to check (eg.: +5521900002233)
*/
public static canSendBroadcast(phone: string): Boolean {
return true; // TODO: REMOVE THIS.
const list = process.env.SECURITY_CAN_PUBLISH.split(';');
return list.includes(phone);
}
Expand Down
17 changes: 9 additions & 8 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
await search.deleteIndex();
} catch (err) {
Expand All @@ -412,6 +404,15 @@ export class GBDeployer implements IGBDeployer {
throw err;
}
}

try {
await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString);
} catch (err) {
GBLog.error(err);
throw err;

}


await search.createIndex(searchSchema, dsName);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export class GBMinService {
}
let activeMin;
if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") {

const toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.activationCode === text)[0];
// TODO: Active in two modes.
const toSwitchMin = GBServer.globals.minInstances.filter(p => p.instance.botId === text)[0];
activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;

let sec = new SecService();
Expand All @@ -168,7 +168,7 @@ export class GBMinService {
res.end();
}
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) {
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}...`);
Expand Down

0 comments on commit 7bc83b8

Please sign in to comment.