UNPKG

msbot

Version:

MSBot command line tool for manipulating Microsoft Bot Framework .bot files

104 lines 4.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Copyright(c) Microsoft Corporation.All rights reserved. * Licensed under the MIT License. */ // tslint:disable:no-console // tslint:disable:no-object-literal-type-assertion const botframework_config_1 = require("botframework-config"); const chalk = require("chalk"); const program = require("commander"); const txtfile = require("read-text-file"); const stdioAsync_1 = require("./stdioAsync"); const utils_1 = require("./utils"); program.Command.prototype.unknownOption = (flag) => { console.error(chalk.default.redBright(`Unknown arguments: ${flag}`)); showErrorHelp(); }; program .name('msbot update luis') .description('update the bot to a LUIS application (--id or --appId is required)') .option('--id <id>', 'service id') .option('-n, --name <name>', 'name for the LUIS app') .option('-a, --appId <appid>', 'AppId for the LUIS App') .option('--version <version>', 'version for the LUIS App, (example: v0.1)') .option('-r, --region <region>', 'region for the LUIS App, (default:westus)') .option('--authoringKey <authoringkey>', 'authoring key for using manipulating LUIS apps via the authoring API (See http://aka.ms/luiskeys for help)') .option('--subscriptionKey <subscriptionKey>', '(OPTIONAL) subscription key used for querying a LUIS model\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') .option('--prefix', 'Append [msbot] prefix to all messages') .action((cmd, actions) => undefined); const command = program.parse(process.argv); const args = {}; Object.assign(args, command); if (args.stdin) { //force verbosity output if args are passed via stdin process.env.PREFIX = 'prefix'; } if (process.argv.length < 3) { program.help(); } else { if (!args.bot) { botframework_config_1.BotConfiguration.loadBotFromFolder(process.cwd(), args.secret) .then(processArgs) .catch((reason) => { console.error(chalk.default.redBright(reason.toString().split('\n')[0])); showErrorHelp(); }); } else { botframework_config_1.BotConfiguration.load(args.bot, args.secret) .then(processArgs) .catch((reason) => { console.error(chalk.default.redBright(reason.toString().split('\n')[0])); showErrorHelp(); }); } } async function processArgs(config) { if (args.stdin) { Object.assign(args, JSON.parse(await utils_1.getStdin())); } else if (args.input) { Object.assign(args, JSON.parse(await txtfile.read(args.input))); } if (!args.id && !args.appId) { throw new Error('requires --id or --appId'); } for (const service of config.services) { if (service.type === botframework_config_1.ServiceTypes.Luis) { const luisService = service; if (luisService.id === args.id || luisService.appId === args.appId) { if (args.hasOwnProperty('name')) luisService.name = args.name; if (args.appId) luisService.appId = args.appId; if (args.subscriptionKey) luisService.subscriptionKey = args.subscriptionKey; if (args.authoringKey) luisService.authoringKey = args.authoringKey; if (args.region) luisService.region = args.region; if (args.version) luisService.version = args.version; await config.save(args.secret); await stdioAsync_1.stdoutAsync(JSON.stringify(luisService, null, 2)); return config; } } } throw new Error(`LUIS Service ${args.appId} was not found in the bot file`); } function showErrorHelp() { program.outputHelp((str) => { console.error(str); return ''; }); process.exit(1); } //# sourceMappingURL=msbot-update-luis.js.map