@@ -15,7 +15,7 @@ const parseText = (text) => {
15
15
const parsedText = {
16
16
taskType : textArray [ 0 ] . trim ( ) ,
17
17
taskTime : textArray [ 1 ] . trim ( ) ,
18
- taskText : textArray [ 2 ] . trim ( )
18
+ taskText : textArray [ 2 ] . trim ( ) ,
19
19
}
20
20
21
21
return parsedText
@@ -25,7 +25,7 @@ const parseText = (text) => {
25
25
const determineTaskType = ( taskTypes , searchString ) => {
26
26
const options = {
27
27
includeScore : true ,
28
- keys : [ 'taskTypes.name' ]
28
+ keys : [ 'taskTypes.name' ] ,
29
29
}
30
30
31
31
const fuse = new Fuse ( taskTypes , options )
@@ -42,7 +42,7 @@ const returnTaskTypes = async (env) => {
42
42
const url = `${ codaEP } /docs/${ docId } /tables/${ typesTableId } /rows`
43
43
const headers = {
44
44
'Content-Type' : 'application/json' ,
45
- ' Authorization' : `Bearer ${ env . CODA_API_KEY } `
45
+ Authorization : `Bearer ${ env . CODA_API_KEY } ` ,
46
46
}
47
47
48
48
const init = {
@@ -51,44 +51,52 @@ const returnTaskTypes = async (env) => {
51
51
}
52
52
53
53
try {
54
- const response = await fetch ( url , init ) ;
54
+ const response = await fetch ( url , init )
55
55
const rj = await response . json ( )
56
56
return rj
57
57
} catch ( e ) {
58
58
console . log ( e )
59
- return new Response ( " Oops! Something went wrong. Please try again later." )
59
+ return new Response ( ' Oops! Something went wrong. Please try again later.' )
60
60
}
61
61
}
62
62
63
63
const generateCodaData = async ( message , env ) => {
64
64
const simple = ! message . includes ( delimiter )
65
65
66
- let data = { rows : [ { cells : [ ] } ] } ;
66
+ let data = { rows : [ { cells : [ ] } ] }
67
67
68
68
function Cell ( columnName , column , value ) {
69
69
this . column = column
70
70
this . value = value
71
71
}
72
72
73
- if ( simple ) {
74
- data . rows [ 0 ] . cells . push ( new Cell ( " Task Name" , " c-70z9tdOF3c" , message ) )
75
- data . rows [ 0 ] . cells . push ( new Cell ( " Task Status" , " c-kN87N8b6Gr" , " Backlog" ) )
76
- data . rows [ 0 ] . cells . push ( new Cell ( " Needs Triage" , " c-2alHSrothg" , true ) )
73
+ if ( simple ) {
74
+ data . rows [ 0 ] . cells . push ( new Cell ( ' Task Name' , ' c-70z9tdOF3c' , message ) )
75
+ data . rows [ 0 ] . cells . push ( new Cell ( ' Task Status' , ' c-kN87N8b6Gr' , ' Backlog' ) )
76
+ data . rows [ 0 ] . cells . push ( new Cell ( ' Needs Triage' , ' c-2alHSrothg' , true ) )
77
77
} else {
78
78
const taskTypeTable = await returnTaskTypes ( env )
79
- const taskTypes = taskTypeTable . items . map ( item => item . name )
79
+ const taskTypes = taskTypeTable . items . map ( ( item ) => item . name )
80
80
const parsedText = parseText ( message )
81
81
const taskTypeMatch = determineTaskType ( taskTypes , parsedText . taskType )
82
-
82
+
83
83
if ( ! taskTypeMatch ) {
84
- return console . error ( "Sorry, I don't know that task type. Please try again." )
84
+ return console . error (
85
+ "Sorry, I don't know that task type. Please try again."
86
+ )
85
87
}
86
88
87
- data . rows [ 0 ] . cells . push ( new Cell ( "Task Name" , "c-70z9tdOF3c" , parsedText . taskText ) )
88
- data . rows [ 0 ] . cells . push ( new Cell ( "Task Status" , "c-kN87N8b6Gr" , "Backlog" ) )
89
- data . rows [ 0 ] . cells . push ( new Cell ( "Task Type" , "c-eDVIqu2xj_" , taskTypeMatch ) )
90
- data . rows [ 0 ] . cells . push ( new Cell ( "Predicted Duration" , "c-L4lltHxi-h" , parsedText . taskTime , ) )
91
- data . rows [ 0 ] . cells . push ( new Cell ( "Needs Triage" , "c-2alHSrothg" , true ) )
89
+ data . rows [ 0 ] . cells . push (
90
+ new Cell ( 'Task Name' , 'c-70z9tdOF3c' , parsedText . taskText )
91
+ )
92
+ data . rows [ 0 ] . cells . push ( new Cell ( 'Task Status' , 'c-kN87N8b6Gr' , 'Backlog' ) )
93
+ data . rows [ 0 ] . cells . push (
94
+ new Cell ( 'Task Type' , 'c-eDVIqu2xj_' , taskTypeMatch )
95
+ )
96
+ data . rows [ 0 ] . cells . push (
97
+ new Cell ( 'Predicted Duration' , 'c-L4lltHxi-h' , parsedText . taskTime )
98
+ )
99
+ data . rows [ 0 ] . cells . push ( new Cell ( 'Needs Triage' , 'c-2alHSrothg' , true ) )
92
100
}
93
101
return data
94
102
}
@@ -104,7 +112,7 @@ const addCodaTodo = async (message, env) => {
104
112
const url = `${ codaEP } /docs/${ docId } /tables/${ taskTableId } /rows`
105
113
const headers = {
106
114
'Content-Type' : 'application/json' ,
107
- ' Authorization' : 'Bearer ' + CODA_API_KEY
115
+ Authorization : 'Bearer ' + CODA_API_KEY ,
108
116
}
109
117
110
118
const init = {
@@ -114,46 +122,46 @@ const addCodaTodo = async (message, env) => {
114
122
}
115
123
116
124
try {
117
- const response = await fetch ( url , init ) ;
125
+ const response = await fetch ( url , init )
118
126
const rj = await response . json ( )
119
127
return rj
120
128
} catch ( e ) {
121
129
console . log ( e )
122
- return new Response ( " Oops! Something went wrong. Please try again later." )
130
+ return new Response ( ' Oops! Something went wrong. Please try again later.' )
123
131
}
124
132
}
125
133
126
134
export default {
127
135
async fetch ( request , env ) {
128
136
const OUTBOUND_PHONE = env . OUTBOUND_PHONE
129
-
137
+
130
138
if ( request . method != 'POST' ) {
131
- return new Response ( " Method Not Allowed" , {
132
- status : 405
139
+ return new Response ( ' Method Not Allowed' , {
140
+ status : 405 ,
133
141
} )
134
142
}
135
143
136
144
// Get body of the request - will be text since it's URL encoded
137
- const data = await request . text ( ) ;
145
+ const data = await request . text ( )
138
146
139
147
// Decode URL
140
- const params = new URLSearchParams ( data ) ;
148
+ const params = new URLSearchParams ( data )
141
149
// Get query params and put in a JS object
142
- const twilioObject = Object . fromEntries ( params . entries ( ) ) ;
143
- const fromNumber = twilioObject . From ;
150
+ const twilioObject = Object . fromEntries ( params . entries ( ) )
151
+ const fromNumber = twilioObject . From
144
152
145
153
// Only allow texts from the users number
146
154
if ( fromNumber != OUTBOUND_PHONE ) {
147
- return new Response ( " Forbidden" , {
148
- status : 403
155
+ return new Response ( ' Forbidden' , {
156
+ status : 403 ,
149
157
} )
150
158
}
151
159
152
- const message = twilioObject . Body ;
160
+ const message = twilioObject . Body
153
161
154
162
const response = await addCodaTodo ( message , env )
155
163
console . log ( JSON . stringify ( response ) )
156
164
157
- return new Response ( " Item successfully added!" )
165
+ return new Response ( ' Item successfully added!' )
158
166
} ,
159
- } ;
167
+ }
0 commit comments