Skip to content

Commit

Permalink
fix(core.gbapp): GB Apps can now publish bots and replace root web ap…
Browse files Browse the repository at this point in the history
…plication.
  • Loading branch information
rodrigorodriguez committed Feb 25, 2020
1 parent 675c851 commit eed995e
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
27 changes: 25 additions & 2 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { GBAdminService } from '../../../packages/admin.gbapp/services/GBAdminSe
import { GBCorePackage } from '../../../packages/core.gbapp';
import { GBConfigService } from '../../../packages/core.gbapp/services/GBConfigService';
import { GBDeployer } from '../../../packages/core.gbapp/services/GBDeployer';
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");

const Spinner = require('cli-spinner').Spinner;
// tslint:disable-next-line: no-submodule-imports
Expand Down Expand Up @@ -337,7 +338,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
endIpAddress: ip
};
await storageClient.firewallRules.createOrUpdate(groupName, serverName, 'gb', params);

// AllowAllWindowsAzureIps must be created that way, so the Azure Search can
// access SQL Database to index its contents.

Expand Down Expand Up @@ -372,7 +373,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name);
const nlpAppId = await this.createNLPService(name, name, instance.cloudLocation, culture, instance.nlpAuthoringKey);

instance.nlpEndpoint = urlJoin(nlp.endpoint, 'apps');
instance.nlpEndpoint = urlJoin(nlp.endpoint, 'apps');
instance.nlpKey = keys.key1;
instance.nlpAppId = nlpAppId;

Expand Down Expand Up @@ -581,6 +582,28 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.storageClient.servers.createOrUpdate(group, name, params);
}

public async createApplication(token: string, name: string) {
return new Promise<string>((resolve, reject) => {
let client = MicrosoftGraph.Client.init({
authProvider: done => {
done(null, token);
}
});
const app = {
displayName: name
};

client.api(`/applications`).post(app, (err, res) => {
if (err) {
reject(err)
}
else {
resolve(res);
}
});
});
}

private async registerProviders(subscriptionId, baseUrl, accessToken) {
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
const requestUrl = urlJoin(baseUrl, query);
Expand Down
7 changes: 7 additions & 0 deletions packages/core.gbapp/dialogs/WelcomeDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { BotAdapter } from 'botbuilder';
import {WaterfallDialog } from 'botbuilder-dialogs';
import { GBMinInstance, IGBDialog } from 'botlib';
import { Messages } from '../strings';
import { GBServer } from '../../../src/app';

/**
* Dialog for Welcoming people.
Expand All @@ -56,6 +57,12 @@ export class WelcomeDialog extends IGBDialog {
min.dialogs.add(new WaterfallDialog('/', [
async step => {

if (GBServer.globals.entryPointDialog !== undefined)
{

return step.replaceDialog(GBServer.globals.entryPointDialog);
}

const user = await min.userProfile.get(context, {});
const locale = step.context.activity.locale;

Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class GBConversationalService implements IGBConversationalService {
this.coreService = coreService;
}

public static getNewMobileCode() {
public getNewMobileCode() {
const passwordGenerator = new PasswordGenerator();
const options = {
upperCaseAlpha: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ STORAGE_SYNC=true
}
}

public setEntryPointDialog(dialogName: string)
{
GBServer.globals.entryPointDialog = dialogName;
}

public setWWWRoot(localPath: string)
{
GBServer.globals.wwwroot = localPath;
Expand Down
18 changes: 15 additions & 3 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,23 @@ export class GBDeployer {
);
}


public async deployBlankBot(botId: string){
let instance = await this.importer.createBotInstance(botId);
return this.deployBotFull(instance, GBServer.globals.publicAddress);

const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);

const service = new AzureDeployerService(this);
let application = service.createApplication(accessToken, botId);

instance.marketplaceId = (application as any).appId;
instance.marketplacePassword = (application as any).passwordCredentials[0];
instance.adminPass = GBAdminService.getRndPassword();

await this.core.saveInstance(instance);

return this.deployBotFull(instance, GBServer.globals.publicAddress);
}

/**
Expand All @@ -179,9 +191,9 @@ export class GBDeployer {
const service = new AzureDeployerService(this);
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const group = GBConfigService.get('CLOUD_GROUP');
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);

if (await service.botExists(instance.botId, group)) {
await service.updateBot(
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class GBMinService {
min.core = this.core;
min.conversationalService = this.conversationalService;
min.adminService = this.adminService;
min.deployer = this.deployer;
min.deployService = this.deployer;
min.instance = await this.core.loadInstance(min.botId);
min.cbMap = {};
min.scriptMap = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/customer-satisfaction.gbapp/services/CSService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import { GuaribasConversation } from '../../analytics.gblib/models';
import { GuaribasQuestionAlternate } from '../models';
import { GuaribasQuestion } from 'packages/kb.gbapp/models';
import { GuaribasQuestion } from '../../../packages/kb.gbapp/models';

/**
* Customer Satisfaction Service Layer.
Expand All @@ -57,7 +57,7 @@ export class CSService {
question = await GuaribasQuestion.findOne({
where: {
instanceId: instanceId,
questionId: questionAlternate.questionTyped;
questionId: questionAlternate.questionTyped
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RootData {
public minInstances: any[]; //
public minBoot: GBMinInstance;
public wwwroot: string; // .gbui or a static webapp.
public entryPointDialog: string; // To replace default welcome dialog.
}

/**
Expand Down

0 comments on commit eed995e

Please sign in to comment.