-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathFunction.cs
More file actions
350 lines (344 loc) · 10.9 KB
/
Function.cs
File metadata and controls
350 lines (344 loc) · 10.9 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
using Alexa.NET.Request;
using Alexa.NET.Request.Type;
using Alexa.NET.Response;
using Amazon.Lambda.Core;
using System;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace MachOneSoftware.FavoriteColor
{
public class Function
{
private const string HelpMessage = "Try asking for a color.";
private const string StopMessage = "Goodbye color seeker";
private const string Error_Unknown = "Sorry, something went wrong. Try asking for a color.";
private readonly string[] coolColors =
{
"Air Force Blue",
"Antique bronze",
"Alice Blue",
"Amaranth" ,
"Amazon Orange",
"American Rose",
"Android Green",
"Antique Brass",
"Antique Fuchsia",
"Antique White",
"Apple Green",
"Aqua",
"Aquamarine",
"Army Green",
"Arsenic",
"As Dark As My Soul Black",
"Azure",
"Baby Throw Up Green",
"Beige",
"Bisque",
"Black",
"Blanched Almond",
"Blue",
"Blue But Every Time It's Blue It Turns Green",
"Blue Violet",
"Bluish Green",
"Brown",
"Burlywood",
"Cadet Blue",
"Caput Mortuum",
"Carrot Parrot",
"Chartreuse",
"Chocolate",
"Cobalt",
"Communist Red",
"Coral",
"Cornflower Blue",
"Cornsilk",
"Corsica Red",
"Crimson",
"Cyan",
"Da Ba Dee Blue",
"Dark Blue",
"Dark Cyan",
"Dark Goldenrod",
"Dark Gray",
"Dark Green",
"Dark Grey",
"Dark Khaki",
"Dark Magenta",
"Dark OliveGreen",
"Dark Orange",
"Dark Orchid",
"Dark Red",
"Dark Salmon",
"Dark SeaGreen",
"Dark SlateBlue",
"Dark SlateGray",
"Dark Turquoise",
"Dark Violet",
"Deep Pink",
"Deep SkyBlue",
"Delorean Gray",
"Dim Grey",
"Dodger Blue",
"Dog Poop Brown",
"Eggplant",
"Electric Orange",
"Emoji Yellow",
"English Lavender",
"Falu Red",
"Firebrick Red",
"Flamingo",
"Floral White",
"Forest Green",
"French Blue",
"Fuchsia",
"Fuzzy Caterpillar Brown",
"Fuzzy Wuzzy Brown",
"Gainsboro",
"Gamboge Yellow",
"Ghost White",
"Gold",
"Goldenrod",
"Goth Black",
"Gray With An A.",
"Green",
"Green But It's We Are Number One",
"Green Dot Com",
"Green Yellow",
"Grey",
"Grey With An E.",
"Honeydew",
"Hot Pink",
"House Fly Black",
"I Guess That's Why They Call It The Blues Blue",
"Indian Red",
"Indigo",
"Ivory",
"Khaki",
"Kitty Cat Black",
"Kitty Cat Calico",
"Kitty Cat Orange",
"Kitty Cat Tortoiseshell",
"Lavender",
"Lavender Blush",
"Lawn Green",
"Lemon Chiffon",
"Libertarian Gold",
"Light Blue",
"Light Coral",
"Light Cyan",
"Light Goldenrod Yellow",
"Light Gray",
"Light Green",
"Light Grey",
"Light Olive green",
"Light Pink",
"Light Salmon",
"Light Sea Green",
"Light Sky Blue",
"Light Slate Gray",
"Light Steel Blue",
"Light Tomato Red",
"Light Yellow",
"Lime",
"Lime Green",
"Linen",
"Macaroon",
"Magenta",
"Malachite",
"Malachite Green",
"Maroon",
"Mauve",
"Medium Aquamarine",
"Medium Blue",
"Medium Orchid",
"Medium Purple",
"Medium Sea Green",
"Medium Slate Blue",
"Medium Spring Green",
"Medium Turquoise",
"Medium Violet Red",
"Midnight Blue",
"Mint Cream",
"Misty Rose",
"Moccasin",
"Navajo White",
"Navy",
"Nebraska Cornhusker Cream",
"Nebraska Cornhusker Scarlet",
"Neon Pink",
"Nomad Red",
"Oat",
"Old Lace",
"Olive",
"Olive Drab",
"Orange",
"Orange But It's All Star By Smash Mouth",
"Orange Is The New Black Black",
"Orange Red",
"Orchid",
"Pale Goldenrod",
"Pale Green",
"Pale Turquoise",
"Pale Violet Red",
"Papaya Whip",
"Peach Puff",
"Peru",
"Pink",
"Plum",
"Powder Blue",
"Purple",
"Purple Haze Purple",
"Purple Mountain Majesties Purple",
"Razzmatazz",
"Real Men Wear Pink Pink",
"Rebecca Purple",
"Red",
"Red Red Wine",
"Rocket's Red Glare Red",
"Rosy Brown",
"Royal Blue",
"Saddle Brown",
"Salmon",
"Sandy Brown",
"Savoy blue",
"Screaming Green",
"Sea Green",
"Seashell",
"Sepia" ,
"Sienna",
"Silver",
"Simpsons Yellow",
"Sky Blue",
"Slate Blue",
"Slate Gray",
"Snow",
"South Dakota Coyotes Red",
"South Dakota Coyotes White",
"Spanish Yellow",
"Spring Green",
"Steel Blue",
"Stupid Yellow",
"Tan",
"Teal",
"The Grass Is Greener On The Other Side Green",
"This Color Will Offend You, So I Won't Say It",
"Thistle",
"Tomato",
"Turquoise",
"Violet",
"Wheat",
"White",
"White Christmas White",
"White Smoke",
"Wine Red",
"Xanadu Green-Gray",
"Yellow",
"Yellow Green",
"peacock blue",
"crimson red",
"queen pink",
"cosmic latte",
"Azure blue",
"navy blue",
"Flamingo purple",
"Frost White",
"spring green",
"Fallow",
"maroon",
"baby pink",
"baby blue",
"blood red",
"peacock green",
"ocean blue",
"saffron",
"fuchsia pink",
"lime green",
"Midnight Blue",
"ultramarine",
"mountbatten pink",
"old rose",
"eggshell",
"tan",
"pale silver",
"Ford Performance Blue",
"melon yellow",
"Champagne",
"Apricot",
"Celadon"
};
public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
{
Shared.RequestId = context.AwsRequestId;
Shared.Logger = context.Logger;
var response = new SkillResponse()
{
Version = "1.0.0",
Response = new ResponseBody() { ShouldEndSession = true }
};
IOutputSpeech output = null;
try
{
var requestType = input.GetRequestType();
if (requestType == typeof(LaunchRequest))
response.Response.ShouldEndSession = HandleRandomColorIntent(out output);
else if (requestType == typeof(SessionEndedRequest))
output = Shared.GetOutput(StopMessage);
else if (requestType == typeof(IntentRequest))
{
var intentRequest = (IntentRequest)input.Request;
switch (intentRequest.Intent.Name)
{
case "AMAZON.CancelIntent":
output = Shared.GetOutput(StopMessage);
break;
case "AMAZON.StopIntent":
output = Shared.GetOutput(StopMessage);
break;
case "AMAZON.HelpIntent":
response.Response.ShouldEndSession = false;
output = Shared.GetOutput(HelpMessage);
break;
case "RandomColorIntent":
response.Response.ShouldEndSession = HandleRandomColorIntent(out output);
break;
default:
response.Response.ShouldEndSession = false;
output = Shared.GetOutput(HelpMessage);
break;
}
}
}
catch (Exception ex)
{
Shared.LogError("FunctionHandler", $"input = {input}; context = {context}", ex);
output = Shared.GetOutput(Error_Unknown);
response.Response.ShouldEndSession = false;
}
finally
{
response.Response.OutputSpeech = output;
}
return response;
}
/// <summary>
/// Handler for RandomColorIntent. Returns a value indicating whether to end the session. Returns the inner response as an out parameter.
/// </summary>
/// <param name="output">Response output speech.</param>
/// <returns></returns>
private bool HandleRandomColorIntent(out IOutputSpeech output)
{
try
{
var r = new Random((int)DateTime.Now.Ticks);
output = Shared.GetOutput(coolColors[r.Next(coolColors.Length)]);
return true;
}
catch (Exception ex)
{
Shared.LogError("HandleRandomColorIntent", "output", ex);
output = Shared.GetOutput(Error_Unknown);
return false;
}
}
}
}