Please watch this video to understand the gameplay, story, and pretty much everything about this project. Please watch this.
Let's say you have to make a game.You can only use buttons, and you cannot explain the mechanics in any other way besides verbally. How would one do this?!
The Core MechanicsA few months ago, my friends and I were eating lunch one day at school, and we started talking about how our parents are unable to keep time very well (be back in 2 minutes turned to 2 hours). The conversation skewed to how good we were at keeping time. Say you had a button, and you pressed it to start a game. It chooses a random number of seconds and tells it to you. Without using any sort of watch or time-keeping piece, you have to press the button again after the aforementioned amount of time. With enough practice, you can become a very good human stopwatch. I don't know why you would want that, but it sounds like a fun party game.
Fast forward a few months, and I saw this Echo Buttons contest. I started thinking about what I could do for the competition. I remembered that game from a few months back, Tick Tock Stop!
How does Alexa work?The Amazon Alexa has three main parts:
- AWS Lambda backend
- Amazon Alexa Interface
- Amazon Alexa Gadgets Interface
Which I have simplified into a simple diagram, for your viewing pleasure.
Let's start with a simple skill, which says, "Hello World!" when you invoke it. This example will only be affiliated with these parts (circled in red):
Let's take a look at an Alexa Skill works. When you say "Alexa, launch Hello World!", Alexa looks for two things (in an invocation): An action, and a subject of that action. In this case, the action is to launch (start) the subject, a skill named "Hello World". Amazon Alexa first looks at her library of activated skills and searches for a possible match. If you activated the Hello World skill in the skill store, Alexa will find the skill and initiate a connection with the skill's server via the internet, as seen by the WiFi logos near the Alexa and Lambda logos in the diagram.
Alexa first tells the server to "invoke" a function which will greet the user. Functions which Alexa tells the server to do are called intents. Intents are what Alexa "intends" to do. In this case, Alexa intends to greet the user. Knowing this, Lambda tells Alexa to say "Hey there, you can say hello!". The user responds to this by saying "Hello!". Alexa now looks at her list of intents and finds an intent that fits the requirements. Think of it like finding a puzzle piece that fits best with another one.
Once Alexa finds one that fits, she will tell the server to run that function related to that intent. In our case, the intent that accepts "Hello" as input is run. The function tells Alexa to say, "Hello World!" and tells Alexa to end the session (conversation), meaning that no more requests will be sent to the sever until the skill is invoked again.
What would happen if a response does not match an intent? In that situation, Alexa will launch the "Error" intent, which almost always says something along the lines of, "I'm sorry, I do not understand."
Step 1- Account SetupFor this project, you need to setup 2 accounts:
- Amazon Developers Account- This account is linked to your skill in the store. You can register for an account here.
- AWS Account- This account is linked to the skill backend. This account requires a credit card, but will not incur charges unless your function exceeds a certain amount of calls, which it shouldn't. You can register for an account here.
Once you have these accounts set up, navigate to the Amazon Alexa Developers Homepage and sign in.
Step 2- Skill SetupNow that we have the accounts set up, we can move on to creating the skill. Click on the button called "Skills" under the menu "Your Alexa Consoles" in the top right corner.
Welcome to the Amazon Developers Console! This is where you can see every skill you have made. If you are just starting out, there should be no skills there. Go ahead and click on the "Create Skill" button in the middle right.
This is the skill creation menu. Enter a name, make sure the default language is English (US) and make sure that a custom model is selected. Press "Create Skill" in the top right corner.
Choose the "Start from scratch" template and press choose.
Congratulations! You've created a skill! Stay on this page.
Step 3- Interaction Model & Interfaces SetupNow that we have a skill, we need to set up the interaction model. The invocation name is what the user will say to invoke the skill like:
- Alexa, launch {invocation name}
- Alexa, play {invocation name}
According to the Alexa Developers, The invocation name must fulfill these requirements:
- 2 or more words
- Contains "only lower-case alphabetic characters, spaces between words, possessive apostrophes (for example, 'sam's science trivia'), or periods used in abbreviations (for example, 'a. b. c.')"
- Does not contain the words "launch", "ask", "tell", "load", "begin", "enable", "Alexa", "Amazon", "Echo", "Computer", "skill" or "app"
Come up with a name and write it down somewhere. We will need this later.
Now that we have an invocation name, we can edit the JSON to work with the Tick Tock Stop skill. Navigate to the "JSON Editor" menu in the left panel.
Download the Interaction Model JSON and drag the file onto the page like so:
Find the property "invocationName" near the top of the JSON file and replace the text:
"tick tock stop",
With your invocation name. Don't forget the double quotes and the comma afterwards, like so:
"my cool game",
Go ahead and press the button called "Save Model". The Interaction Model has now been set up.
Now that we have the interaction model set up, we now need to set up the interfaces. Navigate to the menu called "Interfaces" in the left-side panel. Toggle the Gadget Controller and Game Engine interfaces so that their switches are blue.
Press the button "Save Interfaces" and press the button "Build Model" to finish setup. Keep this tab open.
Step 4- AWS Lambda SetupNavigate to the AWS homepage in a new tab. Click the button "AWS Management Console" under the menu "My Account" in the top right corner.
Welcome to the AWS Management Console! This is where you can monitor your functions. Set your region to US East (N. Virginia) in the drop down menu to the right of your name (in the top right corner).
Under the "Services" drop down menu in the top left corner, select "Lambda".
This will direct you to the Lambda Management console, where you can monitor every lambda function you have made!
Press the button "Create Function" in the top right corner. This is the create function menu. Click on the button "AWS Serverless Application Repository" and select the alexa-skills-kit-nodejs-factskill template.
Scroll down, edit the application name to something you like, and press the button "Deploy" in the bottom right corner.
Wait until all of the resources have finished being created, and press the button "Test app" in the top right corner. Be advised, some resources do not load instantly, so wait a bit to be sure that all has been created.
Now that we have the app set up, click on the left side panel, and press the button called "Functions"
You should see your Lambda Function.
Step 5- Code SetupPress on the function name of the app you just created.
Scroll down until you see your function code and paste in this code, or just paste in the main code at the bottom of the page.
Locate the file "package.json" in the left panel of the code editor, and double click to open it. Edit the description and name property to fit your own skill.
{
"name": "{insert name}", // name here (delete this)
"version": "2.0.0",
"description": "{insert description}", // description here (delete this also)
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"alexa",
"skill",
"fact"
],
"author": "Amazon.com",
"license": "Apache-2.0",
"dependencies": {
"ask-sdk": "^2.0.0"
}
}
Scroll to the top of the page, and press the button labelled "Save". Next, copy the ARN above the "Save" Button
Almost there, just one last step!
Step 6- Linking the AWS Function to the Alexa SkillRemember the Alexa Developer Console tab? Go ahead and open it. Navigate to the "Endpoint" menu in the left side panel. Click on the radio button labelled "AWS Lambda ARN". Remember that ARN we copied earlier? Paste that ARN into the default region box.
Press the button in the top left called "Save Endpoints"
Congratulations! You now have an Alexa Skill!
If you plan to publish this skill to the store, please credit me or leave a link to this Hackster project! Thank you!
Made with ❤️ by Shranav Palakurthi
Comments