-
Notifications
You must be signed in to change notification settings - Fork 7
/
update.js
86 lines (70 loc) · 2.34 KB
/
update.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
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands,
AutopilotCore = require("@dabblelab/autopilot-core"),
ora = require("ora"),
{
convertYargsOptionsToOclifFlags,
normalizeFlags,
} = require("../../../utils"),
{ options, describe } = require("../../../lib/options/tasks/update");
class UpdateAssistantTask extends TwilioClientCommand {
async run() {
await super.run();
let { flags } = await this.parse(UpdateAssistantTask);
flags = normalizeFlags(flags);
if (!flags.hasOwnProperty("assistantSid")) {
console.log(`The '--assistant-sid' is required`);
return;
}
const spinner = ora();
try {
const { assistantSid, taskSid, uniqueName, friendlyName } = flags;
let tSid = taskSid;
if (!taskSid) {
spinner.start(`Getting task list...`);
const taskList = await AutopilotCore.tasks.list(
this.twilioClient,
assistantSid
),
taskChoice = taskList.map((t) => t.uniqueName);
spinner.stop();
if (!taskList.length) {
console.log(
`\n No Task found to update \n Use "twilio autopilot:tasks:create" if you need to create a new task.`
);
return;
}
const answer = await this.inquirer.prompt([
{
type: "list",
name: "taskUniqueName",
message: "Choose the Task to update: ",
choices: taskChoice,
},
]);
tSid = answer.taskUniqueName;
}
spinner.start("Updating assistant task...\n");
let params = {};
if (uniqueName) params.uniqueName = uniqueName;
if (friendlyName) params.friendlyName = friendlyName;
if (Object.keys(params).length)
await AutopilotCore.tasks.update(
this.twilioClient,
assistantSid,
tSid,
params
);
spinner.stop();
console.log(`Task "${tSid}" was updated`);
} catch (err) {
spinner.stop();
console.error(`ERROR: ${err.message}`);
}
}
}
UpdateAssistantTask.description = describe;
UpdateAssistantTask.flags = Object.assign(
convertYargsOptionsToOclifFlags(options),
{ profile: TwilioClientCommand.flags.profile }
);
module.exports = UpdateAssistantTask;