Skip to content

Commit

Permalink
fix(all): Bot factory creation from command line fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Apr 14, 2021
1 parent 3e13202 commit 8de9777
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 91 deletions.
25 changes: 0 additions & 25 deletions packages/azuredeployer.gbapp/dialogs/StartDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ export class StartDialog {
appPassword = this.retrieveAppPassword();
}

let authoringKey: string;
while (authoringKey === undefined) {
authoringKey = this.retrieveAuthoringKey();
}

// Prepares the first instance on bot farm.
const instance = <IGBInstance>{};

Expand All @@ -109,7 +104,6 @@ export class StartDialog {
instance.cloudPassword = password;
instance.cloudSubscriptionId = subscriptionId;
instance.cloudLocation = location;
instance.nlpAuthoringKey = authoringKey;
instance.marketplaceId = appId;
instance.marketplacePassword = appPassword;
instance.adminPass = GBAdminService.getRndPassword();
Expand Down Expand Up @@ -152,25 +146,6 @@ cannot start or end with or contain consecutive dashes and having 4 to 42 charac
return botId;
}

private static retrieveAuthoringKey() {
let authoringKey = GBConfigService.get('NLP_AUTHORING_KEY');
if (authoringKey === undefined) {
process.stdout.write(
`${
GBAdminService.GB_PROMPT
}Due to this opened issue: https://github.com/Microsoft/botbuilder-tools/issues/550\n`
);
process.stdout.write(
`${
GBAdminService.GB_PROMPT
}Please enter your LUIS Authoring Key, get it here: https://www.luis.ai/user/settings and paste it to me:`
);
authoringKey = scanf('%s').replace(/(\n|\r)+$/, '');
}

return authoringKey;
}

private static retrieveAppId() {
let appId = GBConfigService.get('MARKETPLACE_ID');
if (appId === undefined) {
Expand Down
123 changes: 65 additions & 58 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export class AzureDeployerService implements IGBInstallationDeployer {
public subscriptionId: string;
public farmName: any;
public deployer: IGBDeployer;
private freeTier: boolean;

constructor(deployer: IGBDeployer) {
constructor(deployer: IGBDeployer, freeTier: boolean = true) {
this.deployer = deployer;
this.freeTier = freeTier;
}

public static async createInstance(deployer: GBDeployer): Promise<AzureDeployerService> {
Expand Down Expand Up @@ -239,8 +241,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const httpClient = new ServiceClient();

const query = `providers/${
this.provider
const query = `providers/${this.provider
}/checkNameAvailability/Action?api-version=${this.apiVersion}`;

const url = urlJoin(baseUrl, query);
Expand Down Expand Up @@ -270,8 +271,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}
};

const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters));
Expand Down Expand Up @@ -302,8 +302,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
}
};

const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters));
Expand All @@ -324,8 +323,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const httpClient = new ServiceClient();

const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'DELETE', undefined);
Expand Down Expand Up @@ -378,18 +376,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {
let keys: any;
const name = instance.botId;


GBLog.info(`Deploying Deploy Group (It may take a few minutes)...`);
await this.createDeployGroup(name, instance.cloudLocation);

GBLog.info(`Deploying NLP...`);
const nlp = await this.createNLP(name, `${name}-nlp`, instance.cloudLocation);
keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name);
const nlpAppId = await this.createNLPService(name, name, instance.cloudLocation, culture, instance.nlpAuthoringKey);

instance.nlpEndpoint = nlp.endpoint;
instance.nlpKey = keys.key1;
instance.nlpAppId = nlpAppId;

GBLog.info(`Deploying Bot Server...`);
const serverFarm = await this.createHostingPlan(name, `${name}-server-plan`, instance.cloudLocation);
const serverName = `${name}-server`;
Expand All @@ -398,49 +388,59 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Deploying Bot Storage...`);
const administratorLogin = `sa${GBAdminService.getRndReadableIdentifier()}`;
const administratorPassword = GBAdminService.getRndPassword();
const storageServer = `${name.toLowerCase()}-storage-server.database.windows.net`;
const storageServer = `${name.toLowerCase()}-storage-server`;
const storageName = `${name}-storage`;
await this.createStorageServer(name, storageServer, administratorLogin,
administratorPassword, storageServer, instance.cloudLocation
);
await this.createStorage(name, storageServer, storageName, instance.cloudLocation);
instance.storageUsername = administratorLogin;
instance.storagePassword = administratorPassword;
instance.storageName = storageName;
instance.storageName = storageServer;
instance.storageDialect = 'mssql';
instance.storageServer = storageServer;

GBLog.info(`Deploying Search...`);
const searchName = `${name}-search`.toLowerCase();
await this.createSearch(name, searchName, instance.cloudLocation);
const searchKeys = await this.searchClient.adminKeys.get(name, searchName);
instance.searchHost = `${searchName}.search.windows.net`;
instance.searchIndex = 'azuresql-index';
instance.searchIndexer = 'azuresql-indexer';
instance.searchKey = searchKeys.primaryKey;
this.deployer.rebuildIndex(instance, this.getKBSearchSchema(instance.searchIndex));
instance.storageServer = `${storageServer}.database.windows.net`;

GBLog.info(`Deploying Speech...`);
const speech = await this.createSpeech(name, `${name}-speech`, instance.cloudLocation);
keys = await this.cognitiveClient.accounts.listKeys(name, speech.name);
instance.speechEndpoint = speech.endpoint;
instance.speechKey = keys.key1;

// TODO: https://github.com/Azure/azure-rest-api-specs/issues/11460
// GBLog.info(`Deploying SpellChecker...`);
// const spellChecker = await this.createSpellChecker(name, `${name}-spellchecker`);
// keys = await this.cognitiveClient.accounts.listKeys(name, spellChecker.name);
// instance.spellcheckerKey = keys.key1;
// instance.spellcheckerEndpoint = spellChecker.endpoint;

GBLog.info(`Deploying Text Analytics...`);
const textAnalytics = await this.createTextAnalytics(name, `${name}-textanalytics`, instance.cloudLocation);
keys = await this.cognitiveClient.accounts.listKeys(name, textAnalytics.name);

instance.textAnalyticsEndpoint = textAnalytics.endpoint.replace(`/text/analytics/v2.0`, '');
instance.textAnalyticsKey = keys.key1;

// NLP
GBLog.info(`Deploying SpellChecker...`);
const spellChecker = await this.createSpellChecker(name, `${name}-spellchecker`);
keys = await this.cognitiveClient.accounts.listKeys(name, spellChecker.name);
instance.spellcheckerKey = keys.key1;
instance.spellcheckerEndpoint = spellChecker.endpoint;


GBLog.info(`Deploying Search...`);
const searchName = `${name}-search`.toLowerCase();
await this.createSearch(name, searchName, instance.cloudLocation);
const searchKeys = await this.searchClient.adminKeys.get(name, searchName);
instance.searchHost = `${searchName}.search.windows.net`;
instance.searchIndex = 'azuresql-index';
instance.searchIndexer = 'azuresql-indexer';
instance.searchKey = searchKeys.primaryKey;
await this.deployer.rebuildIndex(instance, this.getKBSearchSchema(instance.searchIndex));

GBLog.info(`Deploying NLP...`);
const nlp = await this.createNLP(name, `${name}-nlp`, instance.cloudLocation);
const nlpa = await this.createNLPAuthoring(name, `${name}-nlpa`, instance.cloudLocation);
keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name);
let authoringKeys = await this.cognitiveClient.accounts.listKeys(name, nlpa.name);
instance.nlpAuthoringKey = authoringKeys.key1;
const nlpAppId = await this.createNLPService(name, name, instance.cloudLocation, culture, instance.nlpAuthoringKey);

instance.nlpEndpoint = nlp.endpoint;
instance.nlpKey = keys.key1;
instance.nlpAppId = nlpAppId;

GBLog.info(`Deploying Bot...`);
instance.botEndpoint = this.defaultEndPoint;
Expand Down Expand Up @@ -521,7 +521,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
const parameters = {
location: location,
sku: {
name: 'F0'
name: this.freeTier ? 'F0' : 'S1'
},
name: botId,
kind: 'bot',
Expand All @@ -540,8 +540,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
};

const httpClient = new ServiceClient();
let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
let url = urlJoin(baseUrl, query);
let req = AzureDeployerService.createRequestObject(url, accessToken, 'PUT', JSON.stringify(parameters));
Expand All @@ -555,8 +554,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {

try {
//tslint:disable-next-line:max-line-length
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${
this.apiVersion
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${this.apiVersion
}`;
url = urlJoin(baseUrl, query);
req = AzureDeployerService.createRequestObject(url, accessToken, 'POST', JSON.stringify(parameters));
Expand Down Expand Up @@ -590,7 +588,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
location: location,
administratorLogin: administratorLogin,
administratorLoginPassword: administratorPassword,
fullyQualifiedDomainName: `${serverName}.database.windows.net`
fullyQualifiedDomainName: serverName
};

return await this.storageClient.servers.createOrUpdate(group, name, params);
Expand Down Expand Up @@ -703,12 +701,12 @@ export class AzureDeployerService implements IGBInstallationDeployer {

public async refreshEntityList(
location: string,
nlpAppId: string,
nlpAppId: string,
clEntityId: string,
nlpKey: string,
data: any,
) {

const req = new WebResource();
req.method = 'PUT';
req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/apps/${nlpAppId}/versions/0.1/closedlists/${clEntityId}`;
Expand All @@ -723,10 +721,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {

public async trainNLP(
location: string,
nlpAppId: string,
nlpAppId: string,
nlpAuthoringKey: string,
) {

const req = new WebResource();
req.method = 'POST';
req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/apps/${nlpAppId}/versions/0.1/train`;
Expand All @@ -740,14 +738,14 @@ export class AzureDeployerService implements IGBInstallationDeployer {

public async publishNLP(
location: string,
nlpAppId: string,
nlpAppId: string,
nlpAuthoringKey: string,
) {
const body = {
versionId: "0.1",
isStaging: false,
directVersionPublish: false
}
}
const req = new WebResource();
req.method = 'POST';
req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/apps/${nlpAppId}/publish`;
Expand All @@ -762,7 +760,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {

private async createSearch(group, name, location) {
const params = {
sku: { name: 'free' },
sku: {
name:
this.freeTier ? 'free' : 'standard'
},
location: location
};

Expand All @@ -771,7 +772,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {

private async createStorage(group, serverName, name, location) {
const params = {
sku: { name: 'Free' },
sku: { name: this.freeTier ? 'Free' : 'Basic' },
createMode: 'Default',
location: location
};
Expand All @@ -781,7 +782,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {

private async createCognitiveServices(group, name, location, kind): Promise<CognitiveServicesAccount> {
const params = {
sku: { name: 'F0' },
sku: {
name: this.freeTier || kind === 'LUIS.Authoring' || kind === 'TextAnalytics' ? 'F0' :
kind === 'Bing.SpellCheck.v7' ? 'S1' : 'S0'
},
createMode: 'Default',
location: location,
kind: kind,
Expand All @@ -799,8 +803,12 @@ export class AzureDeployerService implements IGBInstallationDeployer {
return await this.createCognitiveServices(group, name, location, 'LUIS');
}

private async createNLPAuthoring(group, name, location): Promise<CognitiveServicesAccount> {
return await this.createCognitiveServices(group, name, location, 'LUIS.Authoring');
}

private async createSpellChecker(group, name): Promise<CognitiveServicesAccount> {
return await this.createCognitiveServices(group, name, 'global', 'Bing.SpellCheck.v7');
return await this.createCognitiveServices(group, name, 'westus', 'CognitiveServices');
}

private async createTextAnalytics(group, name, location): Promise<CognitiveServicesAccount> {
Expand All @@ -818,9 +826,9 @@ export class AzureDeployerService implements IGBInstallationDeployer {
serverFarmWithRichSkuName: name,
location: location,
sku: {
name: 'F1',
name: this.freeTier ? 'F1' : 'S1',
capacity: 1,
tier: 'Free'
tier: this.freeTier ? 'Free' : 'Standard'
}
};

Expand Down Expand Up @@ -879,7 +887,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
{ name: 'CLOUD_PASSWORD', value: `${instance.cloudPassword}` },
{ name: 'MARKETPLACE_ID', value: `${instance.marketplaceId}` },
{ name: 'MARKETPLACE_SECRET', value: `${instance.marketplacePassword}` },
{ name: 'NLP_AUTHORING_KEY', value: `${instance.nlpAuthoringKey}` },
{ name: 'STORAGE_DIALECT', value: `${instance.storageDialect}` },
{ name: 'STORAGE_SERVER', value: `${instance.storageServer}.database.windows.net` },
{ name: 'STORAGE_NAME', value: `${instance.storageName}` },
Expand Down
7 changes: 6 additions & 1 deletion packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,13 @@ export class GBVMService extends GBService {
const promise = min.cbMap[id].promise;
delete min.cbMap[id];
try {

// if (step.activeDialog.state.options.previousResolve != undefined) {
// step.activeDialog.state.options.previousResolve();
// }

const opts = await promise(step, result);
return await step.endDialog();
return await step.replaceDialog('/hear', opts);
} catch (error) {
GBLog.error(`Error in BASIC code: ${error}`);
const locale = step.context.activity.locale;
Expand Down
3 changes: 0 additions & 3 deletions packages/core.gbapp/services/GBConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ export class GBConfigService {
case 'MARKETPLACE_SECRET':
value = undefined;
break;
case 'NLP_AUTHORING_KEY':
value = undefined;
break;
case 'STORAGE_DIALECT':
value = undefined;
break;
Expand Down
5 changes: 2 additions & 3 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ CLOUD_USERNAME=${instance.cloudUsername}
CLOUD_PASSWORD=${instance.cloudPassword}
MARKETPLACE_ID=${instance.marketplaceId}
MARKETPLACE_SECRET=${instance.marketplacePassword}
NLP_AUTHORING_KEY=${instance.nlpAuthoringKey}
STORAGE_DIALECT=${instance.storageDialect}
STORAGE_SERVER=${instance.storageServer}.database.windows.net
STORAGE_SERVER=${instance.storageServer}
STORAGE_NAME=${instance.storageName}
STORAGE_USERNAME=${instance.storageUsername}
STORAGE_PASSWORD=${instance.storagePassword}
Expand Down Expand Up @@ -513,7 +512,7 @@ STORAGE_SYNC=true
return changedInstance;
} catch (error) {
GBLog.warn(
`In case of error, please cleanup any infrastructure objects
`There is an error being thrown, so please cleanup any infrastructure objects
created during this procedure and .env before running again.`
);
throw error;
Expand Down
Loading

0 comments on commit 8de9777

Please sign in to comment.