Skip to content

This is a tutorial for creating a basic Alexa skill. (No Alexa Required)

Notifications You must be signed in to change notification settings

luciencd/alexatutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 

Repository files navigation

Alexa Tutorial

This is a tutorial for creating a basic Alexa skill. (No Alexa Required)

Basic introduction to the Amazon Alexa Presentation

Introduction

My goal for this tutorial is to provide knowledge on how to create a basic voice wrapper for a 3rd party service which has a REST API.

This tutorial will show you how to make a voice wrapper for YACS, the RPI course scheduler. It has a good REST API service, which returns useful information.

There are two parts to this project:

1: The Alexa Skills kit "front-end", which defines how the Alexa should convert the voice command into a request JSON object that gets sent to the backend.

2: The Amazon Lambda instance, which takes in a request object from the Alexa Skills Kit instance, and interprets it based on its intent and arguments; its main file (lambda_function.py) serves as a wrapper function to interact with any 3rd party API.

Getting Started

AWS Lambda "Backend" Setup

Create an AWS account with a free trial with your education email account @.edu. AWS FREE TIER LINK

Open Amazon Web Services Dashboard. AWS Dashboard

Open Amazon Lambda Dashboard Amazon Lambda Dashboard

Click on blue button "Create a Lambda Function" call it rcostest.

Search through the sample blueprints by looking up "Alexa". Select the alexa-skills-kit-color-expert-python one. Press next.

You should see this: Image of rcostest

Then clone this repo, and find the YACSwrapper file.

It should contain:

YACSwrapper
│
└───Alexa
│   │   IntentSchema.txt
│   │   SampleUtterances.txt
│   │   LIST_OF_COURSES.txt
│   
└───Lambda
│   │   lambda_function.py
│   │   YACSwrapper.py
│   │
│
└───Builder
    │   builder.py

Select lambda_function.py + YACSwrapper.py and archive them. Then upload the ZIP file in this way:

Image of zip Upload

Now, whenever the Alexa hears you say an intent, it will direct it directly to your lambda function(lambda_function.py), which will send a function call to YACSwrapper.py, which will call the YACS API. Once you get data back from YACS, you create an output phrase, and send it back to lambda_function.py. That will then get sent all the way back to the Alexa itself in the form of a vocalized sentence.

Now you are finished setting up the backend to your alexa service.

Alexa Skills Kit "Front-end" Setup

Now onto the "front-end" of the service.

We are trying to interact with YACS on a vocal basis. What functions do we need?

  1. A basic function that tells you how many seats are available in a class.

  2. A function which tells you if a set of classes has any conflicts.

I'm sure there are more possibilities, but these are the two we will focus on.

Setting up the Intent Schema, Custom Slot Types, and Sample Utterances.

In order for the "front-end" to work properly, you need to define what kind of things people will be asking.

When someone asks alexa a question, the phrase is divided into three parts:

  1. Skill Name

  2. Intent

  3. Slots

The skill name is self explanatory.

The intent is the "function" that alexa thinks you are trying to invoke.

The slots are the "arguments" to the intent that alexa binds to particular parts of the question.

Anatomy of a skill request

Now, we need to bring all the necessary information into the right places in the Alexa Skills Kit.

First, goto Alexa Skills Kit and press the yellow button "Add a new Skill"

You should see this: Alexa Skills Kit Pic

Fill out the information, and click next.

Alexa Skills Kit pic 2

Paste the intentSchema.json into the first box.

Paste the sampleUtterances.txt into the second box.

Now we must create a custom speech datatype for our "slots". We will call the list of possibilities LIST_OF_COURSES and press the Add Slot Type to add all the courses in the LIST_OF_COURSES.txt file. This way, the alexa will know to bind courses to the slot when it gets passed to Amazon Lambda instance.

This list of classes (LIST_OF_CLASSES.txt) is generated by running the Builder/builder.py file, to make sure the data is current.

Open /YACSwrapper/Alexa/intentSchema.json

Copy and Paste it into the top box

Open /YACSwrapper/Alexa/LIST_OF_COURSES.txt

Copy and paste in into the custom slot types as LIST_OF_COURSES.

Open /YACSwrapper/Alexa/sampleUtterances.txt

Copy and paste it into the bottom box.

Press Save and continue.

arn

You should see the above field, which is asking you to bind the Alexa skill to the Amazon Lambda instance (the backend we made earlier).

Paste the arn you get from the top right corner of the Lambda Management Console into the input box.

Testing

We have reached the point where we can test if the backend is producing the right inputs. Move on to the Testing portion.

Paste both of these commands into here: You should see the input and output of the Amazon Lambda instance.

Testing framework

How many seats are left in Microbiogy Can I take Introduction to biology, Observational Astronomy, RCOS, and Software Design and Documentation

This is a good way to test your app without requiring an actual alexa. It also acts as an indicator of what you want to say to the alexa if you do have once. It is also great for debugging, as you can copy the left hand json into a test environment in the Amazon lambda framework.

Publishing information

We are not going to cover this as it is very complex, and annoying. Amazon likes to have a stlye guide that all published apps abide by.

Fixes:

Someone make a pull request to ensure any extension to this skill will conform to the Amazon Skill publishing requirements.

Build tools:

Because the Custom Slot type Course is time-dependant, you have to build this project every semester, to reimport all the courses from YACS.

Builder/build.py

Presentation notes Feb 25th

Problems people encountered include:

Alexa not working with RPI wifi , solution: use iphone hotspot. AWS Triggers (alexa not there originally.), solution: refresh AWS lambda function trigger and role, solution: select "Create New role from templates" then in the below input bar, type alexa, then select "simple microservices permissions"

Alexa Skills Kit: during the configuration step, you must make sure your AWS lambda instance is hosted in North Virginia.

New bug which did not appear during testing. LIST_OF_COURSES contained duplicates, and custom slot types cannot handle duplicates. Solved by making set from YACS api in build tool.

Todo: add th

Bonus

Fork the repo to accept 5, 6, 7 possile courses. Add functionality and improve the tutorial.

About

This is a tutorial for creating a basic Alexa skill. (No Alexa Required)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages