restore borked msbot and unit tests from bad merge
This commit is contained in:
Родитель
22d1dde4eb
Коммит
4b11498012
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"path": "packages/MSBot/",
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const pkg = require('../package.json');
|
||||
const semver = require('semver');
|
||||
|
||||
const stdin = require('get-stdin');
|
||||
const msRest = require("ms-rest-js");
|
||||
const { LuisAuthoring } = require('../lib/luisAuthoring');
|
||||
const getOperation = require('./getOperation');
|
||||
|
@ -354,6 +354,13 @@ async function runProgram() {
|
|||
break;
|
||||
|
||||
case "version":
|
||||
if (args.stdin) {
|
||||
let json = JSON.parse(await stdin());
|
||||
args.authoringKey = json.
|
||||
args.region = json.region;
|
||||
args.appId = json.appId;
|
||||
args.version = json.version;
|
||||
}
|
||||
result = await client.versions.importMethod(args.region, args.appId, requestBody, args);
|
||||
break;
|
||||
|
||||
|
|
|
@ -361,6 +361,11 @@
|
|||
"universalify": "0.1.1"
|
||||
}
|
||||
},
|
||||
"get-stdin": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz",
|
||||
"integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g=="
|
||||
},
|
||||
"getpass": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"chalk": "^2.4.1",
|
||||
"cli-table3": "^0.5.0",
|
||||
"fs-extra": "^5.0.0",
|
||||
"get-stdin": "^6.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"ms-rest-js": "^0.17.375",
|
||||
"node-fetch": "^2.0.0",
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Command Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/tests/commandTests.js"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Connection Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/tests/connectTests.js"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Disconnect Tests",
|
||||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||
"args": [
|
||||
"-u",
|
||||
"tdd",
|
||||
"--timeout",
|
||||
"999999",
|
||||
"--colors",
|
||||
"${workspaceFolder}/tests/disconnectTests.js"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}/bin/msbot-get.js",
|
||||
"args": [
|
||||
"9"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "typescript",
|
||||
"tsconfig": "tsconfig.json",
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
"name": "all.bot",
|
||||
"description": null,
|
||||
"version": "2.0",
|
||||
"secretKey": null,
|
||||
"services": [
|
||||
{
|
||||
"type": "appInsights",
|
||||
"id": "47",
|
||||
"name": "testInsights",
|
||||
"tenantId": "microsoft.onmicrosoft.com",
|
||||
"subscriptionId": "2f510b5e-10fe-4f53-9159-b134539ac594",
|
||||
"resourceGroup": "testGroup",
|
||||
"serviceName": "testInsights",
|
||||
"instrumentationKey": "testInstrumentationKey",
|
||||
"applicationId": "2f510b5e-10fe-4f53-9159-b134539ac123",
|
||||
"apiKeys": {
|
||||
"key1": "value1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "blob",
|
||||
"id": "203",
|
||||
"name": "testBlob",
|
||||
"tenantId": "microsoft.onmicrosoft.com",
|
||||
"subscriptionId": "2f510b5e-10fe-4f53-9159-b134539ac594",
|
||||
"resourceGroup": "testGroup",
|
||||
"serviceName": "testBlob",
|
||||
"connectionString": "testConnection",
|
||||
"container": "testContainer"
|
||||
},
|
||||
{
|
||||
"type": "abs",
|
||||
"id": "236",
|
||||
"name": "testBot",
|
||||
"tenantId": "microsoft.onmicrosoft.com",
|
||||
"subscriptionId": "2f510b5e-10fe-4f53-9159-b134539ac594",
|
||||
"resourceGroup": "testGroup",
|
||||
"serviceName": "testBot"
|
||||
},
|
||||
{
|
||||
"type": "cosmosdb",
|
||||
"id": "141",
|
||||
"name": "testCosmosDB",
|
||||
"tenantId": "microsoft.onmicrosoft.com",
|
||||
"subscriptionId": "2f510b5e-10fe-4f53-9159-b134539ac594",
|
||||
"resourceGroup": "testGroup",
|
||||
"serviceName": "testCosmosDB",
|
||||
"connectionString": "testConnectionString",
|
||||
"database": "testDatabase",
|
||||
"collection": "testCollection"
|
||||
},
|
||||
{
|
||||
"type": "luis",
|
||||
"id": "61",
|
||||
"name": "testLuis",
|
||||
"version": "1.0",
|
||||
"appId": "bc2433d4c2564facbe9b1b7a4b6aec5a",
|
||||
"authoringKey": "bca760886b7743eda6385a0e7108c5a5",
|
||||
"subscriptionKey": "1ef3374011f04568bcb274d97bcf3bad",
|
||||
"region": "westus"
|
||||
},
|
||||
{
|
||||
"type": "dispatch",
|
||||
"id": "49",
|
||||
"name": "testDispatch",
|
||||
"appId": "46771c3812f24f45834bbe46fbc771bb",
|
||||
"authoringKey": "c6e9658b1e9b45ada3decda5920a52ab",
|
||||
"serviceIds": [],
|
||||
"subscriptionKey": "d219f80dea564c7a8aba60111308c948",
|
||||
"version": "1.0",
|
||||
"region": "westus"
|
||||
},
|
||||
{
|
||||
"type": "endpoint",
|
||||
"name": "testEndpoint",
|
||||
"id": "66",
|
||||
"appId": "11e830ec-3a22-4c78-84ba-7c065dbf7aa8",
|
||||
"appPassword": "password",
|
||||
"endpoint": "http://foo.com"
|
||||
},
|
||||
{
|
||||
"type": "generic",
|
||||
"id": "204",
|
||||
"name": "testGeneric",
|
||||
"url": "http://foo.com/generic",
|
||||
"configuration": {
|
||||
"key1": "value1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "qna",
|
||||
"id": "125",
|
||||
"name": "testQna",
|
||||
"kbId": "11e830ec-3a22-4c78-84ba-7c065dbf7aa8",
|
||||
"subscriptionKey": "11e830ec-3a22-4c78-84ba-7c065dbf7aa1",
|
||||
"endpointKey": "11e830ec-3a22-4c78-84ba-7c065dbf7a22",
|
||||
"hostname": "https://myqna.azurewebsites.net/qnamaker"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { AppInsightsService, BotConfiguration, IAppInsightsService } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
import * as getStdin from 'get-stdin';
|
||||
import * as txtfile from 'read-text-file';
|
||||
import { uuidValidate } from './utils';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ConnectAppInsightsArgs extends IAppInsightsService {
|
||||
bot: string;
|
||||
secret: string;
|
||||
stdin: boolean;
|
||||
input?: string;
|
||||
keys: string;
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot connect appinsights')
|
||||
.description('Connect the bot file to Azure App Insights')
|
||||
.option('-n, --name <name>', 'friendly name (defaults to serviceName)')
|
||||
.option('-t, --tenantId <tenantId>', 'Azure Tenant id (either GUID or xxx.onmicrosoft.com)')
|
||||
.option('-s, --subscriptionId <subscriptionId>', 'Azure Subscription Id')
|
||||
.option('-r, --resourceGroup <resourceGroup>', 'Azure resource group name')
|
||||
.option('-s, --serviceName <serviceName>', 'Azure service name')
|
||||
.option("-i, --instrumentationKey <instrumentationKey>", "App Insights InstrumentationKey")
|
||||
.option("-a, --applicationId <applicationId>", "(OPTIONAL) App Insights Application Id")
|
||||
.option('--keys <keys>', "Json app keys, example: {'key1':'value1','key2':'value2'} ")
|
||||
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--input <jsonfile>', 'path to arguments in JSON format { id:\'\',name:\'\', ... }')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.option('--stdin', 'arguments are passed in as JSON object via stdin')
|
||||
.action((cmd, actions) => {
|
||||
|
||||
});
|
||||
|
||||
let args = <ConnectAppInsightsArgs><any>program.parse(process.argv);
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
program.help();
|
||||
} else {
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function processConnectAzureArgs(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
if (args.stdin) {
|
||||
Object.assign(args, JSON.parse(await getStdin()));
|
||||
}
|
||||
else if (args.input != null) {
|
||||
Object.assign(args, JSON.parse(await txtfile.read(<string>args.input)));
|
||||
}
|
||||
|
||||
if (!args.serviceName || args.serviceName.length == 0)
|
||||
throw new Error('Bad or missing --serviceName');
|
||||
|
||||
if (!args.tenantId || args.tenantId.length == 0)
|
||||
throw new Error('Bad or missing --tenantId');
|
||||
|
||||
if (!args.subscriptionId || !uuidValidate(args.subscriptionId))
|
||||
throw new Error('Bad or missing --subscriptionId');
|
||||
|
||||
if (!args.resourceGroup || args.resourceGroup.length == 0)
|
||||
throw new Error('Bad or missing --resourceGroup');
|
||||
|
||||
if (!args.instrumentationKey || args.instrumentationKey.length == 0)
|
||||
throw new Error('Bad or missing --instrumentationKey');
|
||||
|
||||
if (!args.apiKeys) {
|
||||
args.apiKeys = {};
|
||||
if (args.keys) {
|
||||
console.log(args.keys);
|
||||
var keys = JSON.parse(args.keys);
|
||||
for (var key in keys) {
|
||||
args.apiKeys[key] = keys[key].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let service = new AppInsightsService({
|
||||
name: args.hasOwnProperty('name') ? args.name : args.serviceName,
|
||||
tenantId: args.tenantId,
|
||||
subscriptionId: args.subscriptionId,
|
||||
resourceGroup: args.resourceGroup,
|
||||
serviceName: args.serviceName,
|
||||
instrumentationKey: args.instrumentationKey,
|
||||
applicationId: args.applicationId,
|
||||
apiKeys: args.apiKeys
|
||||
});
|
||||
var id = config.connectService(service);
|
||||
await config.save(args.secret);
|
||||
process.stdout.write(JSON.stringify(config.findService(id), null, 2));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp() {
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { BlobStorageService, BotConfiguration, IBlobStorageService } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
import * as getStdin from 'get-stdin';
|
||||
import * as txtfile from 'read-text-file';
|
||||
import { uuidValidate } from './utils';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ConnectBlobArgs extends IBlobStorageService {
|
||||
bot: string;
|
||||
secret: string;
|
||||
stdin: boolean;
|
||||
input?: string;
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot connect blob')
|
||||
.description('Connect the bot to Azure Blob Storage Service')
|
||||
.option('-n, --name <name>', 'friendly name (defaults to serviceName)')
|
||||
.option('-t, --tenantId <tenantId>', 'Azure Tenant id (either GUID or xxx.onmicrosoft.com)')
|
||||
.option('-s, --subscriptionId <subscriptionId>', 'Azure Subscription Id')
|
||||
.option('-r, --resourceGroup <resourceGroup>', 'Azure resource group name')
|
||||
.option('--serviceName <serviceName>', 'Azure service name')
|
||||
.option('--connectionString <connectionString>', 'Blob storage connection string')
|
||||
.option('-c, --container <container>', "blob container name")
|
||||
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--input <jsonfile>', 'path to arguments in JSON format { id:\'\',name:\'\', ... }')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.option('--stdin', 'arguments are passed in as JSON object via stdin')
|
||||
.action((cmd, actions) => {
|
||||
|
||||
});
|
||||
|
||||
let args = <ConnectBlobArgs><any>program.parse(process.argv);
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
program.help();
|
||||
} else {
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function processConnectAzureArgs(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
if (args.stdin) {
|
||||
Object.assign(args, JSON.parse(await getStdin()));
|
||||
}
|
||||
else if (args.input != null) {
|
||||
Object.assign(args, JSON.parse(await txtfile.read(<string>args.input)));
|
||||
}
|
||||
|
||||
if (!args.serviceName || args.serviceName.length == 0)
|
||||
throw new Error('Bad or missing --serviceName');
|
||||
|
||||
if (!args.tenantId || args.tenantId.length == 0)
|
||||
throw new Error('Bad or missing --tenantId');
|
||||
|
||||
if (!args.subscriptionId || !uuidValidate(args.subscriptionId))
|
||||
throw new Error('Bad or missing --subscriptionId');
|
||||
|
||||
if (!args.resourceGroup || args.resourceGroup.length == 0)
|
||||
throw new Error('Bad or missing --resourceGroup');
|
||||
|
||||
if (!args.connectionString || args.connectionString.length == 0)
|
||||
throw new Error('Bad or missing --connectionString');
|
||||
|
||||
if (!args.container || args.container.length == 0)
|
||||
throw new Error('Bad or missing --container');
|
||||
|
||||
let services = [];
|
||||
let service = new BlobStorageService({
|
||||
name: args.hasOwnProperty('name') ? args.name : args.serviceName,
|
||||
serviceName: args.serviceName,
|
||||
tenantId: args.tenantId,
|
||||
subscriptionId: args.subscriptionId,
|
||||
resourceGroup: args.resourceGroup,
|
||||
connectionString: args.connectionString,
|
||||
container: args.container
|
||||
});
|
||||
let id = config.connectService(service);
|
||||
await config.save(args.secret);
|
||||
process.stdout.write(JSON.stringify(config.findService(id), null, 2));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp() {
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { BotConfiguration, BotService, EndpointService, IBotService, ServiceTypes } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
import * as getStdin from 'get-stdin';
|
||||
import * as txtfile from 'read-text-file';
|
||||
import * as validurl from 'valid-url';
|
||||
import { uuidValidate } from './utils';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ConnectAzureArgs extends IBotService {
|
||||
bot: string;
|
||||
secret: string;
|
||||
stdin: boolean;
|
||||
input?: string;
|
||||
appId?:string;
|
||||
appPassword?:string;
|
||||
endpoint?:string;
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot connect bot')
|
||||
.description('Connect the bot to Azure Bot Service')
|
||||
.option('--serviceName <serviceName>', 'Azure Bot Service bot id')
|
||||
.option('-n, --name <name>', 'Friendly name for this service (defaults to serviceName)')
|
||||
.option('-t, --tenantId <tenantId>', 'id of the tenant for the Azure service (either GUID or xxx.onmicrosoft.com)')
|
||||
.option('-s, --subscriptionId <subscriptionId>', 'GUID of the subscription for the Azure Service')
|
||||
.option('-r, --resourceGroup <resourceGroup>', 'name of the resourceGroup for the Azure Service')
|
||||
.option('-e, --endpoint <endpoint>', '(OPTIONAL) Registered endpoint url for the Azure Bot Service')
|
||||
.option('-a, --appId <appid>', '(OPTIONAL) Microsoft AppId for the Azure Bot Service\n')
|
||||
.option('-p, --appPassword <appPassword>', '(OPTIONAL) Microsoft AppPassword for the Azure Bot Service\n')
|
||||
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--input <jsonfile>', 'path to arguments in JSON format { id:\'\',name:\'\', ... }')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.option('--stdin', 'arguments are passed in as JSON object via stdin')
|
||||
.action((cmd, actions) => {
|
||||
|
||||
});
|
||||
|
||||
let args = <ConnectAzureArgs><any>program.parse(process.argv);
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
program.help();
|
||||
} else {
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function processConnectAzureArgs(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
if (args.stdin) {
|
||||
Object.assign(args, JSON.parse(await getStdin()));
|
||||
}
|
||||
else if (args.input != null) {
|
||||
Object.assign(args, JSON.parse(await txtfile.read(<string>args.input)));
|
||||
}
|
||||
|
||||
if (!args.serviceName || args.serviceName.length == 0)
|
||||
throw new Error('Bad or missing --serviceName');
|
||||
|
||||
if (!args.tenantId || args.tenantId.length == 0)
|
||||
throw new Error('Bad or missing --tenantId');
|
||||
|
||||
if (!args.subscriptionId || !uuidValidate(args.subscriptionId))
|
||||
throw new Error('Bad or missing --subscriptionId');
|
||||
|
||||
if (!args.resourceGroup || args.resourceGroup.length == 0)
|
||||
throw new Error('Bad or missing --resourceGroup for registered bot');
|
||||
|
||||
let services=[];
|
||||
let service = new BotService({
|
||||
name: args.hasOwnProperty('name') ? args.name : args.serviceName,
|
||||
serviceName: args.serviceName,
|
||||
tenantId: args.tenantId,
|
||||
subscriptionId: args.subscriptionId,
|
||||
resourceGroup: args.resourceGroup
|
||||
});
|
||||
config.connectService(service);
|
||||
services.push(service);
|
||||
if (args.endpoint) {
|
||||
if (!args.endpoint || !(validurl.isHttpUri(args.endpoint) || !validurl.isHttpsUri(args.endpoint)))
|
||||
throw new Error('Bad or missing --endpoint');
|
||||
|
||||
if (!args.appId || !uuidValidate(args.appId))
|
||||
throw new Error('Bad or missing --appId');
|
||||
|
||||
if (!args.appPassword || args.appPassword.length == 0)
|
||||
throw new Error('Bad or missing --appPassword');
|
||||
|
||||
let endpointService = new EndpointService({
|
||||
type: ServiceTypes.Endpoint,
|
||||
name: args.hasOwnProperty('name') ? args.name : args.endpoint,
|
||||
appId: args.appId,
|
||||
appPassword: args.appPassword,
|
||||
endpoint: args.endpoint
|
||||
})
|
||||
config.connectService(endpointService);
|
||||
services.push(endpointService);
|
||||
}
|
||||
await config.save(args.secret);
|
||||
process.stdout.write(JSON.stringify(services, null, 2));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp()
|
||||
{
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { BotConfiguration, CosmosDbService, ICosmosDBService } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
import * as getStdin from 'get-stdin';
|
||||
import * as txtfile from 'read-text-file';
|
||||
import { uuidValidate } from './utils';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ConnectoCosmosDbArgs extends ICosmosDBService {
|
||||
bot: string;
|
||||
secret: string;
|
||||
stdin: boolean;
|
||||
input?: string;
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot connect cosmosdb')
|
||||
.description('Connect the bot to Azure CosmosDb Service')
|
||||
.option('-n, --name <name>', 'friendly name (defaults to serviceName)')
|
||||
.option('-t, --tenantId <tenantId>', 'Azure Tenant id (either GUID or xxx.onmicrosoft.com)')
|
||||
.option('-s, --subscriptionId <subscriptionId>', 'Azure Subscription Id')
|
||||
.option('-r, --resourceGroup <resourceGroup>', 'Azure resource group name')
|
||||
.option('--serviceName <serviceName>', 'Azure service name')
|
||||
.option('--connectionString <connectionString>', 'CosmosDB connection string')
|
||||
.option('-d, --database <database>', "database name")
|
||||
.option('-c, --collection <collection>', "collection name")
|
||||
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--input <jsonfile>', 'path to arguments in JSON format { id:\'\',name:\'\', ... }')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.option('--stdin', 'arguments are passed in as JSON object via stdin')
|
||||
.action((cmd, actions) => {
|
||||
|
||||
});
|
||||
|
||||
let args = <ConnectoCosmosDbArgs><any>program.parse(process.argv);
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
program.help();
|
||||
} else {
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processConnectAzureArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function processConnectAzureArgs(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
if (args.stdin) {
|
||||
Object.assign(args, JSON.parse(await getStdin()));
|
||||
}
|
||||
else if (args.input != null) {
|
||||
Object.assign(args, JSON.parse(await txtfile.read(<string>args.input)));
|
||||
}
|
||||
|
||||
if (!args.serviceName || args.serviceName.length == 0)
|
||||
throw new Error('Bad or missing --serviceName');
|
||||
|
||||
if (!args.tenantId || args.tenantId.length == 0)
|
||||
throw new Error('Bad or missing --tenantId');
|
||||
|
||||
if (!args.subscriptionId || !uuidValidate(args.subscriptionId))
|
||||
throw new Error('Bad or missing --subscriptionId');
|
||||
|
||||
if (!args.resourceGroup || args.resourceGroup.length == 0)
|
||||
throw new Error('Bad or missing --resourceGroup');
|
||||
|
||||
if (!args.connectionString || args.connectionString.length == 0)
|
||||
throw new Error('Bad or missing --connectionString');
|
||||
|
||||
if (!args.database || args.database.length == 0)
|
||||
throw new Error('Bad or missing --database');
|
||||
|
||||
if (!args.collection || args.collection.length == 0)
|
||||
throw new Error('Bad or missing --collection');
|
||||
|
||||
let service = new CosmosDbService({
|
||||
name: args.hasOwnProperty('name') ? args.name : args.serviceName,
|
||||
serviceName : args.serviceName,
|
||||
tenantId: args.tenantId,
|
||||
subscriptionId: args.subscriptionId,
|
||||
resourceGroup: args.resourceGroup,
|
||||
connectionString: args.connectionString,
|
||||
database: args.database,
|
||||
collection: args.collection
|
||||
});
|
||||
let id = config.connectService(service);
|
||||
await config.save(args.secret);
|
||||
process.stdout.write(JSON.stringify(config.findService(id), null, 2));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp() {
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { BotConfiguration, GenericService, IGenericService } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ConnectGenericArgs extends IGenericService {
|
||||
bot: string;
|
||||
secret: string;
|
||||
stdin: boolean;
|
||||
input?: string;
|
||||
keys: string;
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot connect generic')
|
||||
.description('Connect a generic service to the bot')
|
||||
.option('-n, --name <name>', 'name of the service')
|
||||
.option('-u, --url <url>', 'deep link url for the service\n')
|
||||
.option('--keys <keys>', 'serialized json key/value configuration for the service')
|
||||
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--input <jsonfile>', 'path to arguments in JSON format { id:\'\',name:\'\', ... }')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.option('--stdin', 'arguments are passed in as JSON object via stdin')
|
||||
.action((filePath, actions) => {
|
||||
if (filePath)
|
||||
actions.filePath = filePath;
|
||||
});
|
||||
|
||||
let args = <ConnectGenericArgs><any>program.parse(process.argv);
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
program.help();
|
||||
} else {
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processConnectFile)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processConnectFile)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function processConnectFile(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
args.name = args.hasOwnProperty('name') ? args.name : config.name;
|
||||
|
||||
if (!args.url)
|
||||
throw new Error('mising --url');
|
||||
|
||||
if (!args.configuration) {
|
||||
args.configuration = {};
|
||||
if (args.keys) {
|
||||
var keys = JSON.parse(args.keys);
|
||||
for (var key in keys) {
|
||||
args.configuration[key] = keys[key].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add the service
|
||||
let newService = new GenericService({
|
||||
name: args.hasOwnProperty('name') ? args.name : args.url,
|
||||
url: args.url,
|
||||
configuration: args.configuration
|
||||
});
|
||||
let id = config.connectService(newService);
|
||||
await config.save(args.secret);
|
||||
process.stdout.write(JSON.stringify(config.findService(id), null, 2));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp() {
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright(c) Microsoft Corporation.All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import { BotConfiguration } from 'botframework-config';
|
||||
import * as chalk from 'chalk';
|
||||
import * as program from 'commander';
|
||||
import * as process from 'process';
|
||||
|
||||
program.Command.prototype.unknownOption = function (flag: any) {
|
||||
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
|
||||
showErrorHelp();
|
||||
};
|
||||
|
||||
interface ListArgs {
|
||||
bot: string;
|
||||
secret: string;
|
||||
service: string;
|
||||
args: [];
|
||||
}
|
||||
|
||||
program
|
||||
.name('msbot get <serviceNameOrId>')
|
||||
.option('-b, --bot <path>', 'path to bot file. If omitted, local folder will look for a .bot file')
|
||||
.option('--secret <secret>', 'bot file secret password for encrypting service secrets')
|
||||
.action((cmd, actions) => {
|
||||
});
|
||||
|
||||
let args = <ListArgs><any>program.parse(process.argv);
|
||||
|
||||
if (!args.bot) {
|
||||
BotConfiguration.loadBotFromFolder(process.cwd(), args.secret)
|
||||
.then(processListArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
} else {
|
||||
BotConfiguration.load(args.bot, args.secret)
|
||||
.then(processListArgs)
|
||||
.catch((reason) => {
|
||||
console.error(chalk.default.redBright(reason.toString().split('\n')[0]));
|
||||
showErrorHelp();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function processListArgs(config: BotConfiguration): Promise<BotConfiguration> {
|
||||
|
||||
if (args.args.length < 2) {
|
||||
throw new Error('missing the service id or name');
|
||||
}
|
||||
let nameOrId = args.args[0];
|
||||
var service = config.findServiceByNameOrId(nameOrId);
|
||||
if (service == null) {
|
||||
throw new Error(`${nameOrId} was not found in ${config.getPath()}`);
|
||||
}
|
||||
console.log(JSON.stringify(service, null, 4));
|
||||
return config;
|
||||
}
|
||||
|
||||
function showErrorHelp()
|
||||
{
|
||||
program.outputHelp((str) => {
|
||||
console.error(str);
|
||||
return '';
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
let bf = require('botframework-config');
|
||||
let assert = require('assert');
|
||||
let util = require('util');
|
||||
let fs = require('fs');
|
||||
let exec = util.promisify(require('child_process').exec);
|
||||
|
||||
describe("msbot commands", () => {
|
||||
it("msbot init", async () => {
|
||||
let p = await exec(`node bin/msbot-init.js -n save --secret -e http://foo.com/api/messages --appId 2f510b5e-10fe-4f53-9159-b134539ac594 --appPassword appPassword -q`);
|
||||
var result = JSON.parse(p.stdout);
|
||||
|
||||
assert.ok(result.secret, "should have created secret");
|
||||
var config = await bf.BotConfiguration.load("save.bot", result.secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.name, "save", "name is wrong");
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "endpoint", "type is wrong");
|
||||
assert.equal(config.services[0].name, "save", "name is wrong");
|
||||
assert.equal(config.services[0].appId, "2f510b5e-10fe-4f53-9159-b134539ac594", "appId is wrong");
|
||||
assert.equal(config.services[0].appPassword, "appPassword", "password is wrong");
|
||||
});
|
||||
|
||||
it("msbot get", async () => {
|
||||
let p = await exec(`node bin/msbot-get.js -b bot.txt 141`);
|
||||
let result = JSON.parse(p.stdout);
|
||||
|
||||
let bot = await bf.BotConfiguration.load("bot.txt");
|
||||
|
||||
assert.deepEqual(result, bot.findServiceByNameOrId(141), "service by id is wrong");
|
||||
|
||||
p = await exec(`node bin/msbot-get.js -b bot.txt testBlob`);
|
||||
result = JSON.parse(p.stdout);
|
||||
assert.deepEqual(result, bot.findServiceByNameOrId('testBlob'), "service by name is wrong");
|
||||
});
|
||||
|
||||
|
||||
it("msbot list", async () => {
|
||||
let bot = await bf.BotConfiguration.load("bot.txt");
|
||||
let p = await exec(`node bin/msbot-list.js -b bot.txt`);
|
||||
let result = JSON.parse(p.stdout);
|
||||
assert.deepEqual(result.services, bot.toJSON().services, "services are different");
|
||||
|
||||
// list with secret
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
await bot.saveAs("save.bot", secret);
|
||||
p = await exec(`node bin/msbot-list.js -b save.bot --secret ${secret}`);
|
||||
result = JSON.parse(p.stdout);
|
||||
let saveBot = await bf.BotConfiguration.load("save.bot", secret);
|
||||
saveBot.clearSecret();
|
||||
assert.deepEqual(result.services, bot.toJSON().services, "encrypted services are different");
|
||||
});
|
||||
|
||||
|
||||
it("msbot secret --new add", async () => {
|
||||
var config = await bf.BotConfiguration.load("bot.txt");
|
||||
config.saveAs('save.bot');
|
||||
|
||||
// test add secret
|
||||
let p = await exec(`node bin/msbot-secret.js -b save.bot --new`);
|
||||
var secret = p.stdout.split('\n')[1];
|
||||
var buf = new Buffer(secret, "base64");
|
||||
assert.equal(buf.length, 32, "secret should be 32 bytes");
|
||||
config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
assert.ok(config.secretKey.length > 0, "secretKey should be set");
|
||||
});
|
||||
|
||||
it("msbot secret --new replace", async () => {
|
||||
var config = await bf.BotConfiguration.load("bot.txt");
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
config.saveAs('save.bot', secret);
|
||||
|
||||
// test new secret
|
||||
p = await exec(`node bin/msbot-secret.js -b save.bot --secret ${secret} --new`);
|
||||
fs.unlinkSync("save.bot");
|
||||
var secret2 = p.stdout.split('\n')[1];
|
||||
assert.notEqual(secret2, secret, "secret should change");
|
||||
});
|
||||
|
||||
it("msbot secret --clear", async () => {
|
||||
var config = await bf.BotConfiguration.load("bot.txt");
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
config.saveAs('save.bot', secret);
|
||||
|
||||
// test clear secret
|
||||
p = await exec(`node bin/msbot-secret.js -b save.bot --secret ${secret} --clear`);
|
||||
|
||||
// verify we can load without a password
|
||||
config = await bf.BotConfiguration.load("save.bot");
|
||||
fs.unlinkSync("save.bot");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,235 @@
|
|||
let bf = require('botframework-config');
|
||||
let assert = require('assert');
|
||||
let util = require('util');
|
||||
let fs = require('fs');
|
||||
let exec = util.promisify(require('child_process').exec);
|
||||
|
||||
describe("msbot connection tests", () => {
|
||||
|
||||
it("msbot connect appinsights", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let command = `node bin/msbot-connect-appinsights.js `;
|
||||
command += `-b save.bot `;
|
||||
command += `-n TestInsights `;
|
||||
command += `--serviceName testInsights `;
|
||||
command += `--instrumentationKey testInstrumentationKey `;
|
||||
command += `--applicationId 2f510b5e-10fe-4f53-9159-b134539ac123 `;
|
||||
command += `--keys "{\\"key1\\":\\"value1\\"}" `;
|
||||
command += `--secret ${secret} `;
|
||||
command += `-s 2f510b5e-10fe-4f53-9159-b134539ac594 `;
|
||||
command += `--tenantId microsoft.onmicrosoft.com `
|
||||
command += `--resourceGroup testGroup`;
|
||||
let p = await exec(command);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "appInsights", "type is wrong");
|
||||
assert.equal(config.services[0].name, "TestInsights", "name is wrong");
|
||||
assert.equal(config.services[0].serviceName, "testInsights", "servicename is wrong");
|
||||
assert.ok(config.services[0].id.length > 0, "id is wrong");
|
||||
assert.equal(config.services[0].subscriptionId, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionId is wrong")
|
||||
assert.equal(config.services[0].tenantId, "microsoft.onmicrosoft.com", " tenantid is wrong")
|
||||
assert.equal(config.services[0].resourceGroup, "testGroup", "resourceGroup is wrong")
|
||||
assert.equal(config.services[0].instrumentationKey, "testInstrumentationKey", "instrumentationKey missing");
|
||||
assert.equal(config.services[0].applicationId, "2f510b5e-10fe-4f53-9159-b134539ac123", "applicationId missing");
|
||||
assert.equal(config.services[0].apiKeys.key1, 'value1', "key not set");
|
||||
});
|
||||
|
||||
it("msbot connect blob", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-blob.js -b save.bot -n TestBlob --serviceName testBlob --connectionString testConnection --container testContainer --secret ${secret} -s 2f510b5e-10fe-4f53-9159-b134539ac594 --tenantId microsoft.onmicrosoft.com --resourceGroup testGroup `);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "blob", "type is wrong");
|
||||
assert.equal(config.services[0].name, "TestBlob", "name is wrong");
|
||||
assert.equal(config.services[0].serviceName, "testBlob", "servicename is wrong");
|
||||
assert.ok(config.services[0].id.length > 0, "id is wrong");
|
||||
assert.equal(config.services[0].subscriptionId, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionId is wrong")
|
||||
assert.equal(config.services[0].tenantId, "microsoft.onmicrosoft.com", " tenantid is wrong")
|
||||
assert.equal(config.services[0].resourceGroup, "testGroup", "resourceGroup is wrong")
|
||||
assert.equal(config.services[0].connectionString, "testConnection", "connection missing");
|
||||
assert.equal(config.services[0].container, "testContainer", "container missing");
|
||||
});
|
||||
|
||||
it("msbot connect bot", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
bot.description = "testd";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-bot.js -b save.bot -n TestBot --serviceName TestBot --secret ${secret} --endpoint http://foo.com/api/messages -s 2f510b5e-10fe-4f53-9159-b134539ac594 --appId 2f510b5e-10fe-4f53-9159-b134539ac594 --appPassword appPassword --tenantId microsoft.onmicrosoft.com --resourceGroup test `);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 2, "service is not saved");
|
||||
assert.equal(config.services[0].type, "abs", "abs type is wrong");
|
||||
assert.equal(config.services[0].name, "TestBot", "abs name is wrong");
|
||||
assert.equal(config.services[0].serviceName, "TestBot", "abs name is wrong");
|
||||
assert.ok(config.services[0].id.length > 0, "abs id is wrong");
|
||||
assert.equal(config.services[0].subscriptionId, "2f510b5e-10fe-4f53-9159-b134539ac594", "abs subscriptionId is wrong")
|
||||
assert.equal(config.services[0].tenantId, "microsoft.onmicrosoft.com", "abs tenantid is wrong")
|
||||
assert.equal(config.services[1].type, "endpoint", "endpoint type is wrong");
|
||||
assert.equal(config.services[1].appId, "2f510b5e-10fe-4f53-9159-b134539ac594", "endpoint appId is wrong");
|
||||
assert.equal(config.services[1].appPassword, "appPassword", "endpoint password is wrong");
|
||||
});
|
||||
|
||||
it("msbot connect cosmosdb", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-cosmosdb.js -b save.bot -n TestCosmos --serviceName testCosmos --connectionString testConnection --database testDatabase --collection testCollection --secret ${secret} -s 2f510b5e-10fe-4f53-9159-b134539ac594 --tenantId microsoft.onmicrosoft.com --resourceGroup testGroup `);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "cosmosdb", "type is wrong");
|
||||
assert.equal(config.services[0].name, "TestCosmos", "name is wrong");
|
||||
assert.equal(config.services[0].serviceName, "testCosmos", "servicename is wrong");
|
||||
assert.ok(config.services[0].id.length > 0, "id is wrong");
|
||||
assert.equal(config.services[0].subscriptionId, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionId is wrong")
|
||||
assert.equal(config.services[0].tenantId, "microsoft.onmicrosoft.com", " tenantid is wrong")
|
||||
assert.equal(config.services[0].resourceGroup, "testGroup", "resourceGroup is wrong")
|
||||
assert.equal(config.services[0].connectionString, "testConnection", "connection missing");
|
||||
assert.equal(config.services[0].database, "testDatabase", "database missing");
|
||||
assert.equal(config.services[0].collection, "testCollection", "collection missing");
|
||||
});
|
||||
|
||||
|
||||
it("msbot connect dispatch", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
bot.description = "testd";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-luis.js -b save.bot --secret ${secret} -n LUIS -a 2f510b5e-10fe-4f53-9159-b134539ac594 --authoringKey 2f510b5e-10fe-4f53-9159-b134539ac594 --subscriptionKey 2f510b5e-10fe-4f53-9159-b134539ac594 --version 1.0`);
|
||||
let result = JSON.parse(p.stdout);
|
||||
p = await exec(`node bin/msbot-connect-dispatch.js -b save.bot --secret ${secret} -n Dispatch -a e06e3198-45fd-494a-8086-028d260a484b --authoringKey e06e3198-45fd-494a-8086-028d260a484b --subscriptionKey e06e3198-45fd-494a-8086-028d260a484b --version 1.0 --serviceIds ${result.id}`);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
// fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 2, "service is not saved");
|
||||
assert.equal(config.services[0].type, "luis", "type is wrong");
|
||||
assert.equal(config.services[0].name, "LUIS", "name is wrong");
|
||||
assert.equal(config.services[0].region, "westus", "region is wrong");
|
||||
assert.equal(config.services[0].appId, "2f510b5e-10fe-4f53-9159-b134539ac594", "appId is wrong")
|
||||
assert.equal(config.services[0].subscriptionKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionKey is wrong")
|
||||
assert.equal(config.services[0].authoringKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "authoringKey is wrong")
|
||||
assert.equal(config.services[0].version, 1.0, "version is wrong")
|
||||
assert.equal(config.services[1].type, "dispatch", "dispatch type is wrong");
|
||||
assert.equal(config.services[1].name, "Dispatch", "dispatch name is wrong");
|
||||
assert.equal(config.services[1].appId, "e06e3198-45fd-494a-8086-028d260a484b", "dispatch appId is wrong");
|
||||
assert.equal(config.services[1].subscriptionKey, "e06e3198-45fd-494a-8086-028d260a484b", "dispatch subscriptionKey is wrong");
|
||||
assert.equal(config.services[1].authoringKey, "e06e3198-45fd-494a-8086-028d260a484b", "dispatch authoringKey is wrong");
|
||||
assert.equal(config.services[1].version, 1.0, "dispatch version is wrong");
|
||||
assert.equal(config.services[1].serviceIds.length, 1, "dispatch serviceIds is wrong");
|
||||
assert.equal(config.services[1].serviceIds[0], result.id, "dispatch serviceIds[0] is wrong");
|
||||
});
|
||||
|
||||
it("msbot connect luis", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
bot.description = "testd";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-luis.js -b save.bot --secret ${secret} -n LUIS -a 2f510b5e-10fe-4f53-9159-b134539ac594 --authoringKey 2f510b5e-10fe-4f53-9159-b134539ac594 --subscriptionKey 2f510b5e-10fe-4f53-9159-b134539ac594 --region eastus --version 1.0`);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "luis", "type is wrong");
|
||||
assert.equal(config.services[0].name, "LUIS", "name is wrong");
|
||||
assert.equal(config.services[0].region, "eastus", "region is wrong");
|
||||
assert.equal(config.services[0].appId, "2f510b5e-10fe-4f53-9159-b134539ac594", "appId is wrong")
|
||||
assert.equal(config.services[0].subscriptionKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionKey is wrong")
|
||||
assert.equal(config.services[0].authoringKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "authoringKey is wrong")
|
||||
assert.equal(config.services[0].version, 1.0, "version is wrong")
|
||||
});
|
||||
|
||||
it("msbot connect endpoint", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
bot.description = "testd";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-endpoint.js -b save.bot --secret ${secret} -n Endpoint2 --endpoint https://foo.com/api/messages --appId 2f510b5e-10fe-4f53-9159-b134539ac594 --appPassword appPassword`);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "endpoint", "type is wrong");
|
||||
assert.equal(config.services[0].name, "Endpoint2", "name is wrong");
|
||||
assert.equal(config.services[0].appId, "2f510b5e-10fe-4f53-9159-b134539ac594", "appId is wrong")
|
||||
assert.equal(config.services[0].appPassword, "appPassword", "appPassword is wrong")
|
||||
assert.equal(config.services[0].endpoint, "https://foo.com/api/messages", "endpoint is wrong")
|
||||
});
|
||||
|
||||
it("msbot connect generic", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let command = `node bin/msbot-connect-generic.js `;
|
||||
command += `-b save.bot `;
|
||||
command += `-n TestGeneric `;
|
||||
command += `--url https://bing.com `;
|
||||
command += `--keys "{\\"key1\\":\\"value1\\"}" `;
|
||||
command += `--secret ${secret}`;
|
||||
let p = await exec(command);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "generic", "type is wrong");
|
||||
assert.equal(config.services[0].name, "TestGeneric", "name is wrong");
|
||||
assert.ok(config.services[0].id.length > 0, "id is wrong");
|
||||
assert.equal(config.services[0].url, "https://bing.com", "url missing");
|
||||
assert.equal(config.services[0].configuration.key1, "value1", "missing configuration");
|
||||
});
|
||||
|
||||
it("msbot connect qna", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
let bot = new bf.BotConfiguration();
|
||||
bot.name = "test";
|
||||
bot.description = "testd";
|
||||
await bot.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-connect-qna.js -b save.bot --secret ${secret} -n QnA --hostname https://foo.com/qnamaker -k 2f510b5e-10fe-4f53-9159-b134539ac594 --subscriptionKey 2f510b5e-10fe-4f53-9159-b134539ac594 --endpointKey 2f510b5e-10fe-4f53-9159-b134539ac594 `);
|
||||
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
fs.unlinkSync("save.bot");
|
||||
|
||||
assert.equal(config.services.length, 1, "service is not saved");
|
||||
assert.equal(config.services[0].type, "qna", "type is wrong");
|
||||
assert.equal(config.services[0].name, "QnA", "name is wrong");
|
||||
assert.equal(config.services[0].subscriptionKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "subscriptionKey is wrong")
|
||||
assert.equal(config.services[0].endpointKey, "2f510b5e-10fe-4f53-9159-b134539ac594", "endpointKey is wrong")
|
||||
assert.equal(config.services[0].hostname, "https://foo.com/qnamaker", "hostname is wrong")
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
let bf = require('botframework-config');
|
||||
let assert = require('assert');
|
||||
let util = require('util');
|
||||
let fs = require('fs');
|
||||
let exec = util.promisify(require('child_process').exec);
|
||||
|
||||
describe("msbot disconnect tests", () => {
|
||||
|
||||
it("msbot disconnect name", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
var config = await bf.BotConfiguration.load("bot.txt");
|
||||
assert.equal(config.services.length, 9, "service is missing");
|
||||
// save as save.bot
|
||||
await config.saveAs("save.bot", secret);
|
||||
|
||||
let p = await exec(`node bin/msbot-disconnect.js -b save.bot --secret ${secret} testLuis`);
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
assert.equal(config.services.length, 8, "service wasn't removed");
|
||||
|
||||
fs.unlinkSync("save.bot");
|
||||
});
|
||||
|
||||
it("msbot disconnect id", async () => {
|
||||
let secret = bf.BotConfiguration.generateKey();
|
||||
var config = await bf.BotConfiguration.load("bot.txt");
|
||||
assert.equal(config.services.length, 9, "service is missing");
|
||||
// save as save.bot
|
||||
await config.saveAs("save.bot", secret);
|
||||
|
||||
let service = config.services[3];
|
||||
let p = await exec(`node bin/msbot-disconnect.js -b save.bot --secret ${secret} ${service.id}`);
|
||||
var config = await bf.BotConfiguration.load("save.bot", secret);
|
||||
assert.equal(config.services.length, 8, "service wasn't removed");
|
||||
assert.equal(null, config.findService(service.id), "service should have been removed");
|
||||
|
||||
fs.unlinkSync("save.bot");
|
||||
});
|
||||
|
||||
});
|
Загрузка…
Ссылка в новой задаче