Skip to content

Commit 8972269

Browse files
author
Rob McCauley
committed
testflow
1 parent 1d1c1c2 commit 8972269

File tree

10 files changed

+423
-1
lines changed

10 files changed

+423
-1
lines changed

aws/Amazon-DynamoDB/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#### Ingredients
2-
## Amazon-S3 <a id="title"></a>
2+
## Amazon-DynamoDB <a id="title"></a>
33

44
#### What you will learn
55

testing/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ If the test works, you should see a formatted JSON response similar to this:
3333
}
3434
```
3535

36+
#### TestFlow
37+
You can run a sequence of conversation events as a local test and view formatted results in your console window.
38+
[TestFlow](TestFlow/README.md#title)
39+
3640

3741
See also [tools](../tools#title)
3842

testing/TestFlow/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Testing <a id="title"></a>
2+
### TestFlow
3+
4+
You can run your skill code through a sequence of events to see how the conversation session works.
5+
6+
7+
8+
<hr />
9+
10+
Back to the [Home Page](../../README.md#title)
11+

testing/TestFlow/dialogs/default.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LaunchRequest
2+
AMAZON.HelpIntent
3+
AMAZON.CancelIntent
4+
AMAZON.StopIntent
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LaunchRequest
2+
StateRequestIntent usstate=Vermont
3+
StateRequestIntent usstate=California
4+
ISeeIntent animal=bear color=brown
5+
AMAZON.HelpIntent
6+
AMAZON.StopIntent
7+
MyNameIsIntent myName=
8+
MyNameIsIntent myName=Madeline
9+
StateRequestIntent usstate=Texas
10+
RecapIntent
11+
AMAZON.StopIntent
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
{
3+
"intents": [
4+
{
5+
"intent": "StateRequestIntent",
6+
"slots":[
7+
{
8+
"name":"usstate",
9+
"type":"AMAZON.US_STATE"
10+
}
11+
]
12+
},
13+
{
14+
"intent": "MyNameIsIntent",
15+
"slots":[
16+
{
17+
"name":"myName",
18+
"type":"AMAZON.US_FIRST_NAME"
19+
}
20+
]
21+
},
22+
{
23+
"intent": "RecapIntent"
24+
},
25+
26+
{
27+
"intent": "AMAZON.YesIntent"
28+
},
29+
{
30+
"intent": "AMAZON.NoIntent"
31+
},
32+
33+
{
34+
"intent": "AMAZON.HelpIntent"
35+
},
36+
{
37+
"intent": "AMAZON.StopIntent"
38+
},
39+
{
40+
"intent": "AMAZON.CancelIntent"
41+
}
42+
43+
]
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MyNameIsIntent my name is {myName}
2+
MyNameIsIntent call me {myName}
3+
4+
StateRequestIntent {usstate}
5+
StateRequestIntent describe {usstate}
6+
StateRequestIntent how about {usstate}
7+
StateRequestIntent go to {usstate}
8+
9+
RecapIntent recap
10+
RecapIntent summary
11+
RecapIntent what states are in my list

testing/TestFlow/src/index.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
var Alexa = require('alexa-sdk');
2+
3+
exports.handler = function(event, context, callback){
4+
5+
var alexa = Alexa.handler(event, context);
6+
// alexa.appId = "amzn1.echo-sdk-ams.app.8c97fc78-342a-4e4f-823b-e2f91e7f0000";
7+
console.log('console.log() status message from index.js');
8+
9+
alexa.registerHandlers(handlers);
10+
alexa.execute();
11+
12+
};
13+
14+
var handlers = {
15+
'LaunchRequest': function () {
16+
var say = 'Welcome to the Alexa skill!';
17+
this.emit(':ask', say, 'try again');
18+
},
19+
20+
'StateRequestIntent': function() {
21+
var say = '';
22+
23+
if (this.event.request.intent.slots.usstate) {
24+
var myState = this.event.request.intent.slots.usstate.value;
25+
26+
say = 'Okay great! You asked for ' + myState;
27+
28+
// create and store session attributes
29+
if (!this.attributes['myList']) {
30+
this.attributes['myList'] = []; // empty array
31+
}
32+
33+
this.attributes['myList'].push(myState); // add array element
34+
} else {
35+
say = 'I did not hear the name of the state.'
36+
}
37+
38+
this.emit(':ask', say, 'try again');
39+
40+
},
41+
'MyNameIsIntent': function() {
42+
43+
var myName = '';
44+
var say = '';
45+
46+
if (this.event.request.intent.slots.myName) {
47+
myName = this.event.request.intent.slots.myName.value;
48+
this.attributes['myName'] = myName;
49+
say = 'Hi ' + myName + '!';
50+
51+
} else {
52+
say = 'You can tell me your name, for example, you can say my name is Danielle.';
53+
}
54+
//this.event.request.intent.slots.myName.value;
55+
56+
this.emit(':ask', say, 'try again');
57+
},
58+
'ISeeIntent': function() {
59+
var say = '';
60+
61+
if (this.event.request.intent.slots.color && this.event.request.intent.slots.animal) {
62+
var myColor = this.event.request.intent.slots.color.value;
63+
var myAnimal = this.event.request.intent.slots.animal.value;
64+
65+
say = 'You saw a ' + myColor + ' ' + myAnimal;
66+
}
67+
68+
this.emit(':ask', say, 'try again');
69+
70+
},
71+
'RecapIntent': function() {
72+
73+
// create and store session attributes
74+
if (!this.attributes['myList']) {
75+
this.attributes['myList'] = []; // empty array
76+
}
77+
78+
var stateList = this.attributes['myList'].toString(); // add array element
79+
var stateCount = this.attributes['myList'].length;
80+
81+
var say = 'Your list has the following ' + stateCount + ' states. ' + stateList;
82+
83+
this.emit(':ask', say, 'try again');
84+
},
85+
86+
'AMAZON.HelpIntent': function () {
87+
this.emit(':ask', 'Say the name of a U.S. State, for example, say, go to Florida.', 'try again');
88+
},
89+
'AMAZON.CancelIntent': function () {
90+
this.emit(':tell', 'Goodbye');
91+
92+
},
93+
'AMAZON.StopIntent': function () {
94+
var say = '';
95+
var myName = '';
96+
if (this.attributes['myName'] ) {
97+
myName = this.attributes['myName'];
98+
}
99+
say = 'Goodbye, ' + myName;
100+
101+
this.emit(':tell', say );
102+
},
103+
'Unhandled': function() {
104+
105+
this.emit(':ask', 'Sorry, unhandled intent ' + JSON.stringify(this.event.request) + ' error. Try again?', 'Please try again?');
106+
107+
}
108+
};
109+
110+
// end of handlers
111+
112+
// --------------------------------------------------- User Defined Functions ---------------

testing/TestFlow/src/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "SkillStuff",
3+
"version": "1.0.0",
4+
"description": "TestFlow - Lambda function for Alexa",
5+
"readme": "Lambda function for Alexa",
6+
"repository": "my repository",
7+
"main": "index.js",
8+
"scripts": {
9+
"invoke": "aws lambda invoke --function-name 'TestFlow' --payload fileb://../tests/events/alexa-start-session.json ../tests/out.txt && cat ../tests/out.txt",
10+
"test": "node ../tests/test.js",
11+
"deploy": "npm run zip && npm run upload",
12+
"upload": "aws lambda update-function-code --function-name 'TestFlow' --zip-file fileb://../index.zip",
13+
"zip": "zip -r ../index.zip . -x 'package.json' -x '*.git*' "
14+
},
15+
"author": "me",
16+
"license": "Apache-2.0",
17+
"dependencies": {
18+
"alexa-sdk": "^1.0.7"
19+
}
20+
}

0 commit comments

Comments
 (0)