Skip to content

Commit 07976ef

Browse files
author
Rob McCauley
committed
new labs
1 parent 3bcf753 commit 07976ef

File tree

14 files changed

+449
-7
lines changed

14 files changed

+449
-7
lines changed

aws/Amazon-DynamoDB/read/tests/webapp/magic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<script>
1010

11-
const REGION = 'eu-west-1';
12-
var cognitoIdentityPoolId = 'eu-west-1:819bc82c-9b43-40fa-b216-a9d8e4b6d592';
11+
const REGION = 'us-east-1';
12+
var cognitoIdentityPoolId = 'us-east-1:583dd84a-7792-49a6-9ce5-5624f80378e7';
1313

1414
var docClient;
1515

handling-responses/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Alexa skill developers can take advantage of functions to prepare effective spee
99
* [random-phrase](random-phrase#title), to generate a random phrase from a list
1010
* [say-array](say-array#title), to read a list of items with the word "and" or "or" before the last item
1111
* [ssml-audio](ssml-audio#title), to include sound clips and long pauses
12-
12+
* [ssml-speechcons](ssml-speechcons#title), to make Alexa speak with extra emphasis
13+
* [slot-value-check](slot-value-check#title), to verify a user included a slot value in their utterance
14+
* [dialog-directive-delegate](dialog-directive-delegate#title), to explore the new Skill Builder tool.
1315

1416

1517
<hr />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#### Ingredients
2+
## slot-value-check <a id="title"></a>
3+
<hr />
4+
5+
6+
#### What you will learn
7+
8+
Users may not say everything you expect. They may just say "my name is".
9+
We can use a function that returns either null, or the value of the slot.
10+
11+
For example, if you had set slotName = "FirstName", you could check it via:
12+
13+
```js
14+
var slotValue = isSlotValid(this.event.request, slotName); //slot value or false
15+
if (slotValue) { } else { }
16+
```
17+
18+
#### Instructions for deploying this sample skill
19+
20+
1. Create a new AWS Lambda function using the fact blueprint.
21+
1. Delete the code, replace with [index.js](index.js)
22+
1. Locate and Copy the AWS Lambda ARN for the new function.
23+
1. Create a skill with a slot called Item
24+
1. On the Configuration page, paste in your Lambda ARN as the endpoint.
25+
1. Test your skill, both with and without saying slot words.
26+
27+
* Copy the ```isSlotValid()``` helper function to use in your code.
28+
29+
<hr />
30+
31+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// alexa-cookbook sample code
2+
3+
// There are three sections, Text Strings, Skill Code, and Helper Function(s).
4+
// You can copy and paste the entire file contents as the code for a new Lambda function,
5+
// or copy & paste section #3, the helper function, to the bottom of your existing Lambda code.
6+
7+
8+
// 1. Text strings =====================================================================================================
9+
// Modify these strings and messages to change the behavior of your Lambda function
10+
11+
// from the lambda, choose Action > Configure Test Event > Alexa Intent - Recipe
12+
var slotName = "Item";
13+
14+
15+
// 2. Skill Code =======================================================================================================
16+
17+
var Alexa = require('alexa-sdk');
18+
19+
exports.handler = function(event, context, callback) {
20+
var alexa = Alexa.handler(event, context);
21+
// alexa.appId = 'amzn1.echo-sdk-ams.app.1234';
22+
// alexa.dynamoDBTableName = 'YourTableName'; // creates new table for session.attributes
23+
alexa.registerHandlers(handlers);
24+
alexa.execute();
25+
};
26+
27+
var handlers = {
28+
'LaunchRequest': function () {
29+
this.emit(':ask', "try saying an utterance with a slot value to test this.");
30+
},
31+
'Unhandled': function () {
32+
var speechOutput;
33+
var intent = this.event.request.intent.name;
34+
35+
var slotValue = isSlotValid(this.event.request, slotName); //slot value or false
36+
if (slotValue) {
37+
//slot has a valid value
38+
speechOutput="Intent " + intent + ", slot " + slotName + ", is " + slotValue;
39+
} else {
40+
//no valid slot
41+
speechOutput="Intent " + intent + ", did not get a value for " + slotName;
42+
}
43+
this.emit(':tell', speechOutput);
44+
}
45+
};
46+
47+
48+
// END of Intent Handlers {} ========================================================================================
49+
// 3. Helper Function =================================================================================================
50+
51+
52+
function isSlotValid(request, slotName){
53+
var slot = request.intent.slots[slotName];
54+
//console.log("request = "+JSON.stringify(request)); //uncomment if you want to see the request
55+
var slotValue;
56+
57+
//if we have a slot, get the text and store it into speechOutput
58+
if (slot && slot.value) {
59+
//we have a value in the slot
60+
slotValue = slot.value.toLowerCase();
61+
return slotValue;
62+
} else {
63+
//we didn't get a value in the slot.
64+
return false;
65+
}
66+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#### Ingredients
2+
## ssml-speechcons <a id="title"></a>
3+
<hr />
4+
5+
6+
#### What you will learn
7+
This ingredient shows how to add special emphasis to key phrases within your speech output response.
8+
9+
```js
10+
var speechOutput = "aha, this is a phrase with speechcons, well done.";
11+
12+
console.log(addSpeehconSSML(speechOutput)); // includes ssml tags
13+
14+
// <say-as interpret-as="interjection"> aha </say-as>
15+
16+
```
17+
18+
#### Instructions for deploying this sample skill
19+
20+
1. Create a new AWS Lambda function using the fact blueprint.
21+
1. Delete the code, replace with [index.js](index.js)
22+
1. Locate and Copy the AWS Lambda ARN for the new function.
23+
1. Create a skill such as Hello World.
24+
1. On the Configuration page, paste in your Lambda ARN as the endpoint.
25+
1. Test your skill by listening for the ssml response.
26+
27+
* Copy the ```addSpeehconSSML()``` helper function to use in your code.
28+
29+
<hr />
30+
31+
32+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// alexa-cookbook sample code
2+
3+
// There are three sections, Text Strings, Skill Code, and Helper Function(s).
4+
// You can copy and paste the entire file contents as the code for a new Lambda function,
5+
// or copy & paste section #3, the helper function, to the bottom of your existing Lambda code.
6+
7+
8+
// 1. Text strings =====================================================================================================
9+
// Modify these strings and messages to change the behavior of your Lambda function
10+
11+
var speechOutput = "aha, this is a phrase with speechcons, well done."; // Array of items
12+
13+
// 2. Skill Code =======================================================================================================
14+
15+
16+
var Alexa = require('alexa-sdk');
17+
18+
exports.handler = function(event, context, callback) {
19+
var alexa = Alexa.handler(event, context);
20+
// alexa.appId = 'amzn1.echo-sdk-ams.app.1234';
21+
// alexa.dynamoDBTableName = 'YourTableName'; // creates new table for session.attributes
22+
alexa.registerHandlers(handlers);
23+
alexa.execute();
24+
};
25+
26+
var handlers = {
27+
'LaunchRequest': function () {
28+
//add SSML tags to any speechcons in the string
29+
speechOutput=addSpeehconSSML(speechOutput);
30+
this.emit(':tell', speechOutput);
31+
},
32+
'Unhandled': function () {
33+
this.emit('LaunchRequest');
34+
}
35+
};
36+
37+
// END of Intent Handlers {} ========================================================================================
38+
// 3. Helper Function =================================================================================================
39+
40+
41+
function addSpeehconSSML (text) {
42+
//if the text contains a speechcon, add the proper SMML around the speechcon
43+
speechcons.forEach(function(element){
44+
var elementWithSSML=',<say-as interpret-as="interjection">'+element+'</say-as>,';
45+
text = text.replace(element,elementWithSSML);
46+
});
47+
console.log(text);
48+
return text;
49+
}
50+
51+
//list of valid speechcons
52+
var speechcons = ["abracadabra","achoo","aha","ahem","ahoy","all righty","aloha",
53+
"aooga","argh","arrivederci","as you wish","au revoir","aw man","baa",
54+
"bada bing bada boom","bah humbug","bam","bang","batter up","bazinga",
55+
"beep beep","bingo","blah","blarg","blast","boing","bon appetit","bonjour",
56+
"bon voyage","boo","boo hoo","boom","booya","bravo","bummer","caw","cha ching",
57+
"checkmate","cheerio","cheers","cheer up","chirp","choo choo","clank",
58+
"click clack","cock a doodle doo","coo","cowabunga","darn","ding dong","ditto",
59+
"d’oh","dot dot dot","duh","dum","dun dun dun","dynomite","eek","eep",
60+
"encore","en gard","eureka","fancy that","geronimo","giddy up","good grief",
61+
"good luck","good riddance","gotcha","great scott","heads up","hear hear",
62+
"hip hip hooray","hiss","honk","howdy","hurrah","hurray","huzzah","jeepers creepers",
63+
"jiminy cricket","jinx","just kidding","kaboom","kablam","kaching","kapow",
64+
"katchow","kazaam","kerbam","kerboom","kerching","kerchoo","kerflop",
65+
"kerplop","kerplunk","kerpow","kersplat","kerthump","knock knock","le sigh",
66+
"look out","mamma mia","man overboard","mazel tov","meow","merci","moo",
67+
"nanu nanu","neener neener","no way","now now","oh boy","oh brother","oh dear",
68+
"oh my","oh snap","oink","okey dokey","oof","ooh la la","open sesame","ouch",
69+
"oy","phew","phooey","ping","plop","poof","pop","pow","quack","read ‘em and weep",
70+
"ribbit","righto","roger","ruh roh","shucks","splash","spoiler alert","squee",
71+
"swish","swoosh","ta da","ta ta","tee hee","there there","thump","tick tick tick",
72+
"tick-tock","touche","tsk tsk","tweet","uh huh","uh oh","voila","vroom",
73+
"wahoo","wah wah","watch out","way to go","well done","well well","wham",
74+
"whammo","whee","whew","woof","whoops a daisy","whoosh","woo hoo","wow",
75+
"wowza","wowzer","yadda yadda yadda","yay","yikes","yippee","yoink","yoo hoo",
76+
"you bet","yowza","yowzer","yuck","yum","zap","zing","zoinks",];

labs/FactService/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#### Alexa Cookbook
2+
## Fact Service Tutorial <a id="title"></a>
3+
<hr />
4+
5+
### Intro <a id="intro"></a>
6+
7+
This is a set of tutorial steps on how to add features to an Alexa skill.
8+
9+
10+
### Tutorial Steps
11+
We will start by installing the most basic of skills and then follow the labs to learn how to extend the skill.
12+
We will begin with a code template called ```alexa-skill-kit-sdk-factskill```,
13+
however we will replace this code with our starting code so that we see how a fact skill can be created from the ground up.
14+
15+
16+
#### Code
17+
1. Login to AWS and verify the region at the top right is set to the **Ireland** or **N. Virginia** Region region.
18+
1. Click [Lambda](https://console.aws.amazon.com/lambda/home) and then **Create a Lambda function** Do not select the default **Blank** blueprint.
19+
1. Locate and click on the ```alexa-skill-kit-sdk-factskill``` skill template (hint: search for **fact** )
20+
1. Click in the empty square and choose the trigger *Alexa Skills Kit* and click Next.
21+
1. Give your function the name *FactService*
22+
1. Paste in the source code from [src/index.js](./src/index.js) :
23+
24+
```
25+
var Alexa = require('alexa-sdk');
26+
27+
exports.handler = function(event, context, callback) {
28+
var alexa = Alexa.handler(event, context);
29+
30+
// alexa.dynamoDBTableName = 'YourTableName'; // creates new table for userid:session.attributes
31+
32+
alexa.registerHandlers(handlers);
33+
alexa.execute();
34+
};
35+
36+
var handlers = {
37+
'LaunchRequest': function () {
38+
this.emit('MyIntent');
39+
},
40+
41+
'GetNewFactIntent': function () {
42+
this.emit(':tell', 'You can build new voice experiences with the Alexa Skills Kit!');
43+
}
44+
};
45+
```
46+
47+
1. Just below the code editor, create or re-use an execution role, such as ```lambda_basic_execution```
48+
1. Click Next and create the function.
49+
1. Make note of the Lambda ARN, shown near the top right, such as
50+
* ``` arn:aws:lambda:us-east-1:333304287777:function:FactService ```
51+
52+
53+
#### Skill
54+
1. Login to [developer.amazon.com](https://developer.amazon.com) and click Alexa, then Alexa Skills Kit
55+
1. Create a new Skill called ```Fact Service``` with invocation name ```fact service```.
56+
1. Paste in the [IntentSchema.json](./speechAssets/IntentSchema.json) :
57+
58+
```
59+
{
60+
"intents": [
61+
{
62+
"intent": "GetNewFactIntent", "slots":[]
63+
},
64+
65+
{
66+
"intent": "AMAZON.HelpIntent"
67+
},
68+
{
69+
"intent": "AMAZON.StopIntent"
70+
},
71+
{
72+
"intent": "AMAZON.CancelIntent"
73+
}
74+
]
75+
}
76+
77+
```
78+
79+
1. Paste in the [SampleUtterances.txt](speechAssets/SampleUtterances.txt) :
80+
81+
```
82+
GetNewFactIntent tell me a fact
83+
GetNewFactIntent give me a fact
84+
GetNewFactIntent tell me something
85+
```
86+
87+
1. Configure the skill endpoint with the AWS Lambda ARN previously created.
88+
89+
#### Test
90+
* Type or say "open fact service" and Alexa should reply with "You can build new voice experiences with the Alexa Skills Kit"
91+
* Modify code within the Lambda function editor to have Alexa say something besides this phrase. Click the blue ```Save``` button.
92+
* Test and hear Alexa say the new response.
93+
94+
95+
# Labs <a id="labs"></a>
96+
97+
## Lab 1 - Fact List
98+
99+
This lab will show you how to define a list of facts instead of a single fact, and have Alexa pick a random fact to tell the user.
100+
101+
Take a look at the ```// helper functions``` section of code at the bottom of your Lambda code:
102+
103+
```javascript
104+
function getFact() {
105+
var newFact = 'You can build new voice experiences with the Alexa Skills Kit';
106+
return newFact;
107+
}
108+
109+
```
110+
111+
We will enhance our getFact() function with the following:
112+
1. Define an array of facts called **myFacts**. An array is just a list of values, enclosed in square brackets [].
113+
1. Add add in a call to a new helper function called ```randomPhrase()``` to help us pick a random value from the array.
114+
115+
#### Steps
116+
117+
Delete the ```getFact()``` function and replace with the following two functions:
118+
119+
```
120+
function getFact() {
121+
var myFacts = ['Pandas live for about 20 years.','Pandas are native to China.','Pandas eat bamboo.']
122+
123+
var newFact = randomPhrase(myFacts);
124+
125+
return newFact;
126+
}
127+
128+
function randomPhrase(array) {
129+
// the argument is an array [] of words or phrases
130+
var i = 0;
131+
i = Math.floor(Math.random() * array.length);
132+
return(array[i]);
133+
}
134+
```
135+
136+
#### Test
137+
* Type or say "open fact service" and Alexa should reply with one of the facts in your array.
138+
* Modify code within the Lambda function editor to change the fact array to your own custom facts. For example, you could define facts about your hometown. Click the blue ```Save``` button.
139+
* Test and hear Alexa say one of your facts.
140+
141+
## Lab 2 - Handle Help, Stop, Cancel
142+
143+
Within your lambda code, *un-comment* out the three lines that handle the standard Alexa intents.
144+
Hint: locate the // characters and remove them.
145+
Review and modify the response messages for each intent, if desired.
146+
147+
* AMAZON.HelpIntent
148+
* AMAZON.CancelIntent
149+
* AMAZON.StopIntent
150+
151+
You can now submit your skill for publication! See this [guide on the publishing process](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/publishing-an-alexa-skill).
152+
153+
<hr/>
154+
155+
[Back](../../README.md#title) - [Cookbook Home Page](../../README.md#title)
156+

0 commit comments

Comments
 (0)