Professional Documents
Culture Documents
A B O U T T HE A U T H O R
DARRY L
BAR T L E T T
job: Front-end developer
areas of expertise:
JavaScript, PHP, mobile
development
t: @darrylabartlett
ALEXA SDK
CREATE AN ALEXA
SKILL FOR YOUR SITE
Darryl Bartlett demonstrates how you can use the Alexa SDK to
communicate with your website content
Many of us now have some kind of voice WHAT WILL I NEED?
assistant around the home, whether it be an You will need to start by registering for an Amazon
Amazon Echo, Apple HomePod or a Google Home. It Developer account (developer.amazon.com) and an
seems that voice is going to have a huge impact on AWS account (aws.amazon.com).
the way we go about our daily lives and as web Firebase will be used to store our user input,
developers we need to ask ourselves, what are the so make sure you sign up for a Firebase account
ways we can implement voice into our websites and (firebase.google.com). We will also be using the News
web applications? API to get the latest news stories, so get yourself a
In this tutorial, we are going to be building a free API key at newsapi.org.
simple Alexa skill that updates the news content on
a website. The category type will depend on the voice INTENTS, UTTERANCES AND SLOTS
input by the user. It would help if you have some Once you are set up, navigate to developer.amazon.
experience with AWS already but there is a lot of com/alexa/console/ask and click on Create Skill. The
documentation out there to help you out if you get in first thing we need to do is set up Intents, Utterances
a pickle. and Slot Types inside the Alexa Developer Console.
82 december 2018
Alexa SDK
Above Here are the utterances we have setup inside the Alexa Developer Console for our skill.
Feel free to add more
december 2018 83
PROJECTS Alexa SDK
GOING FURTHER WITH then we can move onto the function itself. We won’t
be using the built-in code editor for this project;
instead we will be writing out the functions locally
ALEXA SKILLS and then uploading a zip file. Make sure you copy the
contents of the index.js file inside the Lambda editor,
as we will paste this inside our local project.
If you want to learn more about Alexa skills development
after this tutorial, then check out the compiled list of CREATE A LOCAL PROJECT
resources below. We will start by creating a new Node project locally.
Inside our own index.js file, we will paste the contents
we just took from Lambda. We need to import
Firebase and the Alexa SDK using NPM.
84 december 2018
Alexa SDK
’ContentUpdate’: function() {
var categoryType = this.event.request.intent.slots.
category.value;
if(Firebase.apps.length === 0) {
Firebase.initializeApp(config);
}
Firebase.database().ref(‘/’).set({
preference: categoryType
}).then((data)=>{
Firebase.app().delete().then()
}).catch((err) => {
console.log(err);
})
this.emit(‘:ask’, ‘you updated to ‘ + categoryType);
},
After you save your index.js file, you will need to zip
up the project. Navigate to the project folder from
the command line and type the following command.
zip -r index.zip *
Top The Alexa simulator
is a great way of testing
Head back to your function inside Lambda and scroll your skill on your machine
without needing an Amazon
down to the Function Code section. From the drop- You will also need to enter your News API key from
Echo device
down box for code entry type, select ‘Upload a .zip newsapi.org on line 11 of the main.js file.
file’. You will now be able to upload your zip file. Above Here is what
the final HTML page will
Before you test your project inside the Alexa var myAPIKey = “<YourAPIKey”>; look like. It will display
the category that you
simulator, take the ARN on the top right of the
requested through Alexa
Lambda page and input this inside the Endpoint If you now open the index.html file, it should load in
section of the Alexa console. To test your skill, all some news stories from your chosen category. Every
you need to say is ‘Open web update’ and Alexa will time you tell Alexa to update with a new category
respond with ‘Welcome to web update’. If you now (sport, technology, business or politics), the news
say ‘Update to sport’, Alexa should say ‘you updated story category on the page will change.
to sport’. The word ‘sport’ should also appear under
preference inside your Firebase database. CONCLUSION
This is only a small example of what you could
NEWS PAGE achieve with Alexa and hopefully gives you a good
Finally, download the news page I created (index. foundation for any future voice projects. You could
html). Get the file from https://netm.ag/2EjFwQb always add in more slot values to get more categories
inside the Alexa Project – HTML folder. from the API or even update the project so that it
Open up the main.js file and enter in your own pulls in your own website news/posts. I can’t wait to
Firebase configuration details on lines 1-8, like we see how web and app developers will include Alexa in
did earlier in the tutorial. their projects.
december 2018 85