-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathalexa.html
440 lines (404 loc) · 16.1 KB
/
alexa.html
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
<script type="text/x-red" data-template-name="alexa-skill">
<div class="form-row">
<ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="alexa-skill-config-tabs"></ul>
</div>
<div id="alexa-skill-config-tabs-content" style="min-height: 170px;">
<div id="alexa-skill-config-tabs-setup" style="display:none">
<div class="form-row">
<label for="node-input-skillname"><i class="fa fa-tag"></i> <span data-i18n="alexa-skill-config.label.skillname"></span></label>
<input type="text" id="node-config-input-skillname" data-i18n="[placeholder]alexa-skill-config.placeholder.skillname" />
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-intents"><i class="fa fa-wrench"></i> <span data-i18n="alexa-skill-config.label.intents"></span></label>
</div>
<div class="form-row node-intents-editor-row">
<div style="height: 200px;" class="node-text-editor" id="node-input-intents-editor" ></div>
</div>
<div class="form-row">
<div class="form-tips" data-i18n="[html]alexa-skill-config.tip.intents" style="max-width:575px;"></div>
</div>
</div>
<div id="alexa-skill-config-tabs-account-linking" style="display:none">
<div class="form-row">
<label for="node-config-input-clientId"><i class="fa fa-user"></i> Client Id</label>
</div>
</div>
<div id="alexa-skill-config-tabs-skill" style="display:none">
<div class="form-row">
<label for="node-skill-endpoint"><i class="fa fa-user"></i> Endpoint</label>
<input type="text" id="node-skill-endpoint" disabled="disabled" />
<div class="form-tips" data-i18n="[html]alexa-skill-config.tip.endpoint" style="max-width:575px;"></div>
</div>
<div class="form-row">
<label for="node-schema"><i class="fa fa-user"></i> Schema</label>
</div>
<div class="form-row">
<textarea id="node-schema" rows="4" cols="110" style="width:550px;"></textarea>
</div>
<div class="form-row">
<label for="node-utterances"><i class="fa fa-user"></i> Utterances</label>
</div>
<div class="form-row">
<textarea id="node-utterances" rows="4" cols="110" style="width:550px;"></textarea>
</div>
</div>
</div>
<input type="hidden" id="node-config-input-intents" autofocus="autofocus">
</script>
<script type="text/javascript">
var defaultIntents = JSON.stringify([{name: "SampleIntent",options: { slots:{NAME:"LITERAL",AGE:"NUMBER"}, utterances:[ "my {name is|name's} {names|NAME} and {I am|I'm} {1-100|AGE}{ years old|}"]}}], null, 2);
RED.nodes.registerType('alexa-skill',{
category: 'config',
defaults: {
skillname: {value:"",required:true},
intents: {required:true, value:defaultIntents},
redirectUrl: {value:""},
clientId: {value:"needsADefault", required:true}
},
label: function() {
return this.skillname;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this;
var tabs = RED.tabs.create({
id: "alexa-skill-config-tabs",
onchange: function(tab) {
$("#alexa-skill-config-tabs-content").children().hide();
$("#" + tab.id).show();
if(tab.id === "alexa-skill-config-tabs-skill"){
var data = {skillname:$("#node-config-input-skillname").val()};
data.intents = node.intentsEditor.getValue();
$.post('/alexa/format-intents', data, function(response) {
$("#node-schema").val(response.schema);
$("#node-utterances").val(response.utterances);
}, 'json');
}
}
});
tabs.addTab({
id: "alexa-skill-config-tabs-setup",
label: this._("alexa-skill-config.label.setup")
});
tabs.addTab({
id: "alexa-skill-config-tabs-account-linking",
label: this._("alexa-skill-config.label.account-linking")
});
tabs.addTab({
id: "alexa-skill-config-tabs-skill",
label: this._("alexa-skill-config.label.skill")
});
setTimeout(function() { tabs.resize()},0);
this.intentsEditor = RED.editor.createEditor({
id: 'node-input-intents-editor',
mode: 'ace/mode/json',
value: $("#node-config-input-intents").val()
});
var reg_url = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
var path = reg_url + "/" + node.id+'/alexa';
$("#node-skill-endpoint").val(path);
},
oneditsave: function(){
$("#node-config-input-intents").val(this.intentsEditor.getValue());
this.intents = this.intentsEditor.getValue()
delete this.intentsEditor;
}
});
</script>
<script type="text/x-red" data-template-name="alexa-http launch">
<div class="form-row">
<label for="node-input-skillConfig"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.skill"></span></label>
<input type="text" id="node-input-skillConfig" />
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.name"></span></label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-http launch">
<p>This node receives a LaunchRequest when the user invokes the skill with the invocation name, but does not provide any command mapping to an intent.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-http launch',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
skillConfig: {type:"alexa-skill", required:true}
},
inputs:0,
outputs:1,
icon: "alexa.png",
label: function() {
if(this.name){
return this.name;
}else if(this.skillConfig){
var config = RED.nodes.node(this.skillConfig);
return config.skillname + " Launch";
}else{
return "Alexa Launch";
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
paletteLabel: function() {
return "Alexa Launch";
},
oneditprepare: function() {
}
});
</script>
<script type="text/x-red" data-template-name="alexa-http intent">
<div class="form-row">
<label for="node-input-skillConfig"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.skill"></span></label>
<input type="text" id="node-input-skillConfig" />
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.name"></span></label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-http intent">
<p>This node receives an IntentRequest when the user speaks a command that maps to an intent. The request object sent to your service includes the specific intent and any defined slot values.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-http intent',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
skillConfig: {type:"alexa-skill", required:true},
url: {value:"/alexa_test",required:true},
},
inputs:0,
outputs:1,
icon: "alexa.png",
label: function() {
if(this.name){
return this.name;
}else if(this.skillConfig){
var config = RED.nodes.node(this.skillConfig);
return config.skillname + " Intent";
}else{
return "Intent Request";
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
paletteLabel: function() {
return "Intent Request";
},
oneditprepare: function() {
}
});
</script>
<script type="text/x-red" data-template-name="alexa-http session-end">
<div class="form-row">
<label for="node-input-skillConfig"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.skill"></span></label>
<input type="text" id="node-input-skillConfig" />
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="alexa-httpin.label.name"></span></label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-http session-end">
<p>Your service receives a SessionEndedRequest when a currently open session is closed</p>
<p>Possible reasons for closure:
<ol>
<li>The user says "exit"</li>
<li>The user does not respond or says something that does not match an intent</li>
<li>An error occurs</li>
</ol>
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-http session-end',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
skillConfig: {type:"alexa-skill", required:true}
},
inputs:0,
outputs:1,
icon: "alexa.png",
label: function() {
if(this.name){
return this.name;
}else if(this.skillConfig){
var config = RED.nodes.node(this.skillConfig);
return config.skillname + " SessionEnd";
}else{
return "SessionEnd Request";
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
paletteLabel: function() {
return "SessionEnd Request";
},
oneditprepare: function() {
}
});
</script>
<script type="text/x-red" data-template-name="alexa-say">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-row">
<label for="node-input-text"><i class="fa fa-tag"></i> Text</label>
<input type="text" id="node-input-text" data-i18n="[placeholder]common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-say">
<p>Tell Alexa to say something. Can use multiple say nodes and the phrases will be appended to each other</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-say',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
text: {value:"", required:true}
},
inputs:1,
outputs:1,
icon: "alexa.png",
label: function() {
return this.name || "Say"
},
paletteLabel: function() {
return "Say";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
}
});
</script>
<script type="text/x-red" data-template-name="alexa-card">
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-cardjson"><i class="fa fa-wrench"></i> <span data-i18n="alexa-card.label.object"></span></label>
<input type="hidden" id="node-input-cardjson" autofocus="autofocus">
</div>
<div class="form-row node-text-editor-row">
<div style="height: 200px;" class="node-text-editor" id="node-input-card-editor" ></div>
</div>
<div class="form-row">
<div class="form-tips" data-i18n="[html]alexa-card.tip"></div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="alexa-card.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]alexa-card.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-card">
<p>Adds a card to the users Alexa app </p>
<p>
For Object definition see <a href="https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference#card-object" target="_blank">developer.amazon.com</a></p>
</script>
<script type="text/javascript">
var defaultCard = JSON.stringify({type: "Simple", title: "My Simple Title", content: "My very simple content"}, null, 2);
RED.nodes.registerType('alexa-card',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
cardjson: {value:defaultCard, require:true}
},
inputs:1,
outputs:1,
icon: "alexa.png",
label: function() {
return this.name || "Card"
},
paletteLabel: function() {
return "Card";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
this.editor = RED.editor.createEditor({
id: 'node-input-card-editor',
mode: 'ace/mode/json',
value: $("#node-input-cardjson").val()
});
},
oneditsave: function(){
$("#node-input-cardjson").val(this.editor.getValue());
delete this.editor;
}
});
</script>
<script type="text/x-red" data-template-name="alexa-link-account">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-link-account">
<p>Adds a card to the response instructing the user how to link their account to the skill.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-link-account',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""}
},
inputs:1,
outputs:1,
icon: "alexa.png",
label: function() {
return this.name || "Link Account"
},
paletteLabel: function() {
return "Link Account";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/x-red" data-template-name="alexa-http response">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name" />
</div>
</script>
<script type="text/x-red" data-help-name="alexa-http response">
<p>Completes a response from an alexa request. Required for any Launch, Intent or SessionEnd request.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-http response',{
category: 'alexa',
color:"#96d5e3",
defaults: {
name: {value:""},
},
inputs:1,
outputs:0,
icon: "alexa.png",
align: "right",
label: function() {
return this.name || "Alexa Response"
},
paletteLabel: function() {
return "Alexa Response";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
}
});
</script>