How to build custom Alexa Skill for Amazon Echo devices

Written By:

Three years after launching the Echo speakers and paving the way for human-computer speech interactions, Amazon has finally brought its products to the Indian market. The company has launched Echo, Echo Dot, and Echo Plus with built-in Alexa which is the main feature of these devices.

How to build custom Alexa Skill for Amazon Echo devices

Alexa is basically Amazon's voice service and the brain behind millions of devices including Amazon Echo. Alexa provides a wide range of capabilities or "skills" that enable customers to create a more personalized experience. And the good news is that normal users can also create these skills even if they have no knowledge about coding.

Amazon is offering Alexa Skills Kit via which designers, developers, and brands can build engaging skills and reach new customers. Basically, ASK is a collection of self-service APIs, tools, documentation, and code samples that make it fast and easy for you to add skills to Alexa. With ASK, you can leverage Amazon's knowledge and pioneering work in the field of voice design.

Meanwhile, there are already thousands of skills available in India from brands like Saavn, Zomato, Times of India, Ola, and Goibibo as well as many other innovative designers and developers.

In any case, today we will be looking at how to build a custom skill for the Echo devices.

How to build custom Alexa Skill for Amazon Echo devices

Things to Know

So before getting started, you need to know that there are different types of skills (custom, smart-home, video and more) and these now require different types of services:

As such for a custom skill, you code either an AWS Lambda function or a web service:

AWS Lambda (an Amazon Web Services offering) is a service that lets you run code in the cloud without managing servers. Alexa sends your code user requests and your code can inspect the request, take any necessary actions (such as looking up information online) and then send back a response. You can write Lambda functions in Node.js, Java, Python, or C#.

Alternatively, you can write a web service and host it with any cloud hosting provider. The web service must accept requests over HTTPS. In this case, Alexa sends requests to your web server and your service takes any necessary actions and sends back a response. You can write your web service in any language.

Regardless of how you create your service, you also create a custom interaction model for the skill. This defines the requests the skill can handle and the words users can say to invoke those requests.

Thant being said, let's get down to building you first Alexa skill. Do check out the video tutorial below as well.

Stay tuned to GizBot for more updates!

Step1: Preparing Your Alexa Skill

To begin with, you can prepare your Alexa Skill on the Amazon Alexa Developer Portal. Visit developer.amazon.com/alexa and sign in to begin.

1. Click the "Alexa" button at the top.

2. Click Get Started button under the Alexa Skills kit to begin.

3. Next, on the top right of the screen, click Add a New Skill.

This will get you to the first page of your new Alexa skill.

4. Fill out the Skill Information screen.

Skill Information: This is the information used to identify your skill and how your skill will interact with Alexa. It's pretty straightforward to get started with.

Fill in these fields; Skill Type is "Custom Interaction Model" so we can define the skill behavior, Name is "Test" to easily identify the skill, and Invocation Name or the phrase we'll use to get Alexa to execute our skill is "Test Bot" - i.e."Hey Alexa, ask Test Bot [a phrase]". Press Next on the bottom right when you're ready.

5. After filling in the information click the Next button to move to the Interaction Model.

6. Click on the Launch Skill Builder Beta button. This will launch the new Skill Builder Dashboard.

Step 2: Prepare Your Interaction Model

Next, the interaction model defines how Alexa will interpret things you ask of her. We're now looking at defining the phrase, sentence or question at the end of "Hey Alexa, ask Test Bot [whatever you'd like]" and how we expect Alexa to parse it.

Intents

Intents can be thought of as different functions that your skill can refer to. They can interpret sentences based on Utterances (see below) and from these utterances can populate slots (variables). We'll cover slots in a future tutorial, for now, let's get our first Intent and Utterance set up:

Our Intent needs an Intent Schema, so we'll make a basic one that just has a "HelloWorld" intent. You can copy the setup on the left. This is going to be linked to a very simple Utterance (function trigger).

Utterances

Utterances are trigger phrases to ask Alexa to refer to a specific intent. In order to trigger our HelloWorld intent, we'll use the phrase,"how are you."

This is all we really need to set up our Interaction Model to begin with. We're now ready to actually write code for our Alexa Skill.

1. In the Skill Builder Dashboard click on the "Add+" button near Intents on the top left corner of the dashboard.

2. In the text box provided, enter the new intent name: GetNewFactIntent., and click the Create Intent button.

3. Add 10-15 sample utterances for your intent. These are the things a user would say to make this intent happen. Here are a few examples: Give me a fact, Tell me a fact, Tell me something, Tell me a space fact.

4. Click on the Save Model button, and then click on the Build Model button.

5. If your interaction model builds successfully, click on Configuration button to move on to Configuration.

In our next step of this guide, we will be creating our Lambda function in the AWS developer console, but keep this browser tab open, because we will be returning here again on this page.

Step 3: Write and Test the Code for Your Skill

Your primary coding task for your skill is to create a service that can accept requests from the Alexa service and send back responses.

For the quickest start, create an AWS Lambda function to host the service for your skill. AWS Lambda is a service that lets you run code in the cloud without managing servers.

Alternatively, you can build a web service for your skill and host it with any cloud provider.

1. Go to http://aws.amazon.com and sign in to the console. If you don't already have an account, you will need to create one.

2. Click "Services" at the top of the screen, and type "Lambda" in the search box. You can also find Lambda in the list of services. It is in the "Compute" section.

3. Check your AWS region. AWS Lambda only works with the Alexa Skills Kit in two regions: US East (N. Virginia) and EU (Ireland). Make sure you choose the region closest to your customers.

4. Click the "Create a Lambda function" button. It should be near the top of your screen. (If you don't see this button, it is because you haven't created a Lambda function before. Click the blue "Get Started" button near the center of your screen.)

5. Choose the blueprint named "alexa-skill-kit-sdk-factskill". Amazon has created a blueprint as a shortcut to getting everything set up for your skill. You can search for a blueprint using the provided search box. This blueprint adds the alexa-sdk to your Lambda function so that you don't have to upload it yourself.

6. Configure your trigger. Click in the dashed box, and select Alexa Skills Kit from the list. If you don't see Alexa Skills Kit on the list, jump back to step 2.

7. Configure your function. This screen is where Amazon will enter the important parts of the Lambda function. These values will only ever be visible to you, but make sure that you name your function something meaningful. "SpaceFacts" is sufficient if you don't have another idea for a name.

8. Copy and paste the provided code into the Lambda function code box. Delete the contents of the code box, and paste the contents of the new code.

9. Set up your Lambda function role. Amazon provides a detailed walkthrough for setting up your first role for Lambda. If you have done this before, set your Existing role value to "lambdabasicexecution."

10. For this guide, you can skip all of the Advanced settings.

11. Click the Next button to move to the Review screen. The Review screen is a summary of your choices. Click Create Function in the bottom left corner. You will need to scroll down to find Create Function.

12. After you create the function, the ARN value appears in the top right corner. Copy this value for use in the next section of the guide.

Step 4: Connect Your Voice User Interface To Your Lambda Function

Now we need to connect those two pieces together.

1. Go back to the Amazon Developer Portal and select your skill from the list. You may still have a browser tab open if you started at the beginning of this tutorial.

2. Open the "Configuration" tab on the left side.

3. Select "North America" or "Europe" as your geographical region. IMPORTANT: Make sure you select the same region that you created your Lambda in. Remember, Alexa skills using AWS Lambda can only run in N.Virginia (North America) and Ireland (Europe).

4. Select the "AWS Lambda ARN" option for your endpoint. You have the ability to host your code anywhere that you would like, but for the purposes of simplicity and frugality, we are using AWS Lambda.

5. Paste your Lambda's ARN (Amazon Resource Name) into the textbox provided.

6. Leave "Account Linking" set to "No." For this skill, no need to do Account Linking.

Step 5: Beta Test Your Skill (Optional)

Once your skill is finished, you have the option of setting up a beta test for your skill. With a beta test, you can make your skill available to a limited group of testers that you have personally selected, rather than to the general public.

1. Go back to the Amazon Developer Portal and select your skill from the list. You may still have a browser tab open if you started at the beginning of this tutorial.

2. Open the "Test" tab on the left side.

3. Test your skill with the Service Simulator. To validate that your skill is working as expected, use the Service Simulator. In the Enter Utterance text box, type "give me a fact"

Step 6: Submit Your Skill

When you are ready to make your skill public, submit it for certification. If your skill is currently in a beta test, you can still proceed with certification.

1. To proceed to certification, first test your skill against the submission checklist. This checklist includes the tests performed by Amazon's certification team, so passing all of these tests can speed up the certification process.

2. When you are ready for your skill to be made public, and you have ensured that your skill fulfills the requirements on the certification checklist, submit your skill for certification.

Conclusion

Once your skill is published, Amazon customers will be able to see it in the Alexa App and choose to enable and use it.

However, you can (and should) continue to work on your skill, enhancing its features, fixing any problems, and improving the experience for your end users. For recommendations for ongoing skill development and when you need to re-submit the skill, see the "Creating a New Version of a Live Skill" section in Submitting the Skill for Certification.

Stay tuned to GizBot for more updates!

Read More About alexa | Amazon Echo | speakers | accessories | apps | news

Please Wait while comments are loading...
Recommended Stories
Opinion Poll

Stay updated with latest technology news & gadget reviews - Gizbot