Skip to content

Commit 2e99d9a

Browse files
committed
Adding Readme for Module 1, and updating screenshots for Python
1 parent b89bfc1 commit 2e99d9a

4 files changed

Lines changed: 182 additions & 15 deletions

File tree

‎module-1/README.md‎

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
## Introduction
2+
In this module, you will build Cake Walk, a simple skill that asks the user for their birthday, remembers it, tells them how many days until their next birthday, and wishes them Happy Birthday on their birthday.
3+
* asks the user for their birthday
4+
* remembers it
5+
* tells them how many days until their next birthday
6+
* wishes them Happy Birthday on their birthday
7+
In “Why develop skills with Alexa?” You saw what happens when a user interacts with a simple skill called “Hello World”. In the video below, let’s take a look at how users will interact with Cake Walk once you’ve built it:
8+
9+
As you can see the skill is simple to use yet a bit complex to build. The burden is on us, the skill builder, to make the interaction simple and natural. One way to make it as natural as possible is to mimic human conversational patterns. Humans have memory so your skill should too. It would be frustrating if your best friend always had to ask your name (which may be a sign that they really aren’t your best friend at all). While you could build cake walk in a day, because of its complexity you’ll build cake walk over four modules in this course.
10+
11+
Once you’ve completed this course; you’ll have built a skill that is useful, simple, and sticky. Useful skills provide value to users. For this skill Cake Walk is fun and useful to users by celebrating their birthday with a count down. Cake Walk is also a great example of a sticky skill, which retains the user’s interest and inspires them to keep coming back. Cake Walk encourages our user to keep checking in until their special day. Let’s get started!
12+
13+
### About this module
14+
If this is your first time building an Alexa skill, we recommend completing this module and the next three, which walk you through all the necessary steps.
15+
Don’t worry if you get stuck along the way or if your code breaks. At the end of each module, the complete working code solution is provided for you under the **Code** heading.
16+
If you’re already up to speed on the fundamentals of Alexa skill building and want to make your skill more conversational, please take a look at the [conversational design course](http://alexa.design/cdw) .
17+
18+
### Features covered
19+
* Utterances
20+
* Intents
21+
* Slots
22+
* Dialog management
23+
* Memory and persistence
24+
* User profile settings
25+
26+
## Step 1: Log in
27+
To get started, log into the [Alexa developer console](https://developer.amazon.com/alexa/console/ask) with your Amazon Developer account. If you do not have an account, [click here](https://www.amazon.com/ap/register?clientContext=131-0331464-9465436&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&siteState=clientContext%3D142-6935021-1894360%2CsourceUrl%3Dhttps%253A%252F%252Fdeveloper.amazon.com%252Falexa%2Csignature%3Doyixlki7Yxz8bRUtt4vGJ4EugQ8j3D&marketPlaceId=ATVPDKIKX0DER&language=en_US&pageId=amzn_developer_portal&openid.return_to=https%3A%2F%2Fdeveloper.amazon.com%2Falexa&prevRID=HSRBQ1KHA4E5D1PBHPPP&openid.assoc_handle=mas_dev_portal&openid.mode=checkid_setup&prepopulatedLoginId=&failedSignInCount=0&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0) to create one.
28+
29+
30+
## Step 2: Create your skill
31+
32+
**a.** Click **Create Skill** on the right-hand side of the console. A new page displays.
33+
34+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-2a.png)
35+
36+
37+
**b.** In the **Skill name** field, enter **Cake Walk**.
38+
39+
**c.** Leave the **Default language** set to **English (US)**.
40+
41+
**d.** You are building a custom skill. Under **Choose a model to add to your skill**, select **Custom**.
42+
43+
![](http://alexa-github.s3.amazonaws.com/skill-name-custom.png)
44+
45+
> **Skills have a front end and backend. The front end is where you map utterances (what the user says) into an intent (the desired action). You must decide how to handle the user’s intent in the backend. Host the skill yourself using an function or HTTPS endpoint, or choose Alexa to host the skill for you. There are limits to the AWS Free Tier, so if your skill goes viral, you may want to move to the self-hosted option. For this course, choose Alexa-Hosted (Python).**
46+
47+
**e.** Under **Choose a method to host your skill’s backend resources**, select **Alexa-Hosted (Python)**.
48+
49+
![](http://alexa-github.s3.amazonaws.com/alexa-hosted-python.png)
50+
51+
**f.** At the top of the page, click **Create skill**.
52+
53+
![](http://alexa-github.s3.amazonaws.com/create-skill-button.png)
54+
55+
> **It takes a few moments for AWS to provision resources for your skill. When this process completes, move to the next section.**
56+
57+
>![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-2f-2.png)
58+
59+
> **Note: When you exit and return to the Alexa developer console, find your skill on the Skills tab, in the Alexa Skills list. Click Edit to continue working on your skill.**
60+
61+
> ![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-2f-3.png)
62+
63+
## Step 3: Greet the user
64+
The first thing a user will want to do with the skill is open it. The intent of opening the skill is built into the experience, so you don’t need to define this intent in your front end.
65+
66+
However, you need to respond to the intent in your backend. In this step, you will update your backend code to greet the user when they open the skill.
67+
68+
**a.** Open the Cake Walk skill in the Alexa developer console. Click the Code tab. The code editor opens the lambda_function.py file.
69+
70+
![](http://alexa-github.s3.amazonaws.com/python-code-tab.png)
71+
72+
_To define how your skill responds to a JSON request, you will define a handler for each intent._
73+
74+
There are two pieces to a handler:
75+
* **can_handle()** function
76+
* **handle()** function
77+
The **can_handle()** function is where you define what requests the handler responds to. The **handle()** function returns a response to the user.
78+
If your skill receives a request, the **can_handle()** function within each handler determines whether or not that handler can service the request.
79+
In this case, the user wants to launch the skill, which is a **LaunchRequest**. Therefore, the **can_handle()** function within the **LaunchRequestHandler** will let the SDK know it can fulfill the request. In computer terms, the **can_handle** returns _true_ to confirm it can do the work.
80+
81+
> **Tip:** In the code editor, search for text by pressing **CTRL+F** (**Command+F** on a Mac). A search window opens. This is helpful for searching for pieces of code within the editor.
82+
>
83+
What should happen when a user launches the Cake Walk skill? In this case, you want the skill to simply confirm that the user opened it by saying, "Hello! Welcome to Cake Walk. That was a piece of cake! Bye!"
84+
Within the **LaunchRequestHandler** object, find the **handle()** function. This function uses the **responseBuilder** function to compose and return the response to the user.
85+
86+
Within the **handle()** function, find the line that begins **speak_output =**. This variable contains the string of words the skill should say back to the user when they launch the skill. Let’s change what it says to make sense for this skill.
87+
88+
**b.** Within the **LaunchRequestHandler** object, find the **handle()** function, and the line that begins **speak_output =**. Replace that line with the following:
89+
90+
```python
91+
speak_output = "Hello! Welcome to cake walk. That was a piece of cake! Bye!"
92+
```
93+
94+
> **If you are not familiar with programming, a string is encapsulated in single or double quotation marks. To change a string’s text, replace the text within the quotation marks.**
95+
>
96+
> **When you replace existing text or add new text to the code, blank lines may be introduced just before or after the text. Blank lines will not impact the code, but you may remove them.**
97+
>
98+
> **You may also notice your lines of code are not indented the same as code snippets in this course. This will also not impact the code, but you can use the TAB key to indent code if you would like.**
99+
100+
Within the **LaunchRequestHandler**, on the line under the speech text you just replaced, look for **handlerInput.responseBuilder**. This piece of the SDK will help build the response to the user.
101+
102+
On the next line, look for **.speak(speak_output)**. Note the **speak_output** variable, which you defined earlier. Calling the **.speak()** function tells **responseBuilder** to speak the value of **speak_output** to the user.
103+
104+
Next, look for the **.ask()** function within **responseBuilder**. (Be sure you are looking in the **LaunchRequestHandler**, within the **handle()** function.)
105+
If the skill was supposed to listen for the user’s response, you would use this. In this case, you want the skill to speak and then exit. Therefore, let’s omit this line of code for now.
106+
107+
**c.** Within the **LaunchRequestHandler**, in the **handle()** function, find the line that begins **.ask()**. Add a **#** at the beginning of the line. This turns the line into a comment, meaning the line is ignored when the code runs.
108+
109+
**d.** Next, look for the **.response()** function just below the line you commented out in the **LaunchRequestHandler**. This converts the **responseBuilder’s** work into the response that the skill will return. Remember the line that started with return? Think of it like hitting the Send button—it sends the response.
110+
111+
Your **LaunchRequestHandler** should now look like:
112+
113+
```python
114+
class LaunchRequestHandler(AbstractRequestHandler):
115+
"""Handler for Skill Launch."""
116+
def can_handle(self, handler_input):
117+
# type: (HandlerInput) -> bool
118+
119+
return ask_utils.is_request_type("LaunchRequest")(handler_input)
120+
121+
def handle(self, handler_input):
122+
# type: (HandlerInput) -> Response
123+
speak_output = "Hello! Welcome to cake walk. That was a piece of cake! Bye!"
124+
125+
return (
126+
handler_input.response_builder
127+
.speak(speak_output)
128+
#.ask(speak_output)
129+
.response
130+
)
131+
```
132+
You have built the code that will handle a LaunchRequest for this skill. Before doing anything else, save your changes and deploy the code.
133+
134+
**e.** Click **Save**.
135+
136+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-3-save.png)
137+
138+
**f.** Click **Deploy**.
139+
140+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-3-deploy.png)
141+
142+
## Step 4: Test your skill
143+
Now it is time to test the skill. Start by activating the test simulator.
144+
145+
**a.** Click the **Test** tab. The test simulator opens.
146+
147+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-4-1.jpg)
148+
149+
An alert may appear requesting to use your computer’s microphone. Click **Allow** to enable testing the skill with your voice, just like if you were talking to an Alexa-enabled device.
150+
151+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-4-2.png)
152+
153+
**b.** From the drop-down menu at the top left of the page, select **Development**.
154+
155+
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/3/building-a-skill-4-3.png)
156+
157+
# Testing inside the developer console
158+
There are two ways to test your skill in the console. With the first method, type what the user would say into the box at the top left. Be precise—spelling matters! Alternately, speak to the skill by clicking and holding the microphone icon and speaking.
159+
160+
So far, the skill has one intent: **LaunchRequest**. This function responds to the user when they ask Alexa to open or launch the skill. The user will say, “Alexa, open Cake Walk.” Cake Walk is the name of your skill and was automatically set as the invocation name for the skill. You can change the invocation name, but let’s leave it as is for this exercise.
161+
162+
**c.** Test the skill. Type **open Cake Walk** (not case sensitive) into the box at the top left and press **ENTER**, or click and hold the microphone icon and say, “**Open Cake Walk**.”
163+
164+
> **When testing your skill in the Alexa developer console, you don’t need to provide the wake word (usually “Alexa”). Typing or saying, “Open Cake Walk” is fine. When testing on an Alexa-enabled device, you need the wake word: “Alexa, open Cake Walk.”**
165+
166+
## Wrap-up
167+
When you open the skill, does it say, "Hello! Welcome to Cake Walk. That was a piece of cake! Bye!"? If so, congratulations! You have laid the groundwork for the skill. You will be building new skills with compelling conversational voice experiences in no time.
168+
169+
There is still a lot to learn! In the next section, you will expand the skill to make it more useful.
170+
171+
## Code
172+
If your skill isn’t working or you’re getting some kind of syntax error, download the code sample in Python from the link below. Then, go to the Code tab in the Alexa developer console and copy and paste the code into the **lambda_function.py** file. Be sure to save and deploy the code before testing it.
173+
174+
[Python Github Code Sample, Module 1: Build a Skill in 5 Minutes](https://github.com/alexa/skill-sample-python-first-skill/tree/master/module-1)
175+
176+
[Continue to module 4](https://developer.amazon.com/alexa/alexa-skills-kit/resources/training-resources/cake-walk/cake-walk-4)

‎module-2/README.md‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Module 4
2-
31
## Collecting slots turn-by-turn with auto-delegation
42
In the previous section, you built an Alexa skill that says, “Hello! Welcome to Cake Walk. That was a piece of cake! Bye!” In this section, you will make the skill more useful by having it ask the user for their birthday. When the user responds, the skill will understand and repeat the user’s birthday back to them.
53

@@ -15,11 +13,9 @@ Use the [Alexa developer console](https://developer.amazon.com/alexa/console/as
1513
## Step 1: Ask the user for their birthday
1614
At the moment, the skill simply greets the user and exits. The welcome message helps set the context of the interaction—the user knows they are interacting with Cake Walk. Now you need to capture the user’s birthday to eventually calculate the number of days until the user’s next birthday. To do that, update the skill with programming logic that instructs Alexa to ask for the user’s birthday.
1715

18-
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/4/chapter4-1a.png)
19-
20-
[TODO: Replace with Python Screenshot]
16+
![](http://alexa-github.s3.amazonaws.com/python-code-tab.png)
2117

22-
**a.** In the developer console, click the**Code** tab.
18+
**a.** In the developer console, click the **Code** tab.
2319

2420
Find the **LaunchRequestHandler**. Within the handler, the **speak_output** variable is passed to the **.speak()** function. In the next step, update the string to ask the user for their birthday.
2521

‎module-3/README.md‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Module 5
2-
31
## Adding memory to your skill
42
In this section, you will enable the Cake Walk skill to remember the user’s birthday. What’s the point of the skill collecting information if the skill won’t remember it?
53

@@ -20,9 +18,7 @@ Start by using the AttributesManager to save the user’s birthday in Cake Walk.
2018

2119
**b.** Double-click the**requirements.txt** file in the pane on the left. The file opens in the editor.
2220

23-
![](https://d3ogm7ac91k97u.cloudfront.net/content/dam/alexa/alexa-skills-kit/courses/cake-walk/5/chapter5-1c.png)
24-
25-
[TODO: Replace with Python Screenshot]
21+
![](http://alexa-github.s3.amazonaws.com/python-requirements-1.png)
2622

2723
**c.** You are going to add a **requirement**. It’s easiest to put a new dependency at the bottom of the existing list.
2824

@@ -39,7 +35,8 @@ boto3==1.9.216
3935
ask-sdk-core==1.11.0
4036
ask-sdk-s3-persistence-adapter
4137
```
42-
[TODO: Add Python Screenshot for final requirements.txt]
38+
39+
![](http://alexa-github.s3.amazonaws.com/python-requirements-2.png)
4340

4441
**e.** Click **Save**.
4542

‎module-4/README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Module 6
2-
3-
# Using the Alexa Settings API
1+
## Using the Alexa Settings API
42
In this section, you will enable the Cake Walk skill to calculate the number of days until the user’s next birthday.
53
Use the [Alexa developer console](https://developer.amazon.com/alexa/console/ask) for this module. Log in to the console and open the Cake Walk skill.
64

0 commit comments

Comments
 (0)