├── lambda
└── py
│ ├── requirements.txt
│ └── lambda_function.py
├── NOTICE
├── .github
└── PULL_REQUEST_TEMPLATE.md
├── CODE_OF_CONDUCT.md
├── .ask
└── config
├── instructions
├── create-alexa-hosted-function.md
├── setup-vui-alexa-hosted.md
├── test-using-simulator.md
├── customize-skill-content.md
└── submit-for-certification.md
├── models
└── en-US.json
├── skill.json
├── README.md
├── hooks
├── pre_deploy_hook.ps1
├── pre_deploy_hook.sh
├── post_new_hook.sh
└── post_new_hook.ps1
├── CONTRIBUTING.md
└── LICENSE
/lambda/py/requirements.txt:
--------------------------------------------------------------------------------
1 | ask-sdk
2 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Skill Sample Python Highlowgame
2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | *Issue #, if available:*
2 |
3 | *Description of changes:*
4 |
5 |
6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
7 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/.ask/config:
--------------------------------------------------------------------------------
1 | {
2 | "deploy_settings": {
3 | "default": {
4 | "skill_id": "",
5 | "resources": {
6 | "lambda": [
7 | {
8 | "functionName": "",
9 | "alexaUsage": [
10 | "custom/default"
11 | ],
12 | "runtime": "python3.9",
13 | "handler": "lambda_function.lambda_handler"
14 | }
15 | ]
16 | },
17 | "merge": {}
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/instructions/create-alexa-hosted-function.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa High Low Game Skill
2 |
3 |
4 | Build an engaging high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
5 |
6 | ## Deploying Skill Code
7 |
8 | In the [first step of this guide](./setup-vui-alexa-hosted.md), we built the Voice User Interface (VUI) for our Alexa skill.
9 | On this page, we will be exploring the Alexa-Hosted code editor, and deploying our code to enable testing.
10 |
11 | * *For details on what the Alexa-Hosted skills service provides, open [this page](https://developer.amazon.com/docs/hosted-skills/build-a-skill-end-to-end-using-an-alexa-hosted-skill.html) in a new tab.*
12 |
13 |
14 | Within your skill in the developer console, click on the **Code** tab at the top of the page. You should see folders and files within the left panel, you can change your code, select the **Save** button, then select **Deploy**. This will deploy your code into a Lambda function that is automatically managed for you by the Alexa-Hosted service.
15 |
16 |
17 | At the bottom left corner of the page, notice the link to **Logs: Amazon CloudWatch**. CloudWatch is the logging service you can use to help debug your skill. We will go into more depth on how to use CloudWatch in the next step.
18 |
19 |
20 |
21 | [](./test-using-simulator.md)
22 |
23 |
--------------------------------------------------------------------------------
/models/en-US.json:
--------------------------------------------------------------------------------
1 | {
2 | "interactionModel": {
3 | "languageModel": {
4 | "invocationName": "high low game",
5 | "intents": [
6 | {
7 | "name": "AMAZON.CancelIntent",
8 | "samples": []
9 | },
10 | {
11 | "name": "AMAZON.HelpIntent",
12 | "samples": []
13 | },
14 | {
15 | "name": "AMAZON.StopIntent",
16 | "samples": []
17 | },
18 | {
19 | "name": "AMAZON.YesIntent",
20 | "samples": []
21 | },
22 | {
23 | "name": "AMAZON.FallbackIntent",
24 | "samples": []
25 | },
26 | {
27 | "name": "AMAZON.NoIntent",
28 | "samples": []
29 | },
30 | {
31 | "name": "NumberGuessIntent",
32 | "slots": [
33 | {
34 | "name": "number",
35 | "type": "AMAZON.NUMBER"
36 | }
37 | ],
38 | "samples": [
39 | "{number}",
40 | "is it {number}",
41 | "how about {number}",
42 | "could be {number}"
43 | ]
44 | }
45 | ],
46 | "types": []
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/skill.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest": {
3 | "publishingInformation": {
4 | "locales": {
5 | "en-US": {
6 | "summary": "Guess a number, and Alexa will tell you if you need to guess higher or lower.",
7 | "examplePhrases": [
8 | "Alexa open high low game",
9 | "Alexa start high low game",
10 | "Alexa ask high low game is it {number}"
11 | ],
12 | "name": "High Low Game",
13 | "description": "Guess a number, and Alexa will tell you if you need to guess higher or lower. She will also tell you how many times you have played. "
14 | },
15 | "en-GB": {
16 | "summary": "Guess a number, and Alexa will tell you if you need to guess higher or lower.",
17 | "examplePhrases": [
18 | "Alexa open high low game",
19 | "Alexa start high low game",
20 | "Alexa ask high low game is it {number}"
21 | ],
22 | "name": "High Low Game",
23 | "description": "Guess a number, and Alexa will tell you if you need to guess higher or lower. She will also tell you how many times you have played. "
24 | }
25 | },
26 | "isAvailableWorldwide": true,
27 | "testingInstructions": "Sample Testing Instructions.",
28 | "distributionCountries": []
29 | },
30 | "apis": {
31 | "custom": {
32 | "endpoint": {
33 | "sourceDir": "lambda/py",
34 | "uri": "ask-custom-highlow-default"
35 | }
36 | }
37 | },
38 | "manifestVersion": "1.0"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/instructions/setup-vui-alexa-hosted.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa High Low Game Skill
2 |
3 |
4 | Build an engaging high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
5 |
6 | ## Setting up Your Alexa Skill in the Developer Console (Alexa Hosted)
7 |
8 | With an Alexa-hosted skill, you can build, edit, and publish a skill without leaving the developer console.
9 | The skill includes a code editor for managing and deploying the backend code for your skill.
10 | For details on what the Alexa-Hosted skills service provides, open [this page](https://developer.amazon.com/docs/hosted-skills/build-a-skill-end-to-end-using-an-alexa-hosted-skill.html) in a new tab.
11 |
12 | ### Steps
13 | Now that you've chosen Alexa-Hosted for the method to host your skill's backend resources, to use this template, select **High Low Skill** and click "Choose". It will take a minute to create your Alexa hosted skill, then you will be taken to the Build tab of the console. It will take a minute to create your Alexa hosted skill, then you will be taken to the Build tab of the console.
14 |
15 |
16 | #### Build the Interaction Model for your skill
17 |
18 | The Interaction Model for any skill lays the general guidelines of speech Alexa will listen for, including any additional information it may need to gather (ex: Slot Values). If you want to learn more about the Interaction Model and how it works, make sure to check out [the ASK Documentation on Creating an Interaction Model](https://developer.amazon.com/docs/custom-skills/create-the-interaction-model-for-your-skill.html).
19 |
20 | - If you want to change the skill invocation name, select the **Build** tab, then **Invocation** under **Interaction Model**. Enter a **Skill Invocation Name**. This is the name that your users will need to say to start your skill.
21 | - Click "Build Model".
22 |
23 |
24 | #### NEXT: Review and Deploy the Alexa-Hosted Code
25 | [](./create-alexa-hosted-function.md)
26 |
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Build An Alexa High Low Game Skill using ASK Python SDK
2 | =========================================
3 |
4 | This Alexa sample skill is a template for a basic high-low game skill. The high low game is a game where the player tries to guess the target number between 1 to 100. After each incorrect guess, the player is informed if the target number is higher or lower than their current guess. This continues until the target number is guessed or the player gives up. This sample Alexa Skill is written in Python and demonstrates the use of session and persistent attributes.
5 |
6 |
7 |
8 |
9 | ## Let's Get Started
10 | If this is your first time here, you're new to Alexa Skills Development, or you're looking for more detailed instructions, click the **Get Started** button below:
11 |
12 |
3 |
4 | Build an engaging high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
5 |
6 | ## Testing Your Alexa Skill
7 |
8 | So far, we have created a Voice User Interface, and deployed code to a backend service linked to the skill. Your skill is now ready to test.
9 |
10 | 1. If you are not continuing immediately from the previous step, **go back to the [Amazon Developer Portal](https://developer.amazon.com/alexa/console/ask?&sc_category=Owned&sc_channel=RD&sc_campaign=Evangelism2018&sc_publisher=github&sc_content=Survey&sc_detail=fact-nodejs-V2_GUI-4&sc_funnel=Convert&sc_country=WW&sc_medium=Owned_RD_Evangelism2018_github_Survey_fact-nodejs-V2_GUI-4_Convert_WW_beginnersdevs&sc_segment=beginnersdevs) and select your skill from the list.**
11 |
12 | 2. Access the **Alexa Simulator**, by selecting the **Test** tab from the top navigation menu. Your browser may request permission to access your microphone. While it is recommended to do so, it is not required. Do note that if you don't allow access to the microphone, you must type your utterances to Alexa in the simulator.
13 |
14 | 3. Notice the dropdown next to "Test is disabled for this skill.", found just underneath the top navigation menu. To enable testing mode, toggle the dropdown from Off to Development.
15 |
16 | 4. To validate that your skill is working as expected, invoke your skill from the **Alexa Simulator** just below. You can either type or click and hold the mic from the input box to use your voice.
17 | 1. **Type** "Open" followed by the invocation name you gave your skill previously. For example, "Open space facts".
18 | 2. **Use your voice** by clicking and holding the mic on the side panel and saying "Open" followed by the invocation name you gave your skill.
19 | 3. **If you've forgotten the invocation name** for your skill, revisit the **Build** panel on the top navigation menu and select **Invocation** from the sidebar to review it.
20 |
21 | * *Tip: Always finish your test by saying "stop" to formally end your session.*
22 |
23 |
24 | 5. Ensure your skill works the way that you designed it to.
25 | * After you interact with the Alexa Simulator, you should see the Skill I/O **JSON Input** and **JSON Output** boxes get populated with JSON data. You can also view the **Device Log** to trace your steps.
26 | - You can view the Device Log in the **Test** tab by toggling the check box in the upper right hand corner.
27 | * If it's not working as expected, you can dig into the JSON to see exactly what Alexa is sending and receiving from the endpoint. If something is broken, you can find the error in AWS Cloudwatch.
28 |
29 |
30 | 6. Troubleshooting with CloudWatch log messages: You can add `logger.info()` statements to your code, to track what is happening as your code executes, and help to figure out what is happening when something goes wrong. You will find the log to be incredibly valuable as you move into more advanced skills. To view CloudWatch logs:
31 | 1. Navigate to the **Code** Tab
32 | 2. In the bottom left hand corner, click the **Logs: Amazon CloudWatch** link
33 | 3. Once you are in the AWS CloudWatch Management Console, you can filter your log streams. Sorting by the `Last Event Time` column and clicking the top row will show you the logs of the last invocation. You can also filter or search for a specific log output with the `Filter` input field.
34 |
35 |
36 | [](./customize-skill-content.md)
37 |
--------------------------------------------------------------------------------
/instructions/customize-skill-content.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa High Low Game Skill
2 |
3 |
4 | Build an engaging high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
5 |
6 | ## Customize the Skill to be Yours
7 |
8 | At this point, you should have a working copy of our Fact skill. In order to make it your own, you will need to customize it with data and responses that you create. Here are the things you will need to change:
9 |
10 | 1. **New sentences to respond to your users.** There are several sentences and responses that you will want to customize for your skill.
11 |
12 | 1. Navigate to the **Code** tab again, and expand the project folder on the left to `Skill Code/lambda`.
13 |
14 | 2. Open **[lambda_function.py](../lambda/py/lambda_function.py)**
15 |
16 | 3. We are going to be editing a response message when the user exits the skill, so let's only focus on lines `64-71`. This contains all of the code for when a user exits the skill. I am going to be replacing the response message when a user exits the skill from "Thanks for playing!!" to "Thanks for playing, looking forward to playing with you again!". To do this, let's focus on line `67` in particular, and replace the contents:
17 |
18 | Before:
19 | ```py
20 | def cancel_and_stop_intent_handler(handler_input):
21 | """Single handler for Cancel and Stop Intent."""
22 | # type: (HandlerInput) -> Response
23 | speech_text = "Thanks for playing!!" # <-- What we want to change
24 |
25 | handler_input.response_builder.speak(
26 | speech_text).set_should_end_session(True)
27 | return handler_input.response_builder.response
28 | ```
29 |
30 | After:
31 | ```py
32 | def cancel_and_stop_intent_handler(handler_input):
33 | """Single handler for Cancel and Stop Intent."""
34 | # type: (HandlerInput) -> Response
35 | speech_text = "Thanks for playing, looking forward to playing with you again!" # <-- CHANGED
36 |
37 | handler_input.response_builder.speak(
38 | speech_text).set_should_end_session(True)
39 | return handler_input.response_builder.response
40 | ```
41 |
42 | After you're done editing all of the files necessary, as before, make sure to press **Save**, **Deploy**, and navigate back to the **Testing** tab. When you launch the skill then exit, Alexa should respond with "Thanks for playing, looking forward to playing with you again" instead of "Thanks for playing!!".
43 |
44 | 2. **New language.** If you are creating this skill for another language other than English, you will need to make sure Alexa's responses are also in that language.
45 |
46 | - For example, if you are creating your skill in German, every single response that Alexa makes has to be in German. You can't use English responses or your skill will fail certification.
47 |
48 | 3. **Once you have customized the skill's data, languages and/or sentences, return to the [Amazon Developer Portal](https://developer.amazon.com/alexa/console/ask?&sc_category=Owned&sc_channel=RD&sc_campaign=Evangelism2018&sc_publisher=github&sc_content=Survey&sc_detail=fact-nodejs-V2_GUI-5&sc_funnel=Convert&sc_country=WW&sc_medium=Owned_RD_Evangelism2018_github_Survey_fact-nodejs-V2_GUI-5_Convert_WW_beginnersdevs&sc_segment=beginnersdevs) and select your skill from the list.**
49 |
50 | 4. **Click on "Distribution" in the top navigation to move on to the publishing and certification of your skill.**
51 |
52 |
53 | [](./submit-for-certification.md)
54 |
55 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check [existing open](https://github.com/alexa-labs/skill-sample-python-highlowgame/issues), or [recently closed](https://github.com/alexa-labs/skill-sample-python-highlowgame/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *master* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/alexa-labs/skill-sample-python-highlowgame/labels/help%20wanted) issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Security issue notifications
54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55 |
56 |
57 | ## Licensing
58 |
59 | See the [LICENSE](https://github.com/alexa-labs/skill-sample-python-highlowgame/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60 |
61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
62 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Amazon Software License 1.0
2 |
3 | This Amazon Software License ("License") governs your use, reproduction, and
4 | distribution of the accompanying software as specified below.
5 |
6 | 1. Definitions
7 |
8 | "Licensor" means any person or entity that distributes its Work.
9 |
10 | "Software" means the original work of authorship made available under this
11 | License.
12 |
13 | "Work" means the Software and any additions to or derivative works of the
14 | Software that are made available under this License.
15 |
16 | The terms "reproduce," "reproduction," "derivative works," and
17 | "distribution" have the meaning as provided under U.S. copyright law;
18 | provided, however, that for the purposes of this License, derivative works
19 | shall not include works that remain separable from, or merely link (or bind
20 | by name) to the interfaces of, the Work.
21 |
22 | Works, including the Software, are "made available" under this License by
23 | including in or with the Work either (a) a copyright notice referencing the
24 | applicability of this License to the Work, or (b) a copy of this License.
25 |
26 | 2. License Grants
27 |
28 | 2.1 Copyright Grant. Subject to the terms and conditions of this License,
29 | each Licensor grants to you a perpetual, worldwide, non-exclusive,
30 | royalty-free, copyright license to reproduce, prepare derivative works of,
31 | publicly display, publicly perform, sublicense and distribute its Work and
32 | any resulting derivative works in any form.
33 |
34 | 2.2 Patent Grant. Subject to the terms and conditions of this License, each
35 | Licensor grants to you a perpetual, worldwide, non-exclusive, royalty-free
36 | patent license to make, have made, use, sell, offer for sale, import, and
37 | otherwise transfer its Work, in whole or in part. The foregoing license
38 | applies only to the patent claims licensable by Licensor that would be
39 | infringed by Licensor's Work (or portion thereof) individually and
40 | excluding any combinations with any other materials or technology.
41 |
42 | 3. Limitations
43 |
44 | 3.1 Redistribution. You may reproduce or distribute the Work only if
45 | (a) you do so under this License, (b) you include a complete copy of this
46 | License with your distribution, and (c) you retain without modification
47 | any copyright, patent, trademark, or attribution notices that are present
48 | in the Work.
49 |
50 | 3.2 Derivative Works. You may specify that additional or different terms
51 | apply to the use, reproduction, and distribution of your derivative works
52 | of the Work ("Your Terms") only if (a) Your Terms provide that the use
53 | limitation in Section 3.3 applies to your derivative works, and (b) you
54 | identify the specific derivative works that are subject to Your Terms.
55 | Notwithstanding Your Terms, this License (including the redistribution
56 | requirements in Section 3.1) will continue to apply to the Work itself.
57 |
58 | 3.3 Use Limitation. The Work and any derivative works thereof only may be
59 | used or intended for use with the web services, computing platforms or
60 | applications provided by Amazon.com, Inc. or its affiliates, including
61 | Amazon Web Services, Inc.
62 |
63 | 3.4 Patent Claims. If you bring or threaten to bring a patent claim against
64 | any Licensor (including any claim, cross-claim or counterclaim in a
65 | lawsuit) to enforce any patents that you allege are infringed by any Work,
66 | then your rights under this License from such Licensor (including the
67 | grants in Sections 2.1 and 2.2) will terminate immediately.
68 |
69 | 3.5 Trademarks. This License does not grant any rights to use any
70 | Licensor's or its affiliates' names, logos, or trademarks, except as
71 | necessary to reproduce the notices described in this License.
72 |
73 | 3.6 Termination. If you violate any term of this License, then your rights
74 | under this License (including the grants in Sections 2.1 and 2.2) will
75 | terminate immediately.
76 |
77 | 4. Disclaimer of Warranty.
78 |
79 | THE WORK IS PROVIDED "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
80 | EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF
81 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR
82 | NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER
83 | THIS LICENSE. SOME STATES' CONSUMER LAWS DO NOT ALLOW EXCLUSION OF AN
84 | IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU.
85 |
86 | 5. Limitation of Liability.
87 |
88 | EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL
89 | THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE
90 | SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT,
91 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR
92 | RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK (INCLUDING
93 | BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS
94 | OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER COMM ERCIAL DAMAGES
95 | OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF
96 | SUCH DAMAGES.
97 |
--------------------------------------------------------------------------------
/lambda/py/lambda_function.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # This is a High Low Guess game Alexa Skill.
4 | # The skill serves as a simple sample on how to use the
5 | # persistence attributes and persistence adapter features in the SDK.
6 | import random
7 | import logging
8 |
9 | from ask_sdk.standard import StandardSkillBuilder
10 | from ask_sdk_core.utils import is_request_type, is_intent_name
11 | from ask_sdk_core.handler_input import HandlerInput
12 |
13 | from ask_sdk_model import Response
14 |
15 | SKILL_NAME = 'High Low Game'
16 | sb = StandardSkillBuilder(table_name="High-Low-Game", auto_create_table=True)
17 |
18 | logger = logging.getLogger(__name__)
19 | logger.setLevel(logging.INFO)
20 |
21 |
22 | @sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
23 | def launch_request_handler(handler_input):
24 | """Handler for Skill Launch.
25 |
26 | Get the persistence attributes, to figure out the game state.
27 | """
28 | # type: (HandlerInput) -> Response
29 | attr = handler_input.attributes_manager.persistent_attributes
30 | if not attr:
31 | attr['ended_session_count'] = 0
32 | attr['games_played'] = 0
33 | attr['game_state'] = 'ENDED'
34 |
35 | handler_input.attributes_manager.session_attributes = attr
36 |
37 | speech_text = (
38 | "Welcome to the High Low guessing game. You have played {} times. "
39 | "Would you like to play?".format(attr["games_played"]))
40 | reprompt = "Say yes to start the game or no to quit."
41 |
42 | handler_input.response_builder.speak(speech_text).ask(reprompt)
43 | return handler_input.response_builder.response
44 |
45 |
46 | @sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))
47 | def help_intent_handler(handler_input):
48 | """Handler for Help Intent."""
49 | # type: (HandlerInput) -> Response
50 | speech_text = (
51 | "I am thinking of a number between zero and one hundred, try to "
52 | "guess it and I will tell you if you got it or it is higher or "
53 | "lower")
54 | reprompt = "Try saying a number."
55 |
56 | handler_input.response_builder.speak(speech_text).ask(reprompt)
57 | return handler_input.response_builder.response
58 |
59 |
60 | @sb.request_handler(
61 | can_handle_func=lambda input:
62 | is_intent_name("AMAZON.CancelIntent")(input) or
63 | is_intent_name("AMAZON.StopIntent")(input))
64 | def cancel_and_stop_intent_handler(handler_input):
65 | """Single handler for Cancel and Stop Intent."""
66 | # type: (HandlerInput) -> Response
67 | speech_text = "Thanks for playing!!"
68 |
69 | handler_input.response_builder.speak(
70 | speech_text).set_should_end_session(True)
71 | return handler_input.response_builder.response
72 |
73 |
74 | @sb.request_handler(can_handle_func=is_request_type("SessionEndedRequest"))
75 | def session_ended_request_handler(handler_input):
76 | """Handler for Session End."""
77 | # type: (HandlerInput) -> Response
78 | logger.info(
79 | "Session ended with reason: {}".format(
80 | handler_input.request_envelope.request.reason))
81 | return handler_input.response_builder.response
82 |
83 |
84 | def currently_playing(handler_input):
85 | """Function that acts as can handle for game state."""
86 | # type: (HandlerInput) -> bool
87 | is_currently_playing = False
88 | session_attr = handler_input.attributes_manager.session_attributes
89 |
90 | if ("game_state" in session_attr
91 | and session_attr['game_state'] == "STARTED"):
92 | is_currently_playing = True
93 |
94 | return is_currently_playing
95 |
96 |
97 | @sb.request_handler(can_handle_func=lambda input:
98 | not currently_playing(input) and
99 | is_intent_name("AMAZON.YesIntent")(input))
100 | def yes_handler(handler_input):
101 | """Handler for Yes Intent, only if the player said yes for
102 | a new game.
103 | """
104 | # type: (HandlerInput) -> Response
105 | session_attr = handler_input.attributes_manager.session_attributes
106 | session_attr['game_state'] = "STARTED"
107 | session_attr['guess_number'] = random.randint(0, 100)
108 | session_attr['no_of_guesses'] = 0
109 |
110 | speech_text = "Great! Try saying a number to start the game."
111 | reprompt = "Try saying a number."
112 |
113 | handler_input.response_builder.speak(speech_text).ask(reprompt)
114 | return handler_input.response_builder.response
115 |
116 |
117 | @sb.request_handler(can_handle_func=lambda input:
118 | not currently_playing(input) and
119 | is_intent_name("AMAZON.NoIntent")(input))
120 | def no_handler(handler_input):
121 | """Handler for No Intent, only if the player said no for
122 | a new game.
123 | """
124 | # type: (HandlerInput) -> Response
125 | session_attr = handler_input.attributes_manager.session_attributes
126 | session_attr['game_state'] = "ENDED"
127 | session_attr['ended_session_count'] += 1
128 |
129 | handler_input.attributes_manager.persistent_attributes = session_attr
130 | handler_input.attributes_manager.save_persistent_attributes()
131 |
132 | speech_text = "Ok. See you next time!!"
133 |
134 | handler_input.response_builder.speak(speech_text)
135 | return handler_input.response_builder.response
136 |
137 |
138 | @sb.request_handler(can_handle_func=lambda input:
139 | currently_playing(input) and
140 | is_intent_name("NumberGuessIntent")(input))
141 | def number_guess_handler(handler_input):
142 | """Handler for processing guess with target."""
143 | # type: (HandlerInput) -> Response
144 | session_attr = handler_input.attributes_manager.session_attributes
145 | target_num = session_attr["guess_number"]
146 | guess_num = int(handler_input.request_envelope.request.intent.slots[
147 | "number"].value)
148 |
149 | session_attr["no_of_guesses"] += 1
150 |
151 | if guess_num > target_num:
152 | speech_text = (
153 | "{} is too high. Try saying a smaller number.".format(guess_num))
154 | reprompt = "Try saying a smaller number."
155 | elif guess_num < target_num:
156 | speech_text = (
157 | "{} is too low. Try saying a larger number.".format(guess_num))
158 | reprompt = "Try saying a larger number."
159 | elif guess_num == target_num:
160 | speech_text = (
161 | "Congratulations. {} is the correct guess. "
162 | "You guessed the number in {} guesses. "
163 | "Would you like to play a new game?".format(
164 | guess_num, session_attr["no_of_guesses"]))
165 | reprompt = "Say yes to start a new game or no to end the game"
166 | session_attr["games_played"] += 1
167 | session_attr["game_state"] = "ENDED"
168 |
169 | handler_input.attributes_manager.persistent_attributes = session_attr
170 | handler_input.attributes_manager.save_persistent_attributes()
171 | else:
172 | speech_text = "Sorry, I didn't get that. Try saying a number."
173 | reprompt = "Try saying a number."
174 |
175 | handler_input.response_builder.speak(speech_text).ask(reprompt)
176 | return handler_input.response_builder.response
177 |
178 |
179 | @sb.request_handler(can_handle_func=lambda input:
180 | is_intent_name("AMAZON.FallbackIntent")(input) or
181 | is_intent_name("AMAZON.YesIntent")(input) or
182 | is_intent_name("AMAZON.NoIntent")(input))
183 | def fallback_handler(handler_input):
184 | """AMAZON.FallbackIntent is only available in en-US locale.
185 | This handler will not be triggered except in that locale,
186 | so it is safe to deploy on any locale.
187 | """
188 | # type: (HandlerInput) -> Response
189 | session_attr = handler_input.attributes_manager.session_attributes
190 |
191 | if ("game_state" in session_attr and
192 | session_attr["game_state"]=="STARTED"):
193 | speech_text = (
194 | "The {} skill can't help you with that. "
195 | "Try guessing a number between 0 and 100. ".format(SKILL_NAME))
196 | reprompt = "Please guess a number between 0 and 100."
197 | else:
198 | speech_text = (
199 | "The {} skill can't help you with that. "
200 | "It will come up with a number between 0 and 100 and "
201 | "you try to guess it by saying a number in that range. "
202 | "Would you like to play?".format(SKILL_NAME))
203 | reprompt = "Say yes to start the game or no to quit."
204 |
205 | handler_input.response_builder.speak(speech_text).ask(reprompt)
206 | return handler_input.response_builder.response
207 |
208 |
209 | @sb.request_handler(can_handle_func=lambda input: True)
210 | def unhandled_intent_handler(handler_input):
211 | """Handler for all other unhandled requests."""
212 | # type: (HandlerInput) -> Response
213 | speech = "Say yes to continue or no to end the game!!"
214 | handler_input.response_builder.speak(speech).ask(speech)
215 | return handler_input.response_builder.response
216 |
217 |
218 | @sb.exception_handler(can_handle_func=lambda i, e: True)
219 | def all_exception_handler(handler_input, exception):
220 | """Catch all exception handler, log exception and
221 | respond with custom message.
222 | """
223 | # type: (HandlerInput, Exception) -> Response
224 | logger.error(exception, exc_info=True)
225 | speech = "Sorry, I can't understand that. Please say again!!"
226 | handler_input.response_builder.speak(speech).ask(speech)
227 | return handler_input.response_builder.response
228 |
229 |
230 | @sb.global_response_interceptor()
231 | def log_response(handler_input, response):
232 | """Response logger."""
233 | # type: (HandlerInput, Response) -> None
234 | logger.info("Response: {}".format(response))
235 |
236 |
237 | lambda_handler = sb.lambda_handler()
238 |
--------------------------------------------------------------------------------
/instructions/submit-for-certification.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa High Low Game Skill
2 |
3 |
4 | Build an engaging high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
5 |
6 | ## Get Your Skill Certified and Published
7 |
8 | We are almost done! The last step is to add the metadata that your skill will use in the [Skill Store](http://amazon.com/skills). This page will walk you through the remaining steps to launch your skill!
9 |
10 | 1. Select the **Distribution** link from the top navigation menu.
11 |
12 | 2. Fill out the form fields per the guidance on the screen. Hover over the question mark icons for details regarding each respective field. **Fields marked with an Asterisk, are required!**
13 | * Take the time to get these right so that your skill will pass certification!
14 |
15 | 3. **Write your skill descriptions.**
16 |
17 | * **Spend some time coming up with an enticing, succinct description.** This is one of the few places you have an opportunity to attract new users, so make the most of it! These descriptions show up in the list of skills available in the [Alexa app](http://alexa.amazon.com/spa/index.html#skills) and the [skills store](http://www.amazon.com/skills).
18 |
19 | 4. For your example phrases, **come up with the three most exciting ways** a user can talk to your skill.
20 |
21 | * Make sure that each of your example phrases are a **perfect match with one of your Sample Utterances.** Incorrect example phrases are one of the most common reasons that skills fail certification, so we have provided a short list of things to consider as you write your example phrases:
22 |
23 | | Common Failure Points for Example Phrases |
24 | | ----------------------------------------- |
25 | | Example phrases **must** adhere to the [supported phrases](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/supported-phrases-to-begin-a-conversation?&sc_category=Owned&sc_channel=RD&sc_campaign=Evangelism2018&sc_publisher=github&sc_content=Survey&sc_detail=high-low-game-nodejs-V2_GUI-6&sc_funnel=Convert&sc_country=WW&sc_medium=Owned_RD_Evangelism2018_github_Survey_high-low-game-nodejs-V2_GUI-6_Convert_WW_beginnersdevs&sc_segment=beginnersdevs). |
26 | | Example phrases **must** be based on sample utterances specified in your Intent Schema. |
27 | | Your first example phrase **must** include a wake word and your invocation name. |
28 | | Example phrases **must** provide a contextual response. |
29 |
30 | * **Choose three example phrases that are likely to be the most common ways that users will attempt to interact with your skill.** Make sure that each of them works well, and provides an excellent user experience.
31 |
32 | 5. **Create your skill's icons.** You need two sizes of your icon: 108x108px and 512x512px. When you upload an image, it will be automatically fit to the required dimensions.
33 |
34 | * **Make sure you have the rights to the icons you create.** Please don't violate any trademarks or copyrights.
35 | * **If you don't have software to make icons, try one of these free options:**
36 |
37 | * [Alexa Skill Icon Builder](https://developer.amazon.com/docs/tools/icon-builder.html) (a link to this is included in the console)
38 |
39 | * [GIMP](https://www.gimp.org/) (Windows/Mac/Linux)
40 | * [Canva](https://www.canva.com/) (Web)
41 | * [Paint.NET](http://www.getpaint.net/index.html) (Windows)
42 | * [Inkscape](http://inkscape.org) (Windows/Mac/Linux)
43 | * [Iconion](http://iconion.com/) (Windows/Mac)
44 |
45 | * To make it easier to get started, we've created blank versions of these icons in both sizes for many formats:
46 |
47 | * [PSD](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/psd._TTH_.zip)
48 | * [PNG](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/png._TTH_.zip)
49 | * [GIF](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/gif._TTH_.zip)
50 | * [PDF](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/pdf._TTH_.zip)
51 | * [JPG](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/jpg._TTH_.zip)
52 | * [SVG](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/svg._TTH_.zip)
53 | * [PDN](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/pdn._TTH_.zip) - for [Paint.NET](http://www.getpaint.net/index.html)
54 | * [XCF](https://m.media-amazon.com/images/G/01/mobile-apps/dex/alexa/alexa-skills-kit/tutorials/general/icon-templates/xcf._TTH_.zip) - for [GIMP](https://www.gimp.org/)
55 |
56 | 6. Choose the most appropriate category for your skill.
57 |
58 | 7. **Provide a comprehensive list of keywords for users that are searching for new skills.** This is an optional field, and searching the [Alexa app](http://alexa.amazon.com) or the [skill store](http://www.amazon.com/skills) will also find the words in your Skill Name and descriptions, so you don't need to overdo it. That being said, if there are words that you want users to find your skill with, you should include them here. Separate the keywords with commas.
59 |
60 | 8. **Privacy Policy URL.** This is an optional field, and should not be required for this high-low skill sample. You can leave it blank.
61 |
62 | 9. **Terms of Use URL.** This is also optional, and you can leave it blank.
63 |
64 | 10. When you're ready, click **Save and Continue** at the bottom of the screen to move onto **Privacy & Compliance**
65 |
66 | 11. * **Does this skill allow users to make purchases or spend real money?** For this high-low skill, the answer is no. For future skills, make sure you answer this appropriately.
67 |
68 | * **Does this Alexa skill collect users' personal information?** Again, for this high-low skill, the answer is no. If you do collect information about a user, such as names, email addresses, phone numbers, and so forth, ensure that you answer Yes to this question.
69 | * Answering "yes" to this question will also require you to provide a link to your Privacy Policy on the previous page.
70 |
71 | * **Is your skill directed to children under the age of 13?** Because you customized this skill with data you provided, it is possible that you created a skill that targets children under the age of 13. For this high-low skill, the answer is **no** because it doesn't target a specific age group.
72 | * Factors to consider in determining if this skill is directed to children under 13 include:
73 | * Subject matter of the skill
74 | * Presence of child-oriented activities and incentives
75 | * Type of language used in the skill
76 | * Music and other audio content in the skill
77 | * How the skill is described and marketed
78 | * Intended audience for the skill
79 |
80 | If you're not sure, please see the [FTC's COPPA Guidance and FAQ](https://www.ftc.gov/tips-advice/business-center/guidance/complying-coppa-frequently-asked-questions) for more information.
81 |
82 | 12. **Export Compliance.** Be certain that you agree with all of the conditions. If you do, make sure to check this box, as Amazon requires this permission to distribute your skill around the globe.
83 |
84 | 13. **Provide testing instructions.** Testing instructions give you an opportunity to explain your skill, and any special or possibly confusing features, to the certification team. A value is required in this box.
85 |
86 | * Since you are using our Sample, make sure to add a sentence to your Testing Instructions referencing the Sample you used. For example:
87 |
88 | ```text
89 | This was built using the high low game sample.
90 | ```
91 |
92 | This will let the testing team understand what you're providing them, and should decrease the testing time required.
93 |
94 | **Note:** More details on certification are [available here](https://alexa.design/certification).
95 |
96 | 14. Click the **Save and Continue** button at the bottom of the page to move on to **Availability**.
97 | * You'll want to allow the Public to access the skill unless you are using [Alexa for Business](https://aws.amazon.com/a4b).
98 | * Beta testing is a good idea for every skill, however since this is from a template and is very basic, we'll skip that for now. When you make your next skill, don't skip this step. Seriously. You won't regret it.
99 | * It is recommended to allow your skill to be available in all countries and regions where Amazon distributes skills. Reasons to restrict distribution include not having intellectual property rights to distribute to that area and the content being illegal, offensive or otherwise prohibited in that area.
100 |
101 | 15. If you feel that your skill is ready for certification, click the **Save and Continue** button at the bottom of the page and you'll be taken to the certification tab.
102 |
103 | 16. The **Validation** page will tell you if you have missed any steps along the way which will prevent your skill from being submitted. You shouldn't see anything on this page, but if you do, go back and fix the issues.
104 |
105 | 17. Click on the **Functional test** section and click the **Run** button to run functional tests against your skill. You shouldn't see any errors on this page, but if you do, go back and fix the issues.
106 |
107 | 18. Click on **Submission**, and the click **Submit for Review**.
108 |
109 | 19. **You're done with your submission!** Here are a few things you might need to know:
110 |
111 | * **Certification can take several days to complete.** Please be patient. It takes time because we want to get it right.
112 |
113 | * **Did something go wrong?** Our team of evangelists run [online office hours every Tuesday from 1-2pm Pacific Time](https://alexa.design/officehours). They can help answer any questions you might have.
114 |
115 | * **Want to earn developer perks?** Check out current opportunities to earn perks for building skills: https://developer.amazon.com/alexa-skills-kit/alexa-developer-skill-promotion
116 |
117 | If you’re not in the US, please check out our other promotions in the [UK](https://developer.amazon.com/en-gb/alexa-skills-kit/alexa-developer-skill-promotion), [Germany](https://developer.amazon.com/de/alexa-skills-kit/alexa-developer-skill-promotion), [Japan](https://developer.amazon.com/ja/alexa-skills-kit/alexa-developer-skill-promotion), [France](https://developer.amazon.com/fr/alexa-skills-kit/alexa-developer-skills-promotion), [Australia](https://developer.amazon.com/alexa-skills-kit/anz/alexa-developer-skill-promotion), [Italy](https://developer.amazon.com/it/alexa-skills-kit/alexa-developer-skill-promotion), [Spain](https://developer.amazon.com/es/alexa-skills-kit/alexa-developer-skill-promotion), [Mexico](https://developer.amazon.com/es-mx/alexa-skills-kit/alexa-developer-skill-promotion), [Canada](https://developer.amazon.com/alexa-skills-kit/alexa-developer-skill-promotion-canada), and [India](https://developer.amazon.com/alexa-skills-kit/alexa-developer-skill-promotion-india) to see if your country of residence is included.
118 |
--------------------------------------------------------------------------------