Skip to content

Commit

Permalink
new(admin.gbapp): Publish command will publish every package type.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jun 14, 2020
1 parent 557fcb0 commit 5a99ef0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 46 deletions.
28 changes: 18 additions & 10 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,22 @@ export class AdminDialog extends IGBDialog {
step.activeDialog.state.options.args.split(' ')[0] : null;

const packages = [];
let skipError = false;
if (filename === null || filename === "") {
await min.conversationalService.sendText(min, step, `Starting publishing for ${botId}.gbkb...`);
await min.conversationalService.sendText(min, step, `Starting publishing for ${botId} packages...`);
packages.push(`${botId}.gbkb`);
packages.push(`${botId}.gbtheme`);
packages.push(`${botId}.gbdialog`);
packages.push(`${botId}.gbot`);
skipError = true;
} else {
await min.conversationalService.sendText(min, step, `Starting publishing for ${filename}...`);
packages.push(filename);
}

try {

await CollectionUtil.asyncForEach(packages, async packageName => {
await CollectionUtil.asyncForEach(packages, async packageName => {

try {
const cmd1 = `deployPackage ${process.env.STORAGE_SITE} /${process.env.STORAGE_LIBRARY}/${botId}.gbai/${packageName}`;

if (await (deployer as any).getStoragePackageByName(min.instance.instanceId,
Expand All @@ -253,12 +257,16 @@ export class AdminDialog extends IGBDialog {
}
await GBAdminService.deployPackageCommand(min, cmd1, deployer);
await min.conversationalService.sendText(min, step, `Finished publishing ${packageName}.`);
});
} catch (error) {
await min.conversationalService.sendText(min, step, `ERROR: ${error}`);
GBLog.error(error);
return await step.replaceDialog('/ask', { isReturning: true });
}

} catch (error) {
GBLog.error(error);
if (!skipError) {
await min.conversationalService.sendText(min, step, `ERROR: ${error}`);

return await step.replaceDialog('/ask', { isReturning: true });
}
}
});
await min.conversationalService.sendText(min, step, Messages[locale].publish_success);
if (!step.activeDialog.state.options.confirm) {
return await step.replaceDialog('/ask', { isReturning: true });
Expand Down
1 change: 1 addition & 0 deletions packages/core.gbapp/dialogs/WelcomeDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class WelcomeDialog extends IGBDialog {
: Messages[locale].good_night;

await min.conversationalService.sendText(min, step, Messages[locale].hi(msg));

await step.replaceDialog('/ask', { firstTime: true });

if (
Expand Down
76 changes: 42 additions & 34 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export class GBMinService {
const simpleLocale = context.activity.locale.substring(0, 2);
const hasBadWord = wash.check(simpleLocale, context.activity.text);


if (hasBadWord) {
await step.beginDialog('/pleaseNoBadWords');
} else if (isVMCall) {
Expand Down Expand Up @@ -693,43 +694,50 @@ export class GBMinService {
await step.continueDialog();
} else {

let query = context.activity.text;
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 {

const translatorEnabled = () => {
if (min.instance.params) {
const params = JSON.parse(min.instance.params);
return params['Enable Worldwide Translator'] === "TRUE";
let query = context.activity.text;

const translatorEnabled = () => {
if (min.instance.params) {
const params = JSON.parse(min.instance.params);
return params['Enable Worldwide Translator'] === "TRUE";
}
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);
}
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);
}

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 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
});
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ export class WhatsappDirectLine extends GBService {
}

public async received(req, res) {


if (req.body.messages === undefined) {
res.end();
return; // Exit here.
Expand Down

0 comments on commit 5a99ef0

Please sign in to comment.