This guide is going to show you how to build an Amazon Alexa Skills in 10 minutes by using python, aws and an information api.
In addition, Amazon is currently running a promotion for giving out Echo for free. In summary:
Find more details here
To see what the final product look like, you will need to download the Alexa app and enable the skill Joke Teller
To Test it, simply say:
It will return you a random joke.
Go through the API list in this link, I will suggest to start from a simple api that returns a sequence. I have picked the icanhazdadjoke api which will randomly return a joke, so my app name will be joke teller.
Click this link for registration, fill in required information. You can use your Amazon account to log in.
Go to here and fill the promotion form.
After login to your development account ,go to this link.
You will see something like this, click Create Skill:
Fill in the required information:
Now you need to set up your Invocation name, which is the name that will active your skill. The name I used here is "joke teller"
After setting the Invocation name, we will need to set up the Intent. Add a new intent with a name. I used the name joke. Intent is something that will response the user's query. As we are only building a simple skill, so we only have one intent without any slots. Examples intent:
After adding few intents, you need to click save model and then build model.
Congratulations, you are almost there.
Now go to Code section -> Open lambda_function, and copy and paste below code to an empty space, change the "joke" to the name of your intent:
class jokeIntentHandler(AbstractRequestHandler):
"""Handler for shouldI."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("joke")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = requests.get("https://icanhazdadjoke.com/", headers={"Accept":"text/plain"}).text
return (
handler_input.response_builder
.speak(speak_output)
# .ask("add a reprompt if you want to keep the session open for the user to respond")
.response
)
This code basically returns a random joke by calling the joke api we just pciked.
It is also worth changing any wording you want to change, I believe you can understand this easily.
Finally, add below code at the end of the section, then click Save and Deploy
sb.add_request_handler(jokeIntentHandler())
You can now test your skill in the test tab to make sure it works. In my scenario, I can say:
"ask joke teller to make me laugh"
Now we can start to publish our skill, go to distribution and fill the basic information.
One thing needs to be careful is the Example Phrases, you will need to make sure the example phrases are in your intent. For example if your intents are:
Then your example phrases can be one or both of below:
Save and Continue when everything is ready, you will also need to fill in both Privacy Section and Availability.
Please use the same example phrases as testing instructions in Privacy Section.
Go to Certification after completing the whole distribution section, Run both Validation Test and Functional test to make sure everything is OK.
And then go to Submission to Submit the skill, you skill will be in the Alexa Skill store after few days.
As you can see it is very simple to create the simple skill, you can be flexible on any of the API to make your skill more fun. According to the terms, you will receive your echo dot in 60 days.