-
Notifications
You must be signed in to change notification settings - Fork 7
/
delete.js
79 lines (65 loc) · 2.21 KB
/
delete.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
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands,
AutopilotCore = require("@dabblelab/autopilot-core"),
ora = require("ora"),
{
convertYargsOptionsToOclifFlags,
normalizeFlags,
} = require("../../../utils"),
{ options, describe } = require("../../../lib/options/webhooks/delete");
class DeleteAssistantWebhook extends TwilioClientCommand {
async run() {
await super.run();
let { flags } = await this.parse(DeleteAssistantWebhook);
flags = normalizeFlags(flags);
if (!flags.hasOwnProperty("assistantSid")) {
console.log(`The '--assistant-sid' is required`);
return;
}
const spinner = ora();
try {
const { assistantSid, webhookSid } = flags;
let wSid = webhookSid;
if (!webhookSid) {
spinner.start(`Getting webhook list...`);
const webhookList = await AutopilotCore.webhooks.list(
this.twilioClient,
assistantSid
),
webhookChoice = webhookList.map((t) => t.uniqueName);
spinner.stop();
if (!webhookList.length) {
console.log(
`\n No webhook found to delete \n Use "twilio autopilot:webhooks:create" if you need to create a new webhook.`
);
return;
}
const answer = await this.inquirer.prompt([
{
type: "list",
name: "webhookUniqueName",
message: "Select the webhook you want to delete: ",
choices: webhookChoice,
},
]);
wSid = answer.webhookUniqueName;
}
spinner.start("Deleting assistant webhooks...\n");
const webhook = await AutopilotCore.webhooks.remove(
this.twilioClient,
assistantSid,
wSid
);
spinner.stop();
console.log(`Webhooks "${wSid}" was deleted`);
} catch (err) {
spinner.stop();
console.error(`ERROR: ${err.message}`);
}
}
}
DeleteAssistantWebhook.description = describe;
DeleteAssistantWebhook.flags = Object.assign(
convertYargsOptionsToOclifFlags(options),
{ profile: TwilioClientCommand.flags.profile }
);
module.exports = DeleteAssistantWebhook;