Adding a Custom Skill to Your Alexa!
When I started as a student at Flatiron I had no previous coding experience. I went home at the end of the first week of class and started thinking about the technology around my home. I realized that Alexa, this device I was given as a present, was just sitting there unexplored. I began to wonder exactly how she worked, could I peek under the hood and could I do anything to customize her.
I had remembered poking around on Code Academy and seeing a mini course on how to customize your Alexa by adding “Skills”, which are essentially apps. I also got excited about the prospect of adding my own Skills after realizing that Alexa could be so much more than a bluetooth speaker and my personal weatherman.
So…how do you customize Alexa? I dug a little deeper and realized that Alexa is essentially like a website, with a front end and a back end to work with. The first step you need to take is signing in to or creating an Amazon Developer account.
As of March 27, 2018, Amazon released a new console for the Alexa Skills Kit developer console. What I gathered from reading blogs describing the previous Alexa Skills developer console, that older version was not as streamlined as this new experience. This new console boasts a refreshed user interface and new functionalities.
Great! Thanks Amazon! Now that you have signed in or created your developer account with Amazon, go ahead and click on the Amazon Alexa service, at the top left of your screen. It will take you to the new interface they just launched.
Before we get to creating a new skill for Alexa lets take a look at what exactly Alexa Skills Kit (ASK) are!
What Is the Alexa Skills Kit?
The Alexa Skills Kit (ASK) is where developers can access self-service APIs, code samples, and tools to help you build and add skills to Alexa. The idea here is for developers and brands to create skills that can reach tens of millions of Alexa devices.
Before we start building, lets take a look at what kind of Alexa Skills we can build. Amazon provides some examples of types of Skills, which include: smart home skills, games and trivia skills, flash briefing skills, custom skills, kid skills and skills for the workplace.
Now that we have an idea of what we can build, let’s click on create skill! That will take us to this page!
Time to name your skill! After naming your skill, you will then be taken to this page.
Now choose the custom option for your custom skill.
We then arrive at our skill building page. Lets take a look at some of the functions available to us and talk about the ideas behind each one.
On the left hand side is where we can access all the steps to build our skill. For my first skill I followed Amazon’s fact model where Alexa will give me space facts.
The first step is what’s called “Invocation.” This is where users can say a skill’s invocation name to begin an interaction with a particular custom skill. I will name my invocation “space fact.” So, then as a user, you would begin the interaction with Alexa by saying something like: Alexa, tell me a space fact.
After creating the invocation name, we go to the next tool, “Intent.” What is an intent?
When we think about Intents, we can envision something like buttons on a web page. This intent will take the user input and then execute some code. Many skills can have multiple intents! Here we are using Utterances, which we will need to set, to map to our intent. In this example when I say “Howdy”, Alexa will then execute the HelloIntent.
Let’s add some Utterances for GetNewFactIntent.
Since we are doing a very simple first Skill, we do not need slots for this. But to learn amore about slots please visit here.
Now for some code! Let’s check out the JSON Editor for the intent and utterances I created.
So now that we have our front-end interaction set up we need to connect with the back-end.
Before you go any further, you need to have an AWS account to generate a Lambda function.
What is a Lambda function? It is a server-less computer service from AWS (Amazon Web Services), to connect the front-end interactions to the back-end. In order to do this, you have to provide its ARN (Amazon Resource Name).
Amazon suggests for your first time to select “blue print function” and the Alexa skills option. For my first time skill tutorial Amazon suggests using the “alexa-skill-kit-sdk-factskill” option. I then had to edit the existing code to create my specific function. For example, for my first skill I used example code to create my Lambda function for my space facts which I grabbed from the suggested GitHub page. I pasted the code from Github into my function page and saved it.
After you have your Lambda function written out, you need to get the ARN and paste it in the EndPoint section in the Alexa Developer Console. In your AWS page the function is located in the top right corner:
After you paste the ARN in the correct location in the Alexa developer console, you need to save your EndPoint. Barring no errors you should get a green light!
Now head to your test tab at the top of the page and you can test out your new skill!
Here we can see our JSON input and JSON output at work! Super neat! You can also click on the Voice and Tone tab to play around with Alexa’s tone. They have a “whispering” mode and, I must say, it’s super creepy.
Last step is Launch!
Head to the Launch tab and you will see this page where you need to fill out a Skill name, description and ways to invoke the skill through utterances.
For launching, you need to fill out all the information, include a picture for your logo and then provide testing instructions for the Amazon testing team.
Space Facts is now in certification! I received an email letting me know it will take about 5 business days for Amazon to review and publish my skill to the Alexa store.
BONUS FACTS! Amazon will pay developers for engaging skills!
Recap of how Alexa works (from Code Academy):
- When we said “Tell me a space fact”, our speech audio was sent to Alexa in the cloud.
- Alexa used NLU (Natural Language Understanding) and ASR (Automatic Speech Recognition) technologies to parse our request and figured out that we want to talk to the Space Fact skill.
- It then sent a request in the form of a JSON object. The request includes the intent (SpaceFactIntent) to our Lambda function.
- Our Lambda function received the request and responded to Alexa with another JSON object, which included the output speech in text format.
- Alexa converted this output speech from text to speech and returned the audio to the device where it is played back.
Final Thoughts
Amazon has definitely set up a very user friendly console for creating new Alexa Skills. If I were going to create my next skill from scratch I would want to take a look at how to build Lambda functions. It looks like Code Academy has a quick “how-to” for building Lambda functions that seems like an easy walk through! I really enjoyed being able to look at the code behind Alexa, the feeling of creating a new Skill, seeing the code behind that skill run and then sending it off for certification. My next steps are to really think about how I want to customize my Alexa with skills that fit my life and then build them!
Sources: Code Academy; Amazon Web Services