An Amazon Alexa skill that answers a user's weather questions:
What technologies will we be using?
Even if you already have an amazon/aws account you will need to follow these steps. Only if you already have an Amazon Alexa Developer account can you skip this section
-
Go to Amazon Alexa Console
-
Click "Create your Amazon account"
-
Fill out the required information (you can skip the phone number step)
-
Click the "Alexa Skills Kit" if the signup asks for your interests:
- When you are done, you should be able to navigate to this screen if you click the "alexa developer console" in the top left of the screen:
- Keep this tab open
In another tab do these steps:
-
Go to the Sign Up
-
Fill our the required information (you will need to verify your account via the email)
-
When done, hit submit and go to the email you used and click on the Account Activation link
-
When you have verified your email, login to ensure
-
Keep this tab open
In this section we will walk through the process of setting up your first Alexa Skill!
- If not already, login to the Alexa Developer Console and go to the homescreen by clicking the Alexa Developer Console logo in the top left. You should be here:
- Click "Create Skill" Button
- Name your skill
Weather Skill
- In the "Choose a model to add to your skill" section, select
Custom
tile
- In the "Choose a method to host your skill's backen resources" section, select
Alexa-Hosted (Python)
tile
- Click "Create skill" button
- In "Choose a template to add to your skill" screen you'll want to click the "Import skill" button:
- For the Git repository URL use:
https://github.com/TechContentRepo/AlexaWeatherSkill.git
- Click import
- You should get a loading screen that says it is creating your Alexa skill (It took a minute to create for me)
- That's it! Your skill should be imported which means we'll be programming from here on out!
There is a lot here and it's understandable that it'll be confusing, but we'll walk you through everything you need to use!
The "Invocation" is what someone needs to say in order to interact with an Alexa Skill.
- On the left, click on the "Invocation" tab
- For our skill we are going to use
weather app
for the Invocation - Click the "Save Model" button at the top:
The Interaction Model is the logic that defines the voice interface that the user interacts with an Alexa Skill. Here is some verbiage that we will use throughout this portion:
- Intent - Represents an action that fulfills a user's spoken request. They can optionally have arguments called slots.
- Sample Utterances - A set of likely spoken phrases that are mapped to a specific intent.
- Slots - a "variable" within an intent/utterance. There are some built-in amazon slots, but you are able to define your own if you'd like.
Now let's build our own Interaction Model!
- On the left, Click "Interaction Model" and then click on the "Intents" sub-item
- Click on the "Add Intent" button:
- Our intent is going to be called
CurrentWeatherIntent
because we want to have our skill tell the user what the current weather is. - Click "Create custom intent" button.
- Now we need to add a Sample Utterance. Let's do one that looks like this
What is the weather in {place}
. Make sure to click the "+" button or it won't be added!
- Now we need to create an Intent slot for
{place}
. To do this, go to the "Intent Slots" section at the bottom and create an intent that looks like this:
This treats {place}
as a variable that can take different values depending on what the user says. Make sure to click the "+" button or it won't be added!
- Click the "Build Model" button at the top:
This will take a second, but just wait until you get a "Full Build Successful" notification at the bottom to ensure there were no issues.
Now that we've built our skill to accept inputs we need to write the code that takes those inputs and does what we want with them!
- On the top of the Alexa Developer Console click the "Code" tab. You will see an editor that has a file called
lambda_function.py
. This file already has most of the code that we need to build the weather app. - On
line 25
paste your weather API key here. To do this, go back to your WeatherAPI dashboard and generate a free tier API key. - Now scroll down to
line 64
. Here you will see our Intent Hander. This does exactly what you would expect, it handles the intent that is passed into it. Read through thedef handle(self, handler_input)
to understand what is going on. - You will notice that the
speak_output
is left blank and has an example for how to create an output. Feel free to create your own output or use the following:
speak_output = "The current temperature in " + str(api_response['location']['name']) + " is " + str(api_response['current']['temp_f']) + " degrees Fahrenheit"
- Click the "Deploy" button and that's it!
That's right, now we get to finally see our Alexa Skill in action!
- Navigate to the "Test" tab on the top of the developer console
- Enable testing by clicking the dropdown and selecting "Development"
- Type into the input:
Open weather app
- this opens our app using its Invocation
- Now you can ask our skill the weather using the Sample Utterance we outlined:
What is the weather in Chicago
Voila! Congratulations on creating your first Alexa Skill!
Now that you've implemented Current Weather, you can implement Future Weather or Historical Weather functionalities. The base code is already there, and the intents are already created for you. Take a look at them, and use what you learned from current weather to enhance your Alexa skill. Some notes:
- For simplicity, "tomorrow" is the only available date for FutureWeatherIntent.
- Because of API free tier limitations, you will only be able to get historical data from the last 7 days.