Skip to content

Commit 7ce4669

Browse files
issues, improvements and new commands
1 parent 07adf6a commit 7ce4669

File tree

17 files changed

+867
-82
lines changed

17 files changed

+867
-82
lines changed

package-lock.json

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

package.json

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
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.6",
4+
"version": "1.0.0-beta.7",
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.7",
8+
"@dabblelab/autopilot-core": "^1.0.0-beta.8",
99
"@oclif/command": "^1.5.19",
1010
"@oclif/config": "^1.13.3",
1111
"@oclif/plugin-help": "^2.2.1",
1212
"@twilio/cli-core": "^3.0.3",
13-
"csv-parse": "^4.5.0",
13+
"csv-parse": "^4.6.3",
1414
"extract-zip": "^1.6.7",
1515
"ora": "^3.4.0",
1616
"pretty-json-stringify": "0.0.2",
@@ -83,6 +83,57 @@
8383
},
8484
"autopilot:import": {
8585
"description": "Import a DialogFlow Agent/Alexa Interaction Model"
86+
},
87+
"autopilot:tasks": {
88+
"description": "Create, Update, Delete, and List Twilio Autopilot Assistant Tasks"
89+
},
90+
"autopilot:tasks:list": {
91+
"description": "List all tasks of an assistant"
92+
},
93+
"autopilot:tasks:create": {
94+
"description": "Create a task of an assistant"
95+
},
96+
"autopilot:tasks:update": {
97+
"description": "Update a task of an assistant"
98+
},
99+
"autopilot:tasks:delete": {
100+
"description": "Delete a task of an assistant"
101+
},
102+
"autopilot:samples:upload": {
103+
"description": "Upload task samples"
104+
},
105+
"autopilot:fields": {
106+
"description": "Create, Update, Delete, and List Fields of a Task"
107+
},
108+
"autopilot:fields:create": {
109+
"description": "Create task field"
110+
},
111+
"autopilot:fields:list": {
112+
"description": "List task fields"
113+
},
114+
"autopilot:fields:delete": {
115+
"description": "Delete task field"
116+
},
117+
"autopilot:fieldtypes": {
118+
"description": "Create, Update, and List fieldTypes of an assistant"
119+
},
120+
"autopilot:fieldtypes:create": {
121+
"description": "Create assistant fieldType"
122+
},
123+
"autopilot:fieldtypes:list": {
124+
"description": "List Assistant fieldTypes"
125+
},
126+
"autopilot:fieldtypes:update": {
127+
"description": "Update Assistant fieldType"
128+
},
129+
"autopilot:fieldvalues:upload": {
130+
"description": "Upload FieldValues"
131+
},
132+
"autopilot:queries:export": {
133+
"description": "Export Assistant Queries"
134+
},
135+
"autopilot:modelbuilds:create": {
136+
"description": "Create Model Builds"
86137
}
87138
}
88139
},
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const {flags} = require('@oclif/command'),
2+
{ TwilioClientCommand } = require('@twilio/cli-core').baseCommands,
3+
AutopilotCore = require('@dabblelab/autopilot-core'),
4+
ora = require('ora');
5+
6+
class CreateAssistantTaskField extends TwilioClientCommand {
7+
8+
async runCommand() {
9+
10+
let { flags } = this.parse(CreateAssistantTaskField);
11+
12+
if (!flags.hasOwnProperty('assistantSid')) {
13+
console.log(`The '--assistantSid' is required`);
14+
return;
15+
}
16+
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+
27+
if(!flags.uniqueName){
28+
console.log(`The '--uniqueName' is required`);
29+
return;
30+
}
31+
32+
const spinner = ora().start('Creating task field...\n');
33+
try{
34+
35+
const {assistantSid, taskSid, fieldTypeSid, uniqueName} = flags,
36+
params = {
37+
uniqueName : uniqueName,
38+
fieldType : fieldTypeSid
39+
};
40+
41+
const field = await AutopilotCore.fields.create(this.twilioClient, assistantSid, taskSid, params);
42+
spinner.stop();
43+
console.log(`Task field with UniqueName: ${uniqueName} was created.`);
44+
}catch(err){
45+
46+
spinner.stop();
47+
48+
console.error(`ERROR: ${err}`);
49+
}
50+
}
51+
52+
}
53+
54+
CreateAssistantTaskField.description = `Create field of a task`;
55+
56+
CreateAssistantTaskField.flags = Object.assign(
57+
{
58+
assistantSid : flags.string({
59+
char : 's',
60+
description : 'assistant that owns the task',
61+
required : true
62+
}),
63+
taskSid : flags.string({
64+
description : 'task sid',
65+
required : true
66+
}),
67+
uniqueName : flags.string({
68+
description : 'field unique name',
69+
required : true
70+
}),
71+
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
74+
})
75+
},
76+
TwilioClientCommand.flags
77+
)
78+
79+
module.exports = CreateAssistantTaskField;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const {flags} = require('@oclif/command'),
2+
{ TwilioClientCommand } = require('@twilio/cli-core').baseCommands,
3+
AutopilotCore = require('@dabblelab/autopilot-core'),
4+
ora = require('ora');
5+
6+
class DeleteAssistantTaskField extends TwilioClientCommand {
7+
8+
async runCommand() {
9+
10+
let { flags } = this.parse(DeleteAssistantTaskField);
11+
12+
if (!flags.hasOwnProperty('assistantSid')) {
13+
console.log(`The '--assistantSid' is required`);
14+
return;
15+
}
16+
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+
27+
const spinner = ora().start('Deleting task field...\n');
28+
try{
29+
30+
const {assistantSid, taskSid, fieldTypeSid} = flags;
31+
32+
const field = await AutopilotCore.fields.remove(this.twilioClient, assistantSid, taskSid, fieldTypeSid);
33+
spinner.stop();
34+
console.log(`Task field with Sid: ${fieldTypeSid} was deleted.`);
35+
}catch(err){
36+
37+
spinner.stop();
38+
39+
console.error(`ERROR: ${err}`);
40+
}
41+
}
42+
43+
}
44+
45+
DeleteAssistantTaskField.description = `Delete a field of a task`;
46+
47+
DeleteAssistantTaskField.flags = Object.assign(
48+
{
49+
assistantSid : flags.string({
50+
char : 's',
51+
description : 'assistant that owns the task',
52+
required : true
53+
}),
54+
taskSid : flags.string({
55+
description : 'task sid',
56+
required : true
57+
}),
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
61+
})
62+
},
63+
TwilioClientCommand.flags
64+
)
65+
66+
module.exports = DeleteAssistantTaskField;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const {flags} = require('@oclif/command'),
2+
{ TwilioClientCommand } = require('@twilio/cli-core').baseCommands,
3+
AutopilotCore = require('@dabblelab/autopilot-core'),
4+
ora = require('ora');
5+
6+
class ListAssistantTaskFields extends TwilioClientCommand {
7+
8+
async runCommand() {
9+
10+
let { flags } = this.parse(ListAssistantTaskFields);
11+
12+
if (!flags.hasOwnProperty('assistantSid')) {
13+
console.log(`The '--assistantSid' is required`);
14+
return;
15+
}
16+
17+
if (!flags.hasOwnProperty('taskSid')) {
18+
console.log(`The '--taskSid' is required`);
19+
return;
20+
}
21+
const spinner = ora().start('Getting task fields...\n');
22+
try{
23+
24+
const {assistantSid, taskSid} = flags;
25+
const fullData = await AutopilotCore.fields.list(this.twilioClient, assistantSid, taskSid);
26+
spinner.stop();
27+
this.output(fullData, this.flags.properties);
28+
}catch(err){
29+
30+
spinner.stop()
31+
32+
console.error(`ERROR: ${err}`)
33+
}
34+
}
35+
36+
}
37+
38+
ListAssistantTaskFields.description = `List all fields of a task`;
39+
40+
ListAssistantTaskFields.flags = Object.assign(
41+
{
42+
properties: flags.string({
43+
default: 'sid, uniqueName, fieldType',
44+
description:
45+
'The Autopilot Assistant Task List.'
46+
}),
47+
assistantSid : flags.string({
48+
char : 's',
49+
description : 'assistant that owns the task',
50+
required : true
51+
}),
52+
taskSid : flags.string({
53+
description : 'task sid',
54+
required : true
55+
})
56+
},
57+
TwilioClientCommand.flags
58+
)
59+
60+
module.exports = ListAssistantTaskFields
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const {flags} = require('@oclif/command'),
2+
{ TwilioClientCommand } = require('@twilio/cli-core').baseCommands,
3+
AutopilotCore = require('@dabblelab/autopilot-core'),
4+
ora = require('ora');
5+
6+
class CreateAssistantFieldType extends TwilioClientCommand {
7+
8+
async runCommand() {
9+
10+
let { flags } = this.parse(CreateAssistantFieldType);
11+
12+
if (!flags.hasOwnProperty('assistantSid')) {
13+
console.log(`The '--assistantSid' is required`);
14+
return;
15+
}
16+
17+
if(!flags.uniqueName){
18+
console.log(`The '--uniqueName' is required`);
19+
return;
20+
}
21+
22+
const spinner = ora().start('Creating field type...\n');
23+
try{
24+
25+
const {assistantSid, uniqueName, friendlyName} = flags;
26+
let params = {
27+
uniqueName : uniqueName
28+
};
29+
30+
if(friendlyName)
31+
params.friendlyName = friendlyName;
32+
33+
const fieldType = await AutopilotCore.fieldTypes.create(this.twilioClient, assistantSid, params);
34+
spinner.stop();
35+
console.log(`Field Type with UniqueName: ${uniqueName} was created.`);
36+
}catch(err){
37+
38+
spinner.stop();
39+
40+
console.error(`ERROR: ${err}`);
41+
}
42+
}
43+
44+
}
45+
46+
CreateAssistantFieldType.description = `Create a field type of an assistant`;
47+
48+
CreateAssistantFieldType.flags = Object.assign(
49+
{
50+
assistantSid : flags.string({
51+
char : 's',
52+
description : 'assistant in which to create',
53+
required : true
54+
}),
55+
uniqueName : flags.string({
56+
description : 'unique name for the field type',
57+
required : true
58+
}),
59+
friendlyName : flags.string({
60+
description : 'friendly name for field type.'
61+
})
62+
},
63+
TwilioClientCommand.flags
64+
)
65+
66+
module.exports = CreateAssistantFieldType;

0 commit comments

Comments
 (0)