Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[Botskills] Use botWebAppName and resourceGroupName from the appsetti…
Browse files Browse the repository at this point in the history
…ngs file (#2346)

* Create AppSetting model

* Rename CognitiveModel model

* Separate initializacion, validation, assignment. Use appsettings for botname and rgname

* Remove partial initialization for connect command

* Separate initializacion, validation, assignment for disconnect

* Separate initializacion, validation, assignment for list

* Separate initializacion, validation, assignment for refresh

* Separate initializacion, validation, assignment. Use appsettings for botname and rgname

* Remove unused attribute for models

* Update refresh documentation attributes

* Update whole documentation removing botName parameter

* Update warning removing botName parameter

* Fix tests

* Update comments and fix tslint issues

* Replicate comment of appsettings validation
  • Loading branch information
Batta32 authored and darrenj committed Sep 12, 2019
1 parent 2588dc5 commit 5618317
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 173 deletions.
4 changes: 2 additions & 2 deletions docs/_docs/howto/skills/addingskills.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Run the following command to add each Skill to your Virtual Assistant. This assu
The `--luisFolder` parameter can be used to point the Skill CLI at the source LU files for trigger utterances. For Skills provided within this repo these can be found in the `Deployment/Resources/LU` folder of each Skill. The CLI will automatically traverse locale folder hierarchies. This can be omitted for any of the skills we provide as the LU files are provided locally. Also, you have to specify the `--cs` (for C#) or `--ts` (for TypeScript) argument for determining the coding language of your assistant, since each language takes different folder structures that need to be taken into consideration.

```bash
botskills connect --botName YOUR_BOT_NAME --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder [path] --cs
botskills connect --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder [path] --cs
```

See the [Skill CLI documentation]({{site.baseurl}}/reference/botskills) for detailed CLI documentation.
Expand Down Expand Up @@ -96,7 +96,7 @@ Run the following command to update a Skill to your Virtual Assistant. This assu
The `--luisFolder` parameter can be used to point the Skill CLI at the source LU files for trigger utterances. For Skills provided within this repo these can be found in the `Deployment/Resources/LU` folder of each Skill. The CLI will automatically traverse locale folder hierarchies. This can be omitted for any of the skills we provide as the LU files are provided locally. Also, you have to specify the `--cs` (for C#) or `--ts` (for TypeScript) argument for determining the coding language of your assistant, since each language takes different folder structures that need to be taken into consideration.

```bash
botskills update --botName YOUR_BOT_NAME --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder [path] --cs
botskills update --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder [path] --cs
```

## Refresh Connected Skills
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/reference/knownissues.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ There is a known issue in the `Botskills` CLI tool during the command's executio

Example of the `connect` command with a trailing backslash in the `luisFolder` argument:
``` bash
botskills connect --botName "<YOUR_VA_NAME>" --localManifest "<YOUR_LOCAL_MANIFEST_FILE>" --luisFolder "<YOUR_LUIS_FOLDER_PATH>/" --ts
botskills connect --localManifest "<YOUR_LOCAL_MANIFEST_FILE>" --luisFolder "<YOUR_LUIS_FOLDER_PATH>/" --ts
```

So, to avoid this, it's highly recommended to use `PowerShell 6` to execute the CLI tool commands. Also, you can remove the trailing backslash of the argument.
4 changes: 2 additions & 2 deletions docs/_docs/reference/skills/botskills.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The `connect` command allows you to connect a Skill, be it local or remote, to y
Here is an example:
```bash
botskills connect --botName <YOUR_VA_NAME> --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder <YOUR_LUIS_FOLDER_PATH> --cs
botskills connect --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder <YOUR_LUIS_FOLDER_PATH> --cs
```
*Remember to re-publish your Assistant to Azure after you've added a Skill unless you plan on testing locally only*
Expand All @@ -70,7 +70,7 @@ The `update` command allows you to update a Skill, be it local or remote, to you
Here is an example:
```bash
botskills update --botName <YOUR_BOT_NAME> --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder <YOUR_LUIS_FOLDER_PATH> --cs
botskills update --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder <YOUR_LUIS_FOLDER_PATH> --cs
```
For further information, see the [Update command documentation]({{site.repo}}/tree/master/tools/botskills/docs/update.md).
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/tutorials/add-prebuilt-skill/4_connect_skill.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To add your new Skill to your assistant/Bot we provide a `botskills` command lin
Run the following command from a command prompt **within the directory of your assistant/Bot**.

```bash
botskills connect --botName YOUR_BOT_NAME --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>\Deployment\Resources\LU\en\" --cs
botskills connect --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>\Deployment\Resources\LU\en\" --cs
```
**Remember to re-publish your Assistant to Azure after you've added a Skill unless you plan on testing locally only**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To add your new Skill to your assistant/Bot we provide a `botskills` command lin
Run the following command from a command prompt **within the directory of your assistant/Bot**.

```bash
botskills connect --botName YOUR_BOT_NAME --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>/Deployment/Resources/LU/en/" --cs
botskills connect --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>/Deployment/Resources/LU/en/" --cs
```

See the [Adding Skills]({{site.baseurl}}/howto/skills/addingskills) for more detail on how to add skills.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To add your new Skill to your assistant/Bot we provide a `botskills` command lin
Run the following command from a command prompt **within the directory of your assistant/Bot**.

```bash
botskills connect --botName YOUR_BOT_NAME --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>/Deployment/Resources/LU/en/" --cs
botskills connect --remoteManifest "http://<YOUR_SKILL_MANIFEST>.azurewebsites.net/api/skill/manifest" --luisFolder "<YOUR-SKILL_PATH>/Deployment/Resources/LU/en/" --cs
```

See the [Adding Skills]({{site.baseurl}}/howto/skills/addingskills) for more detail on how to add skills.
1 change: 0 additions & 1 deletion tools/botskills/docs/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ For Skills that require other Authentication connection configuration please fol

| Option | Description |
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -b, --botName \<name> | Name of your Virtual Assistant bot |
| -l, --localManifest \<path> | Path to local Skill Manifest file |
| -r, --remoteManifest \<url> | URL to remote Skill Manifest |
| --cs | Determine your Virtual Assistant project structure to be a csharp-like structure |
Expand Down
1 change: 0 additions & 1 deletion tools/botskills/docs/refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ botskills refresh [options]
| --ts | Determine your Virtual Assistant project structure to be a TypeScript-like structure |
| --dispatchName [name] | (OPTIONAL) Name of your Virtual Assistant's '.dispatch' file (defaults to the name displayed in your Cognitive Models file) |
| --language [language] | (OPTIONAL) Locale used for LUIS culture (defaults to 'en-us') |
| --luisFolder [path] | (OPTIONAL) Path to the folder containing your Skills' '.lu' files (defaults to './deployment/resources/skills/en' inside your Virtual Assistant folder) |
| --dispatchFolder [path] | (OPTIONAL) Path to the folder containing your Virtual Assistant's '.dispatch' file (defaults to './deployment/resources/dispatch/en' inside your Virtual Assistant folder) |
| --outFolder [path] | (OPTIONAL) Path for any output file that may be generated (defaults to your Virtual Assistant's root folder) |
| --lgOutFolder [path] | (OPTIONAL) Path for the LuisGen output (defaults to a 'service' folder inside your Virtual Assistant's folder) |
Expand Down
1 change: 0 additions & 1 deletion tools/botskills/docs/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ botskills update [options]

| Option | Description |
|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -b, --botName \<name> | Name of your Virtual Assistant bot |
| -l, --localManifest \<path> | Path to local Skill Manifest file |
| -r, --remoteManifest \<url> | URL to remote Skill Manifest |
| --cs | Determine your Virtual Assistant project structure to be a csharp-like structure |
Expand Down
106 changes: 66 additions & 40 deletions tools/botskills/src/botskills-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { existsSync, readFileSync } from 'fs';
import { extname, isAbsolute, join, resolve } from 'path';
import { ConnectSkill } from './functionality';
import { ConsoleLogger, ILogger } from './logger';
import { ICognitiveModelFile, IConnectConfiguration } from './models';
import { IAppSetting, ICognitiveModel, IConnectConfiguration } from './models';
import { sanitizePath, validatePairOfArgs } from './utils';

function showErrorHelp(): void {
Expand All @@ -31,7 +31,6 @@ program.Command.prototype.unknownOption = (flag: string): void => {
program
.name('botskills connect')
.description('Connect a skill to your assistant bot. Only one of both path or URL to Skill is needed.')
.option('-b, --botName <name>', 'Name of your assistant bot')
.option('-l, --localManifest <path>', 'Path to local Skill Manifest file')
.option('-r, --remoteManifest <url>', 'URL to remote Skill Manifest')
.option('--cs', 'Determine your assistant project structure to be a CSharp-like structure')
Expand All @@ -57,8 +56,23 @@ if (process.argv.length < 3) {
process.exit(0);
}

logger.isVerbose = args.verbose;
let botName: string = '';
let localManifest: string;
let remoteManifest: string;
let noRefresh: boolean = false;
let dispatchName: string;
let language: string;
let luisFolder: string;
let dispatchFolder: string;
let outFolder: string;
let lgOutFolder: string;
let skillsFile: string = '';
let resourceGroup: string = '';
let appSettingsFile: string;
let cognitiveModelsFile: string;
let lgLanguage: string;

logger.isVerbose = args.verbose;

// Validation of arguments
// cs and ts validation
Expand All @@ -71,19 +85,13 @@ if (csAndTsValidationResult) {
process.exit(1);
}

const projectLanguage: string = args.cs ? 'cs' : 'ts';
lgLanguage = args.cs ? 'cs' : 'ts';

// noRefresh validation
if (args.noRefresh) {
noRefresh = true;
}

// botName validation
if (!args.botName) {
logger.error(`The 'botName' argument should be provided.`);
process.exit(1);
}

// localManifest && remoteManifest validation
const manifestValidationResult: string = validatePairOfArgs(args.localManifest, args.remoteManifest);
if (manifestValidationResult) {
Expand All @@ -98,22 +106,15 @@ if (args.localManifest && extname(args.localManifest) !== '.json') {
process.exit(1);
}

// Initialize an instance of IConnectConfiguration to send the needed arguments to the connectSkill function
const configuration: Partial<IConnectConfiguration> = {
botName: args.botName,
localManifest: args.localManifest,
remoteManifest: args.remoteManifest,
noRefresh: noRefresh,
lgLanguage: projectLanguage
};
localManifest = args.localManifest;
remoteManifest = args.remoteManifest;

// outFolder validation -- the const is needed for reassuring 'configuration.outFolder' is not undefined
const outFolder: string = args.outFolder ? sanitizePath(args.outFolder) : resolve('./');
configuration.outFolder = outFolder;
// outFolder validation -- the var is needed for reassuring 'configuration.outFolder' is not undefined
outFolder = args.outFolder ? sanitizePath(args.outFolder) : resolve('./');

// skillsFile validation
if (!args.skillsFile) {
configuration.skillsFile = join(configuration.outFolder, (args.ts ? join('src', 'skills.json') : 'skills.json'));
skillsFile = join(outFolder, (args.ts ? join('src', 'skills.json') : 'skills.json'));
} else if (extname(args.skillsFile) !== '.json') {
logger.error(`The 'skillsFile' argument should be a JSON file.`);
process.exit(1);
Expand All @@ -124,44 +125,69 @@ if (!args.skillsFile) {
Please make sure to provide a valid path to your Assistant Skills configuration file using the '--skillsFile' argument.`);
process.exit(1);
}
configuration.skillsFile = skillsFilePath;
skillsFile = skillsFilePath;
}

// resourceGroup validation
configuration.resourceGroup = args.resourceGroup || configuration.botName;

// appSettingsFile validation
configuration.appSettingsFile = args.appSettingsFile || join(configuration.outFolder, (args.ts ? join('src', 'appsettings.json') : 'appsettings.json'));
appSettingsFile = args.appSettingsFile || join(outFolder, (args.ts ? join('src', 'appsettings.json') : 'appsettings.json'));

// validate the existence of the appsettings file
if (appSettingsFile !== undefined) {
const appSettings: IAppSetting = JSON.parse(readFileSync(appSettingsFile, 'UTF8'));
// use botWebAppName and resourceGroupName properties from appsettings file
botName = appSettings.botWebAppName;
resourceGroup = appSettings.resourceGroupName;
} else {
logger.error(`The 'appSettings' file doesn't exist`);
process.exit(1);
}

// cognitiveModelsFile validation
const cognitiveModelsFilePath: string = args.cognitiveModelsFile || join(configuration.outFolder, (args.ts ? join('src', 'cognitivemodels.json') : 'cognitivemodels.json'));
configuration.cognitiveModelsFile = cognitiveModelsFilePath;
const cognitiveModelsFilePath: string = args.cognitiveModelsFile || join(outFolder, (args.ts ? join('src', 'cognitivemodels.json') : 'cognitivemodels.json'));
cognitiveModelsFile = cognitiveModelsFilePath;

// language validation
const language: string = args.language || 'en-us';
configuration.language = language;
language = args.language || 'en-us';
const languageCode: string = (language.split('-'))[0];

// luisFolder validation
configuration.luisFolder = args.luisFolder ? sanitizePath(args.luisFolder) : join(configuration.outFolder, 'Deployment', 'Resources', 'Skills', languageCode);
luisFolder = args.luisFolder ? sanitizePath(args.luisFolder) : join(outFolder, 'Deployment', 'Resources', 'Skills', languageCode);

// dispatchFolder validation
configuration.dispatchFolder = args.dispatchFolder ? sanitizePath(args.dispatchFolder) : join(configuration.outFolder, 'Deployment', 'Resources', 'Dispatch', languageCode);
dispatchFolder = args.dispatchFolder ? sanitizePath(args.dispatchFolder) : join(outFolder, 'Deployment', 'Resources', 'Dispatch', languageCode);

// lgOutFolder validation
configuration.lgOutFolder = args.lgOutFolder ? sanitizePath(args.lgOutFolder) : join(configuration.outFolder, (args.ts ? join('src', 'Services') : 'Services'));
lgOutFolder = args.lgOutFolder ? sanitizePath(args.lgOutFolder) : join(outFolder, (args.ts ? join('src', 'Services') : 'Services'));

// dispatchName validation
if (!args.dispatchName) {
// try get the dispatch name from the cognitiveModels file
const cognitiveModelsFile: ICognitiveModelFile = JSON.parse(readFileSync(cognitiveModelsFilePath, 'UTF8'));
configuration.dispatchName = cognitiveModelsFile.cognitiveModels[languageCode].dispatchModel.name;
const cognitiveModels: ICognitiveModel = JSON.parse(readFileSync(cognitiveModelsFilePath, 'UTF8'));
dispatchName = cognitiveModels.cognitiveModels[languageCode].dispatchModel.name;
} else {
configuration.dispatchName = args.dispatchName;
dispatchName = args.dispatchName;
}

configuration.logger = logger;

// End of arguments validation

new ConnectSkill(logger).connectSkill(<IConnectConfiguration> configuration);
// Initialize an instance of IConnectConfiguration to send the needed arguments to the connectSkill function
const configuration: IConnectConfiguration = {
botName: botName,
localManifest: localManifest,
remoteManifest: remoteManifest,
noRefresh: noRefresh,
dispatchName: dispatchName,
language: language,
luisFolder: luisFolder,
dispatchFolder: dispatchFolder,
outFolder: outFolder,
lgOutFolder: lgOutFolder,
skillsFile: skillsFile,
resourceGroup: resourceGroup,
appSettingsFile: appSettingsFile,
cognitiveModelsFile: cognitiveModelsFile,
lgLanguage: lgLanguage,
logger: logger
};

new ConnectSkill(logger).connectSkill(configuration);
Loading

0 comments on commit 5618317

Please sign in to comment.