-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathimport.js
97 lines (78 loc) · 2.55 KB
/
import.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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/import");
class ImportAssistant extends TwilioClientCommand {
async run() {
await super.run();
let spinner = ora();
try {
let { flags, args } = await this.parse(ImportAssistant);
flags = normalizeFlags(flags);
let filename = ``,
assistant = {};
if (args.type === "alexa") {
if (!flags.hasOwnProperty("model")) {
console.log(`The '--model' argument is required`);
return;
}
const model = flags.model,
redirectURL = flags.redirectURL,
modelFullPath = `${path.resolve()}/${model}`;
spinner.start("Importing assistant...");
filename = await AutopilotCore.importAlexaModel(
modelFullPath,
redirectURL
);
} else {
if (!flags.hasOwnProperty("dfbackup")) {
console.log(`The '--dfbackup' argument is required`);
return;
}
if (!flags.hasOwnProperty("dfagent")) {
console.log(`The '--dfagent' argument is required`);
return;
}
const dfbackup = flags.dfbackup,
name = flags.dfagent,
dfFullPath = `${path.resolve()}/${dfbackup}`;
spinner.start("Importing bot...");
filename = await AutopilotCore.importDialogFlowAgent(dfFullPath, name);
}
const fullPath = path.resolve(process.cwd(), filename);
if (await AutopilotCore.existAssistant(fullPath, this.twilioClient)) {
assistant = await AutopilotCore.updateAssistant(
fullPath,
this.twilioClient
);
} else {
assistant = await AutopilotCore.createAssistant(
fullPath,
this.twilioClient
);
}
spinner.stop();
console.log(`Bot "${assistant.uniqueName}" was imported`);
} catch (err) {
spinner.stop();
console.error(`ERROR: ${err}`);
}
}
}
ImportAssistant.description = describe;
ImportAssistant.args = [
{
name: "type",
required: false,
description: "Type of import DialogFlow/Alexa",
default: "dialogflow",
options: ["dialogflow", "alexa"],
},
];
ImportAssistant.flags = Object.assign(
convertYargsOptionsToOclifFlags(options),
{ profile: TwilioClientCommand.flags.profile }
);
module.exports = ImportAssistant;