Skip to content

Commit b8934a3

Browse files
fix issues and improvements in new commands
1 parent 1a9781d commit b8934a3

File tree

23 files changed

+926
-238
lines changed

23 files changed

+926
-238
lines changed

README.md

Lines changed: 538 additions & 15 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@dabblelab/plugin-autopilot",
33
"description": "Create, Update, Delete, List, Simulate, Import and Export Twilio Autopilot Assistant",
4-
"version": "1.0.0-beta.8",
4+
"version": "1.0.0-beta.9",
55
"author": "Steve Tingiris",
66
"bugs": "https://github.com/tingiris/twilio-cli-autopilot-plugin/issues",
77
"dependencies": {
8-
"@dabblelab/autopilot-core": "^1.0.0-beta.9",
8+
"@dabblelab/autopilot-core": "^1.0.0-beta.10",
99
"@oclif/command": "^1.5.19",
1010
"@oclif/config": "^1.13.3",
1111
"@oclif/plugin-help": "^2.2.1",
@@ -77,9 +77,6 @@
7777
"autopilot:simulate": {
7878
"description": "Simulate an assistant"
7979
},
80-
"autopilot:field": {
81-
"description": "Bulk upload field values"
82-
},
8380
"autopilot:import": {
8481
"description": "Import a DialogFlow Agent/Alexa Interaction Model"
8582
},
@@ -158,7 +155,6 @@
158155
"scripts": {
159156
"postpack": "rm -f oclif.manifest.json",
160157
"posttest": "eslint --ignore-path .gitignore . && npm audit",
161-
"prepack": "oclif-dev manifest && oclif-dev readme",
162158
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
163159
"version": "oclif-dev readme && git add README.md"
164160
}

src/commands/autopilot/export.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ExportAssistants.description = `Export an assistant`;
5959
ExportAssistants.flags = Object.assign(
6060
{
6161
assistantSid : flags.string({
62+
char : 's',
6263
description : 'assistant sid'
6364
}),
6465
uniqueName : flags.string({

src/commands/autopilot/field.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/commands/autopilot/fields/create.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,86 @@ class CreateAssistantTaskField extends TwilioClientCommand {
1414
return;
1515
}
1616

17-
if(!flags.taskSid){
18-
console.log(`The '--taskSid' is required`);
19-
return;
20-
}
21-
22-
if(!flags.fieldTypeSid){
23-
console.log(`The '--fieldTypeSid' is required`);
24-
return;
25-
}
26-
2717
if(!flags.uniqueName){
2818
console.log(`The '--uniqueName' is required`);
2919
return;
3020
}
3121

32-
const spinner = ora().start('Creating task field...\n');
22+
const spinner = ora();
3323
try{
3424

3525
const {assistantSid, taskSid, fieldTypeSid, uniqueName} = flags,
3626
params = {
3727
uniqueName : uniqueName,
3828
fieldType : fieldTypeSid
3929
};
30+
let tSid = taskSid, fSid = fieldTypeSid;
31+
32+
if(!taskSid){
33+
34+
spinner.start(`Getting task list...`)
35+
const taskList = await AutopilotCore.tasks.list(this.twilioClient, assistantSid),
36+
taskChoice = taskList.map(t => t.uniqueName);
37+
38+
spinner.stop();
39+
if(!taskList.length){
40+
console.log(`\n No Task \n Use "twilio autopilot:tasks:create" if you need to create a new task.`);
41+
return;
42+
}
43+
const answer = await this.inquirer.prompt(
44+
[
45+
{
46+
type: 'list',
47+
name: 'taskUniqueName',
48+
message: 'Choose your task in which to create: ',
49+
choices: taskChoice
50+
}
51+
]
52+
);
53+
54+
tSid = answer.taskUniqueName;
55+
56+
}
57+
58+
if(!fieldTypeSid){
59+
60+
console.log(`\nUse 'twilio autopilot:fieldtypes:create' if you need to create a new field type.\n`);
61+
spinner.start('Getting Field Types...');
62+
const fieldTypeList = await AutopilotCore.fieldTypes.list(this.twilioClient, assistantSid),
63+
builtInFieldTypesList = await AutopilotCore.builtInFieldTypes,
64+
fieldTypeChoice = fieldTypeList.map(f => f.uniqueName),
65+
builtInFieldTypesChoice = builtInFieldTypesList.map(b => b.uniqueName);
66+
67+
let f_choices = builtInFieldTypesChoice, inquirer = this.inquirer;
68+
if(fieldTypeChoice.length)
69+
f_choices = [...new Set(fieldTypeChoice), new inquirer.Separator(), ...new Set(builtInFieldTypesChoice)];
70+
71+
spinner.stop();
72+
const answer = await this.inquirer.prompt(
73+
[
74+
{
75+
type: 'list',
76+
name: 'fieldTypeUniqueName',
77+
message: 'Choose your Field Type to create: ',
78+
choices: f_choices
79+
}
80+
]
81+
);
82+
83+
fSid = answer.fieldTypeUniqueName;
84+
85+
}
86+
spinner.start('Creating task field...\n')
87+
params.fieldType = fSid;
88+
89+
const field = await AutopilotCore.fields.create(this.twilioClient, assistantSid, tSid, params);
4090

41-
const field = await AutopilotCore.fields.create(this.twilioClient, assistantSid, taskSid, params);
4291
spinner.stop();
4392
console.log(`Task field with UniqueName: ${uniqueName} was created.`);
4493
}catch(err){
4594

4695
spinner.stop();
47-
48-
console.error(`ERROR: ${err}`);
96+
console.error(`ERROR: ${err.message}`);
4997
}
5098
}
5199

@@ -61,16 +109,14 @@ CreateAssistantTaskField.flags = Object.assign(
61109
required : true
62110
}),
63111
taskSid : flags.string({
64-
description : 'task sid',
65-
required : true
112+
description : 'task sid'
66113
}),
67114
uniqueName : flags.string({
68115
description : 'field unique name',
69116
required : true
70117
}),
71118
fieldTypeSid : flags.string({
72-
description : 'The Field Type of the new field. Can be: a [Built-in FieldType](https://www.twilio.com/docs/assistant/api/built-in-field-types ), the `unique_name`, or the `sid` of a custom Field Type.',
73-
required : true
119+
description : 'The Field Type of the new field. Can be: a [Built-in FieldType](https://www.twilio.com/docs/assistant/api/built-in-field-types ), the `unique_name`, or the `sid` of a custom Field Type.'
74120
})
75121
},
76122
TwilioClientCommand.flags

src/commands/autopilot/fields/delete.js

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,71 @@ class DeleteAssistantTaskField extends TwilioClientCommand {
1414
return;
1515
}
1616

17-
if(!flags.taskSid){
18-
console.log(`The '--taskSid' is required`);
19-
return;
20-
}
17+
const spinner = ora();
18+
try{
2119

22-
if(!flags.fieldTypeSid){
23-
console.log(`The '--fieldTypeSid' is required`);
24-
return;
25-
}
20+
const {assistantSid, taskSid, fieldSid} = flags;
21+
let tSid = taskSid, fSid = fieldSid;
2622

27-
const spinner = ora().start('Deleting task field...\n');
28-
try{
23+
if(!taskSid){
24+
25+
spinner.start(`Getting task list...`)
26+
const taskList = await AutopilotCore.tasks.list(this.twilioClient, assistantSid),
27+
taskChoice = taskList.map(t => t.uniqueName);
2928

30-
const {assistantSid, taskSid, fieldTypeSid} = flags;
29+
spinner.stop();
30+
if(!taskList.length){
31+
console.log(`\n No Task in which to delete fields \n Use "twilio autopilot:tasks:create" if you need to create a new task.`);
32+
return;
33+
}
34+
const answer = await this.inquirer.prompt(
35+
[
36+
{
37+
type: 'list',
38+
name: 'taskUniqueName',
39+
message: 'Choose your task in which to delete: ',
40+
choices: taskChoice
41+
}
42+
]
43+
);
3144

32-
const field = await AutopilotCore.fields.remove(this.twilioClient, assistantSid, taskSid, fieldTypeSid);
45+
tSid = answer.taskUniqueName;
46+
}
47+
48+
if(!fieldSid){
49+
50+
spinner.start(`Getting task fields list...`)
51+
const fieldList = await AutopilotCore.fields.list(this.twilioClient, assistantSid, tSid),
52+
fieldChoice = fieldList.map(f => f.uniqueName);
53+
54+
spinner.stop();
55+
if(!fieldList.length){
56+
console.log(`\n No Task Fields to delete \n Use "twilio autopilot:fields:create" if you need to create a new task field.`);
57+
return;
58+
}
59+
const answer = await this.inquirer.prompt(
60+
[
61+
{
62+
type: 'list',
63+
name: 'fieldUniqueName',
64+
message: 'Choose your Field to delete: ',
65+
choices: fieldChoice
66+
}
67+
]
68+
);
69+
70+
fSid = answer.fieldUniqueName;
71+
}
72+
73+
spinner.start('Deleting task field...\n');
74+
const field = await AutopilotCore.fields.remove(this.twilioClient, assistantSid, tSid, fSid);
3375
spinner.stop();
34-
console.log(`Task field with Sid: ${fieldTypeSid} was deleted.`);
76+
console.log(`Task field '${fSid}' was deleted.`);
3577
}catch(err){
3678

3779
spinner.stop();
3880

39-
console.error(`ERROR: ${err}`);
81+
console.error(`ERROR: ${err.message}`);
4082
}
4183
}
4284

@@ -52,12 +94,10 @@ DeleteAssistantTaskField.flags = Object.assign(
5294
required : true
5395
}),
5496
taskSid : flags.string({
55-
description : 'task sid',
56-
required : true
97+
description : 'task sid'
5798
}),
58-
fieldTypeSid : flags.string({
59-
description : 'The Field Type of the new field. Can be: a [Built-in FieldType](https://www.twilio.com/docs/assistant/api/built-in-field-types ), the `unique_name`, or the `sid` of a custom Field Type.',
60-
required : true
99+
fieldSid : flags.string({
100+
description : 'The Field Type of the new field. Can be: a [Built-in FieldType](https://www.twilio.com/docs/assistant/api/built-in-field-types ), the `unique_name`, or the `sid` of a custom Field Type.'
61101
})
62102
},
63103
TwilioClientCommand.flags

0 commit comments

Comments
 (0)