-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontEnd.sh
More file actions
executable file
·502 lines (427 loc) · 15.4 KB
/
Copy pathFrontEnd.sh
File metadata and controls
executable file
·502 lines (427 loc) · 15.4 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!/bin/bash
echo "Alexa Skill Generator v1.0 - Robert Balmbra"
echo -e "Warning - Please read the README file for usage information and specific requirements.\n"
#make sure ask is installed
if ! type "ask" > /dev/null; then
echo "Error - 'Ask' isnt installed, please install it"
exit 1
fi
#check if ~/.ask/cli_config
if [ ! -f ~/.ask/cli_config ]; then
echo "Error - Alexa config doesnt exist, please run ask init"
exit 2
fi
#make sure node is installed
if ! type "node" > /dev/null; then
echo "Error - 'node' isnt installed, please install it"
exit 3
fi
#make sure typescript is installed
if ! type "tsc" > /dev/null; then
echo "Error - 'tsc' isnt installed, please install it"
exit 4
fi
echo "What is the skill name called: "
read APP_NAME
directory=$(echo $APP_NAME | tr "[:upper:]" "[:lower:]" | sed 's/ /-/g') #pc made directory from APP_NAME
#check if directory exists before processing
if [ -d "$directory" ]; then
echo "Error - The app name '$directory' exists, please use another name or use a different folder."
exit 5
fi
#get basic template
ask new --skill-name "${APP_NAME}" --template Basic --url https://sandr-photography.com/alexa/templates.json &> /dev/null
#insert user input to skill.json
sed -e "s/\${APP_NAME}/${APP_NAME}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
sed -e "s/\${NAME}/${APP_NAME}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
#sed -e "s/\${directory}/${$APP_NAME}/" $directory/skill.json > $directory/skill.json.tmp
#mv $directory/skill.json.tmp $directory/skill.json
sed -e "s/$directory/$APP_NAME/g" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
echo "What is the invocation name: "
read invocationName
echo "What is your name: "
read FULL_NAME
sed -e "s/\${FULL_NAME}/${FULL_NAME}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
echo "Please enter a keyword that describes the skill: "
read KEYWORD_1
echo "Please enter another keyword that describes the skill: "
read KEYWORD_2
echo "Please enter a final keyword that describes the skill: "
read KEYWORD_3
#write keywords to skill.json
sed -e "s/\${KEYWORD_1}/${KEYWORD_1}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
sed -e "s/\${KEYWORD_2}/${KEYWORD_2}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
sed -e "s/\${KEYWORD_3}/${KEYWORD_3}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
echo -e "\n"
#Application category
Applicationtypes[0]="ALARMS_AND_CLOCKS"
Applicationtypes[1]="ASTROLOGY"
Applicationtypes[2]="BUSINESS_AND_FINANCE"
Applicationtypes[3]="CALCULATORS"
Applicationtypes[4]="CALENDARS_AND_REMINDERS"
Applicationtypes[5]="COMMUNICATION"
Applicationtypes[6]="CONNECTED_CAR"
Applicationtypes[7]="COOKING_AND_RECIPE"
Applicationtypes[8]="CURRENCY_GUIDES_AND_CONVERTERS"
Applicationtypes[9]="DATING"
Applicationtypes[10]="DELIVERY_AND_TAKEOUT"
Applicationtypes[11]="DEVICE_TRACKING"
Applicationtypes[12]="EDUCATION_AND_REFERENCE"
Applicationtypes[13]="EVENT_FINDERS"
Applicationtypes[14]="EXERCISE_AND_WORKOUT"
Applicationtypes[15]="FASHION_AND_STYLE"
Applicationtypes[16]="FLIGHT_FINDERS"
Applicationtypes[17]="FRIENDS_AND_FAMILY"
Applicationtypes[18]="GAME_INFO_AND_ACCESSORY"
Applicationtypes[19]="GAMES"
Applicationtypes[20]="HEALTH_AND_FITNESS"
Applicationtypes[21]="HOTEL_FINDERS"
Applicationtypes[22]="KNOWLEDGE_AND_TRIVIA"
Applicationtypes[23]="MOVIE_AND_TV_KNOWLEDGE_AND_TRIVIA"
Applicationtypes[24]="MOVIE_INFO_AND_REVIEWS"
Applicationtypes[25]="MOVIE_SHOWTIMES"
Applicationtypes[26]="MUSIC_AND_AUDIO_ACCESSORIES"
Applicationtypes[27]="MUSIC_AND_AUDIO_KNOWLEDGE_AND_TRIVIA"
Applicationtypes[28]="MUSIC_INFO_REVIEWS_AND_RECOGNITION_SERVICE"
Applicationtypes[29]="NAVIGATION_AND_TRIP_PLANNER"
Applicationtypes[30]="NEWS"
Applicationtypes[31]="NOVELTY"
Applicationtypes[32]="ORGANIZERS_AND_ASSISTANTS"
Applicationtypes[33]="PETS_AND_ANIMAL"
Applicationtypes[34]="PODCAST"
Applicationtypes[35]="PUBLIC_TRANSPORTATION"
Applicationtypes[36]="RELIGION_AND_SPIRITUALITY"
Applicationtypes[37]="RESTAURANT_BOOKING_INFO_AND_REVIEW"
Applicationtypes[38]="SCHOOLS"
Applicationtypes[39]="SCORE_KEEPING"
Applicationtypes[40]="SELF_IMPROVEMENT"
Applicationtypes[41]="SHOPPING"
Applicationtypes[42]="SMART_HOME"
Applicationtypes[43]="SOCIAL_NETWORKING"
Applicationtypes[44]="SPORTS_GAMES"
Applicationtypes[45]="SPORTS_NEWS"
Applicationtypes[46]="STREAMING_SERVICE"
Applicationtypes[47]="TAXI_AND_RIDESHARING"
Applicationtypes[48]="TO_DO_LISTS_AND_NOTES"
Applicationtypes[49]="TRANSLATORS"
Applicationtypes[50]="TV_GUIDES"
Applicationtypes[51]="UNIT_CONVERTERS"
Applicationtypes[52]="WEATHER"
Applicationtypes[53]="WINE_AND_BEVERAGE"
Applicationtypes[54]="ZIP_CODE_LOOKUP"
i=1
for category in "${Applicationtypes[@]}"
do
str="${category//_/ }"
echo $i. $str
((i++))
done
echo "Please select the number of the desired category above: "
read choice
categorycalc=`expr $choice - 1`
CATEGORY=${Applicationtypes[$categorycalc]}
echo -e "\n"
sed -e "s/\${CATEGORY}/${CATEGORY}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
#phrases input
echo "Enter first phrase: "
read PHRASE_1
echo -e "\n"
sed -e "s/\${PHRASE_1}/${PHRASE_1}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
output="Alexa ask ${invocationName}, ${PHRASE_1}"
sed -e "s/\${PHRASE_1}/${output}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
echo "Enter second phrase: "
read PHRASE_2
echo -e "\n"
sed -e "s/\${PHRASE_2}/${PHRASE_2}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
sed -e "s/\${PHRASE_2}/${PHRASE_2}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
echo "Enter third phrase: "
read PHRASE_3
echo -e "\n"
sed -e "s/\${PHRASE_3}/${PHRASE_3}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
sed -e "s/\${PHRASE_3}/${PHRASE_3}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
#enter short description
echo "Enter short description: "
read SHORT_DESC
echo -e "\n"
sed -e "s/\${SHORT_DESC}/${SHORT_DESC}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
echo "Enter long description: "
#enter long description
read FULL_DESC
echo -e "\n"
sed -e "s/\${FULL_DESC}/${FULL_DESC}/" $directory/skill.json > $directory/skill.json.tmp
mv $directory/skill.json.tmp $directory/skill.json
declare -a intents=()
#header
file="model.test"
echo -e "{\n \"interactionModel\": {\n \"languageModel\": {\n \"invocationName\": \"$invocationName\",\n \"intents\": [" > $file
#Loop over generation of intents
i=0
intentmaincount=0
echo "Warning - Please only use periods and characters, numbers are not supported within Intent Names."
while true
do
echo -e "\nEnter an intent name: "
read IntentName
echo -e "\nDo you want to add another intent (Y/N): "
read OtherIntent
intents[i]=$IntentName
if [ $OtherIntent == 'n' ] || [ $OtherIntent == 'N' ];
then
break
fi
((i=i+1))
((intentmaincount++))
done
#Write raw template
i=0
for intent in "${intents[@]}"
do
echo "$intent"
if [ $i != 0 ];
then
comma=','
else
comma=''
fi
echo -e " $comma{\n \"name\": \"${intent}\",\n \"slots\": [\${SLOTS_$i}],\n \"samples\": [\${SAMPLES_$i}]\n }" >> $file
cat <<- EOF >> $directory/lambda/custom/index.ts
,
'$intent': function () {
let self: Alexa.Handler = this;
var speechOutput = "";
self.emit(":tellWithCard", speechOutput, this.t('APP_NAME'), speechOutput);
}
EOF
((i=i+1))
done
cat <<- EOF >> $directory/lambda/custom/index.ts
}
export class handler {
constructor(event: Alexa.RequestBody, context: Alexa.context, callback: Function) {
let alexa = Alexa.handler(event, context);
alexa.appId = "${SKILL_ID}";
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
}
}
EOF
cat << EOF >> $file
,{
"name": "AMAZON.HelpIntent"
}
,{
"name": "AMAZON.StopIntent"
}
,{
"name": "AMAZON.CancelIntent"
}
,{
"name": "AboutIntent",
"slots":[],
"samples":["Who wrote this Skill","Who is the developer of this skill","Who developed this skill","Who designed this skill"]
}
EOF
#Loop over intents and ask for some samples
i=0
slotcount=0
runOnce=0
runoncet=0
for intent in "${intents[@]}"
do
sampleslist=""
declare -a slotnames=()
while true
do
echo -e "\nPlease type a sample for $intent: "
read Sample
sampleslist+="\"$Sample\""
echo -e "\nDo you want add any other samples (Y/N): "
read Answer
if [ $Answer == 'n' ] || [ $Answer == 'N' ];
then
#write to file
sed -e "s/\${SAMPLES_$i}/$sampleslist/" $file > $file.tmp
mv $file.tmp $file
echo -e "\nDoes this intent need any slots (Y/N): "
read SlotAnswer
o=0
if [ $SlotAnswer == 'n' ] || [ $SlotAnswer == 'N' ];
then
nothing=""
sed -e "s/\${SLOTS_$i}/$nothing/" $file > $file.tmp
mv $file.tmp $file
break
fi
slotstring=""
comma=""
while true
do
echo "Please type the slot name: "
read SlotName
echo "Please type the custom or AMAZON slot type: "
read SlotType
#append into string
if [ $o != 0 ]; then
comma=","
else
comma=""
fi
read -r -d '' slotstringtmpg << EOM
$comma{
"name": "$SlotName",
"type": "$SlotType"
}
EOM
slotstringtmp=`echo -e ${slotstringtmpg} | tr '\n' "\r"`
slotstring+=$slotstringtmp
if [[ $SlotType == *"AMAZON"* ]]; then
echo "AMAZON slot type inserted into model"
else
echo "Please type your custom types, seperated by a comma: "
read CustomType
if [ $runOnce == 0 ]; then
echo -e " ],\n \"types\":[" >> $file
runOnce=1
fi
if [ $o != 0 ]; then
echo -e " ,{\n \"name\": \"$SlotType\",\n \"values\": [" >> $file
else
if [ $runoncet == 1 ]; then
echo -e " ,{\n \"name\": \"$SlotType\",\n \"values\": [" >> $file
else
echo -e " {\n \"name\": \"$SlotType\",\n \"values\": [" >> $file
runoncet=1
fi
fi
l=0
comma=''
wordsfull=$(echo $CustomType | tr "," "\n")
wordscount=0
for word in $wordsfull
do
((wordscount++))
done
((wordscount--))
for word in $wordsfull
do
if [ $l != 0 ]; then
comma=' ,'
else
comma=' '
fi
if [ $l == $wordscount ]; then
echo -e "$comma{\n \"name\": {\n \"value\": \"$word\"\n }\n }\n ]\n }" >> $file
else
echo -e "$comma{\n \"name\": {\n \"value\": \"$word\"\n }\n }" >> $file
fi
((l=l+1))
done
fi
(( slotcount+=1 ))
echo "Do you want to insert anymore slots (Y/N): "
read Answer
((o++))
if [ $Answer == 'n' ] || [ $Answer == 'N' ];
then
o=0
echo $slotstring
sed -e "s/\${SLOTS_$i}/$slotstring/" $file > $file.tmp
mv $file.tmp $file
break
fi
done
#finish intent
break
else
sampleslist+=","
fi
done
((i=i+1))
done
if [ $o != 0 ]; then
echo -e " ]\n }\n }\n }\n" >> $file
else
echo -e "\n ] \n } \n } \n }" >> $file
fi
echo "Type the number of the intent that should be initially placed into the mocha test framework, this can be changed altered in the future: "
u=1
for intent in "${intents[@]}"
do
echo "$u. $intent"
((u=u+1))
done
max=$((u-1))
while true
do
read UserInputIntent
if [ "$UserInputIntent" -ge 1 ] && [ "$UserInputIntent" -le $max ]
then
id=$((UserInputIntent-1))
break
else
echo "Invalid choice, please try again:"
fi
done
echo "Added intent '${intents[$id]}' to the mocha framework"
sed -e "s/\${INTENT_NAME}/${intents[$id]}/" $directory/lambda/custom/test/index.js > $directory/lambda/custom/test/index.js.tmp
mv $directory/lambda/custom/test/index.js.tmp $directory/lambda/custom/test/index.js
echo -e "\nCopying temporary model over to models folder"
#copy model.test over each model
FILES=$directory/models/*
for f in $FILES
do
cp model.test $f
done
echo "Generating index.js using tsc"
cd $directory/lambda/custom/
tsc index.ts
cd ../../../
echo -e "\nDeploying initial alexa skill, please wait"
cd $directory
ask deploy
#return opcode
if [[ $? -eq 0 ]]; then
echo "Successfully deployed skill."
else
echo "Error - An error occured, see error above."
exit 1
fi
cd ..
echo -e "Warning - Please update the logos of the skill through the alexa skill interface, To deploy in the future please execute 'ask deploy'.\n"
echo -e "\nAdding skill id to test framework"
SKILL_ID=$(cat ${directory}/.ask/config | grep "skill_id" | awk '{print $2}' | cut -c 2- | rev | cut -c 3- | rev)
sed -e "s/\${SKILL_ID}/${SKILL_ID}/" $directory/lambda/custom/index.ts > $directory/lambda/custom/index.ts.tmp
mv $directory/lambda/custom/index.ts.tmp $directory/lambda/custom/index.ts
sed -e "s/\${SKILL_ID}/${SKILL_ID}/" $directory/lambda/custom/test/index.js > $directory/lambda/custom/test/index.js.tmp
mv $directory/lambda/custom/test/index.js.tmp $directory/lambda/custom/test/index.js
cd $directory
ask deploy
cd ..
echo -e "\nAs skill testing is disabled by default when a skill is made through the ask CLI, do you want me to turn testing on for the testing framework(Y/N): "
read answer
if [[ $answer = 'Y' || $answer = 'y' ]] ; then
echo "Please type in your username for AWS: "
read username
echo "Please type in your password: "
read password
node $directory/other/index.js "$username" "$password" "$SKILL_ID"
echo "Setup complete, goodbye"
else
echo "Setup complete, goodbye"
fi