Intro: Make Alexa Skills With Cloud9- No Credit Card or Hardware Required
Hello, today I am going to be showing you how to create your own Amazon Alexa skill using Cloud9. For those of you that don't know, Cloud9 is an online IDE supporting lots of different languages and it's one hundred percent free - no credit card required. An Alexa skill is like an app but for Alexa devices.
I have always loved programming and voice assistants but only recently took up programming the Amazon Echo. My problems are I don't know a lot of node.js, so I will be programming in python for this tutorial and, being a secondary school student I don't have a credit card, meaning I'm unable to use AWS lamda. The way I solved this problem was to use Cloud9.
I hope you enjoy this tutorial. If you get stuck anywhere try the images as I have tried to add hints in the correct places and if you are still stuck please feel free to add a Question or comment.
(Thanks to HeikoAL on Pixabay for the cover image)
Step 1: Sign Into Cloud9 and Amazon Developer Console.
To make our skill, we will need to create the main logic for the skill in python on Cloud9 and the way it integrates with Alexa on the Amazon Developer Console.
You will most likely need a Cloud9 account already for this to work as recently Amazon took over Cloud9, integrating it into AWS, however it appears to be possible to sign in with Github, Bitbucket or Google on the old platform which is what we need to do.
Visit this website: https://c9.io/login and login.
2. Amazon Developer Console
Now visit https://developer.amazon.com and sign in at the top right corner. Now click on Alexa and then Your Alexa Dashboards in the top right. You should see an older looking screen like the one above right. We now need to click on Get Started in the Alexa Skills Kit box.
Step 2: Set Up the Alexa Skill in the Amazon Dev Console
Now we are going to set up the skill in the Amazon server. If you already know how to do this, you needn't read this and you may skip on to the next step.
Click on Add a New Skill and you should be presented with a screen like the one above.
In the radio buttons at the top, we should choose Custom Interaction Model
Now choose the language of your skill. It is important to choose English UK if your amazon account has a UK address as testing will not work on a real life echo device if you choose US. It may still work on Echoism though.
Now you should enter the name and invocation name of your skill. I would recommend these are the same for convenience. The name is what a user would see in the Alexa app and the invocation name is what a user would say when triggering the skill, for example: Alexa, ask "Invocation name" about the weather. For my first skill I named them both Test.
Our skill will not be using the final three things so they can be left alone.
Now you need to click save and next. The Dev console may reformat slightly here but it won't lose any data.
Step 3: Interaction Model
You should now be on the interaction model tab of the console. This is where we tell Alexa how we would like it to interpret our commands. Choose the Launch Skill Builder Beta option.
We now need to set up an intent for our skill which is like a function it performs. Click the Add an intent button and enter a suitable name. This can be anything and does not need to be known by the user, however we will need it for the programming later on. I have named my HelloWorld.
Now we should add some utterances which are things a user might say if they wanted to invoke this. I have typed "for a greeting" and "for a hello" into this box. Make sure to press enter in between. In order to activate this intent, a user will say "Alexa, ask test for a greeting."
Once this has been completed, we now need to press save model and build model at the top. Make sure to save first and then build. The building may take a few minutes.
Finally, we need to click the Configuration button at the top left.
Step 4: Onto Cloud9
At this point we need to return to Cloud9 and build the back end to our skill.
In your dashboard create a new workspace and enter a memorable name. You can add a description if you wish but it isn't necessary. You should also choose Python as the language. Now press create workspace. It will take some time to load but eventually you should be presented with a screen like the above. This is your workspace.
Cloud9 workspaces are ubuntu linux machines which work in a very similar way to a raspberry pi. They have the one advantage that they are hosted. Before we can write our code into this environment, we will need to execute a few commands to get it ready.
1. Upgrade pip: sudo -H pip2 install --upgrade pip
2. Install Flask: sudo pip install flask
3. Install Flask-Ask, the library which interfaces with Alexa: sudo pip install flask-ask
Now we can write our program. Click the green plus at the top and choose New File. Press File, Save and enter a suitable name with .py at the end for example HelloAlexa.py. Now press save. In the next step we will enter the code of our program.
Step 5: The Code!
Now it is necessary to enter the following code, instead of HelloWorld, use your intent name that you created earlier:
from flask import Flask, render_template
from flask_ask import Ask, statement
app = Flask(__name__)
ask = Ask(app, '/')
return statement("Hello, world.")
if __name__ == "__main__":
host = os.getenv('IP', '0.0.0.0')
port = int(os.getenv('PORT', 8080))
app.debug = True
Let's run through the code:
The first three lines import our necessary modules, Flask-Ask, for amazon Alexa and Flask which is a prerequisite of Flask-Ask. The next two lines create app and ask which are like the master variables of our program. In order to access the bits we want to access we need them. Line 6 is a decorator. It says when we receive a call to the web address that our program is running on, if the url contains "HelloWorld" then the following code block will run. The function below the decorator doesn't run any code, it just returns the value Hello, world. The statement() command is needed to convert the string into a form Alexa can understand. Finally, the rest of the code is a way of making sure that our program runs properly on Cloud9. It basically says: if we run this code directly, as in not as a module then the code will listen on port 8080. The app.debug line ensures the code doesn't stop prematurely. If you ever make another application like this on Cloud9, you will always need to remember the last 5 lines or else you will get a "No application seems to be running here" error. The ports Cloud9 uses are 8080,8081 and 8082 so any of these would have been fine.
Make sure to save your code and then continue to the next step.
Step 6: Link Cloud9 to Alexa
Now we need to link our Cloud9 code to our Alexa app in the Dev portal.
Press the green run button in the corner. Now copy and paste the link at the top of your terminal into your web browser. View the image if you can't find it. If you see an orange screen with an Open The Application button, you should click it. You should see a white screen which says Method Not Allowed on it. This may sound bad, however all this means is that Flask-Ask has been configured properly so that only the Alexa service may visit that page. If this has worked fine, return to the Dev Console in Amazon and make sure you are in the configuration tab. Now press HTTPS and paste the URL you just had into the text box that pops up. You can ignore the rest of the settings, just press Save and Next. You should now see a small box asking you about Certificates. Choose the second option, "My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority" and now press Save and then Next.
You should be onto the Test stage now. If you are, that's great progress to the next stage. If not, check you have followed the instructions correctly.
Step 7: Testing!
You should now see a page like the one above. If the i box where it says Please Complete the Interaction Model is set to Disabled, then enable it. We can start by testing the skill on here and then we can try with a real echo device. Go down to the service simulator section and enter one of the utterances you created earlier. Now press Ask Test. You should see some blue text on both sides. The right hand one should contain the words "Hello, World" or some other text that you set your skill to respond with. If your right-hand one contains an error, check that your code is still running and that you typed it in correctly.
Once that works, you can move on to testing it with a real echo device. Make sure the echo device is signed in with the same account and then you should be able to try it. Remember to say "Alexa, ask Test" and then your utterance. If you don't have an echo device then you can use the echo simulator https://echosim.io/welcome You will need to sign in with your Amazon Developer account.
Thank you for reading my Instructable. I hope it worked for you. If you have any questions make sure to post a comment and if you liked it please vote for me in the Voice Activated contest and the first time author contest.