UNPKG

msbot

Version:

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

88 lines 3.48 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 stdioAsync_1 = require("./stdioAsync"); program.Command.prototype.unknownOption = (flag) => { console.error(chalk.default.redBright(`Unknown arguments: ${flag}`)); showErrorHelp(); }; program .name('msbot connect generic') .description('Connect a generic service to the bot (--id or --url is required)') .option('--id <id>', 'service id') .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') .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.id && !args.url) { throw new Error('requires --id or --url'); } for (const service of config.services) { if (service.type === botframework_config_1.ServiceTypes.Generic) { const genericService = service; if (genericService.id === args.id || genericService.url === args.url) { const id = service.id; const newService = new botframework_config_1.GenericService(args); Object.assign(service, newService); service.id = id; if (args.keys) { genericService.configuration = JSON.parse(args.keys); } await config.save(args.secret); await stdioAsync_1.stdoutAsync(JSON.stringify(genericService, null, 2)); return config; } } } throw new Error(`Generic Service ${args.url} was not found in the bot file`); } function showErrorHelp() { program.outputHelp((str) => { console.error(str); return ''; }); process.exit(1); } //# sourceMappingURL=msbot-update-generic.js.map