-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcreate.js
56 lines (42 loc) · 1.55 KB
/
create.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands,
AutopilotCore = require("@dabblelab/autopilot-core"),
ora = require("ora"),
path = require("path"),
{ convertYargsOptionsToOclifFlags, normalizeFlags } = require("../../utils"),
{ options, describe } = require("../../lib/options/create");
class CreateAssistant extends TwilioClientCommand {
async run() {
await super.run();
let spinner = await ora();
try {
let { flags } = await this.parse(CreateAssistant);
flags = normalizeFlags(flags);
let schema = flags.schema,
clonedAssistant = "";
if (schema == "templates") {
//TODO: the templates.json url should not be hard coded
let url =
"https://raw.githubusercontent.com/twilio/autopilot-templates/master/Assistants/templates.json";
clonedAssistant = await AutopilotCore.cloneTemplate(url, false);
schema = path.join(clonedAssistant, "schema.json");
}
spinner.start("Creating bot...");
let fullPath = `${path.resolve()}/${schema}`;
const assistant = await AutopilotCore.createAssistant(
fullPath,
this.twilioClient
);
spinner.stop();
console.log(`Bot "${assistant.uniqueName}" was created`);
} catch (err) {
spinner.stop();
console.error(`ERROR: ${err}`);
}
}
}
CreateAssistant.description = describe;
CreateAssistant.flags = Object.assign(
convertYargsOptionsToOclifFlags(options),
{ profile: TwilioClientCommand.flags.profile }
);
module.exports = CreateAssistant;