introduction to building alexa skills and putting your amazon echo to work
TRANSCRIPT
INTRODUCTION TO BUILDING ALEXA SKILLS AND PUTTING YOUR AMAZON ECHO TO WORK.
ABE DIAZ
@abe238
WHO’S THIS GUY?
Was: Developer -> Evangelist ->Product
Manager
Now: Technical Program Manager @
‣ Alexa Enthusiast (not an Expert)
Contact Info: Twitter: @abe238 [email protected]
@abe238
@abe238
HOW DID I END UP HERE?
@abe238
TEXT
ME: “ALEXA, OPEN SMS AND TEXT MY WIFE “I LOVE YOU”!”
WIFE: “HEY, WHO THE HELL IS
TEXTING ME!”
ALEXA: “OK”
@abe238
GOT HOOK?
@abe238
BEFORE I FORGET… WHO WANTS SOME FREE STUFF?
WANT AN ALEXA ENABLED DEVICE?
▸ 1) Do this TODAY!
▸ bit.ly/alexacheckin
▸ Event Name: CODEDAY
▸ Within 30 days fill this out:
▸ bit.ly/alexabootcamp
@abe238
ALEXA SKILLS
WHAT ARE THESE SKILLS YOU TALK ABOUT?
▸ Alexa provides a set of built-in capabilities, referred to as skills. For example, Alexa’s abilities include playing music from multiple providers, answering questions, providing weather forecasts, and querying Wikipedia.
▸ The Alexa Skills Kit (ASK) lets you teach Alexa new skills. Customers can access these new abilities by asking Alexa questions or making requests. You can build skills that provide users with many different types of abilities.
▸ There are two main types of skills Custom Skills and Smart Home Skills. This session will focus on Custom Skills.
@abe238
WHAT IS AN ALEXA
SKILL?
@abe238
SKILL SERVICE
@abe238
ALEXA SKILLS
ALEXA SKILL SERVICE
▸ A skill service is nothing but a piece of code accessible on the internet that responds to commands sent out by Alexa enabled devices.
▸ In theory you can write (and host) your code in any language as long as you are able to handle http requests.
@abe238
ALEXA SKILLS
ALEXA SKILL SERVICE
▸ Typically this code is written in three preferred languages:
▸ Why those three languages?
▸ Because these are the ones supported in AWS Lambda’s code editor.
▸ Why do I care about AWS Lambda?
@abe238
ALEXA SKILLS
WHY USE AWS LAMBDA?
Using an AWS Lambda function for your service eliminates some of the complexity around setting up and managing your own endpoint:
▸ You do not need to administer or manage any of the compute resources for your service.
▸
▸ You do not need an SSL certificate.
▸ You do not need to verify that requests are coming from the Alexa service yourself. Access to execute your function is controlled by permissions within AWS instead.
▸ AWS Lambda runs your code only when you need it and scales with your usage, so there is no need to provision or continuously run servers.
▸ Alexa encrypts its communications with Lambda utilizing TLS.
▸ For most developers, the Lambda free tier is sufficient for the function supporting an Alexa skill. The first one million requests each month are free. Note that the Lambda free tier does not automatically expire, but is available indefinitely.
#SERVERLESS
@abe238
ALEXA SKILLS
CODE MANAGEMENT WITHIN AWS LAMBDA
How do you upload or manage your code in AWS Lambda?
▸ Write your code directly in the code editor in the Lambda console (Node.js or Python).
▸ Write your code offline and copy and paste it into the Lambda console editor (Node.js or Python).
▸ Write your code offline and upload it to the Lambda function in a zip file (Node.js, Python, or Java).
▸ Use the Eclipse IDE and the AWS Toolkit for Eclipse (Java). For details, see Using AWS Lambda with the Toolkit for Eclipse.
@abe238
ALEXA SKILLS
DIRECTLY EDIT YOUR CODE
@abe238
ALEXA SKILLS
UPLOAD YOUR CODE
@abe238
IF NOT USING AWS LAMBDA
▸ Best Resource: http://bit.ly/alexawalterquesada
@abe238
SKILL INTERFACE
MODEL
@abe238
ALEXA SKILLS
WHAT COMPOSES A SKILL’S INTERFACE
When designing and building a custom skill, you create the following:
‣ A set of intents that represent actions that users can do with your skill. These intents represent the core functionality for your skill.
‣ A set of sample utterances that specify the words and phrases users can say to invoke those intents. You map these utterances to your intents. This mapping forms the interaction model for the skill.
‣ An invocation name that identifies the skill. The user includes this name when initiating a conversation with your skill.
‣ A cloud-based service that accepts these intents as structured requests and then acts upon them. This service must be accessible over the Internet. You provide an endpoint for your service when configuring the skill.
‣ A configuration that brings all of the above together so that Alexa can route requests to the service for your skill. You create this configuration in the developer portal.
@abe238
ALEXA SKILLS
WHAT COMPOSES A SKILL’S INTERFACE
@abe238
ALEXA, ASK ONEBUSAWAY, WHERE IS MY BUS?
Me (in the morning)
SAMPLE ALEXA REQUESTINVOCATION NAME
INTENT: FIND BUS INTENT
@abe238
ALEXA SKILLS
INTENTS‣ There are Custom and Built-In Intents
‣ Built-In Intents help abstract a lot of the logic for default actions like cancelling or repeating a prompt.
@abe238
ALEXA SKILLS
SAMPLE UTTERANCES
The words to be used to invoke a specific intent are called utterances.
@abe238
ALEXA SKILLS
CARDS (WITHIN THE APP)
Cards are also part of a skill’s interface. Here is an example of a skill card within the Alexa mobile app.
ALEXA, GET HIGH TIDE FOR SEATTLE FROM TIDE POOLER NOTE: CARDS CAN
HAVE TEXT OR IMAGES (JPG, PNG)
@abe238
ALEXA SKILLS
USER FLOW (INCLUDING CARDS)
@abe238
ALEXA SKILLS
END TO END USER FLOW
@abe238
ALEXA SKILLS
SLOT TYPES
‣ To avoid having to define hundreds of sample utterances, the concept of slot types was created.
‣ This allows us to insert a variable in the sample utterances descriptions that can handle multiple values.
@abe238
ALEXA SKILLS
SLOT TYPES
@abe238
ALEXA SKILLS
SLOT TYPES
@abe238
ALEXA SKILLS
SLOT TYPES
EVERY SKILL IS DIFFERENT
@abe238
TYPES OF SKILLS
WHAT PATTERN DOES MY SKILL FIT?
Every skill is different, but there are similar patterns across skills.
▸ Fact Skills:
▸ How to Skills:
▸ Decision Trees:
▸ Other: Audio Player, Games, Custom
“ALEXA, OPEN CAT FACTS”
“ALEXA, ASK MY BARTENDER HOW TO MAKE A MOJITO”
ME: “ALEXA, ASK PLAY HOOKY IF I SHOULD STAY IN BED” ALEXA: “IS IT RAINING OUTSIDE?”
ME: “YES” ALEXA: “OK, IS ELLEN PLAYING ON THE TV?”
ME: “NO” ALEXA: “THEN I THINK YOU GET GET OUT OF BED.”
@abe238
WHAT DO WE NEED TO START?
@abe238
INGREDIENTS FOR A SKILL
WHAT DO I NEED TO BUILD A SKILL
▸ Amazon Developer Account (developer.amazon.com)
▸ App Configuration
▸ AWS Account (aws.amazon.com)
▸ Lambda function:
▸ Easy: https://s3.amazonaws.com/memodoring-cloudformation/cloudformation.json
▸ Region: US East (N. Virginia) This is the only region with Alexa skills support.
▸ Resource: bit.ly/alexa123cloud
@abe238
DEMO
CREATING LAMBDA FUNCTIONS FROM A TEMPLATE
▸ Create a stack using the cloud formation template.
▸ You will see 3 lambda functions created in your console. (Go to: Services > Compute > Lambda)
▸ For each Lambda function, create a trigger (Alexa Skill) and test (Start Session).
▸ References for templates (github.com/alexa):
▸ bit.ly/alexa123fact
▸ bit.ly/alexa123decision
▸ bit.ly/alexa123howto
@abe238
DEMO
CREATING LAMBDA FUNCTIONS FROM SCRATCH
▸ Select name, runtime
▸ Code:
▸ inline
▸ zip file
▸ S3 - Use this if planning to plug into CI engine for deployments
▸ Role:
▸ Basic Execution will cover most scenarios
▸ If planning to store values, then select micro service or create a custom role with dynamodb permissions.
@abe238
DEMO
DEALING WITH SESSIONS
▸ Every time a user invokes a skill name, a session is created.
▸ While inside the skills, if the user is being reprompted for input, the same session remains active.
▸ Because of that, the recommendation is to handle long term sessions by persisting data separately in a data store like DynamoDB.
@abe238
ALEXA DYNAMODB
▸ Amazon DynamoDB
▸ Use DynastyJS
▸ https://www.npmjs.com/package/dynasty
▸ Promise-based DynamoDB API
▸ 5 reads/writes per second by default
▸ Reference: http://bit.ly/alexadynamopersistence
@abe238
ACCOUNT LINKING
▸ If you need to authenticate users, Lambda can do so by means of Account Linking.
▸ Account linking uses OAuth 2.0
@abe238
MORE INFO
WHAT CAN YOU DO WITH ALEXA?
▸ Start your car remotely: http://fortune.com/2016/08/18/hyundai-genesis-amazon/
▸ Open your door lock: http://fortune.com/2016/07/28/alexa-amazon-august-smart-lock/
▸ Where’s my stuff? http://www.geekwire.com/2016/amazon-adds-package-tracking-alexas-abilities/
▸ Alexa talks back: http://mashable.com/2016/09/08/amazon-echo-push-notifications/
@abe238
MORE INFO
IFTTT
@abe238
MORE INFO
BUILD YOUR OWN ECHO
@abe238
MORE INFO
TEST WITHOUT A DEVICE
@abe238
MORE INFO
THINGS YOU CAN’T DO
▸ Collect sensitive data: Health, PII
▸ Be respectful of Brands (“Harry Potter”)
▸ For now, there are no such notifications.
▸ Can’t actively listen to mics (e.g. make calls through the device)
@abe238
ALEXA, ASK REWIND AND CAPTURE, WHY IS IT CALLED AMAZON?
DEMO
@abe238
REMEMBER TO DO THIS TODAY
WANT AN ALEXA ENABLED DEVICE?
▸ 1) Do this TODAY!
▸ bit.ly/alexacheckin
▸ Event Name: CODEDAY
▸ Within 30 days fill this out:
▸ bit.ly/alexabootcamp