introduction to building alexa skills and putting your amazon echo to work

48
INTRODUCTION TO BUILDING ALEXA SKILLS AND PUTTING YOUR AMAZON ECHO TO WORK. ABE DIAZ

Upload: abe-diaz

Post on 21-Apr-2017

1.399 views

Category:

Devices & Hardware


0 download

TRANSCRIPT

Page 1: Introduction to building alexa skills and putting your amazon echo to work

INTRODUCTION TO BUILDING ALEXA SKILLS AND PUTTING YOUR AMAZON ECHO TO WORK.

ABE DIAZ

Page 2: Introduction to building alexa skills and putting your amazon echo to work

@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]

Page 3: Introduction to building alexa skills and putting your amazon echo to work

@abe238

Page 4: Introduction to building alexa skills and putting your amazon echo to work

@abe238

HOW DID I END UP HERE?

Page 5: Introduction to building alexa skills and putting your amazon echo to work

@abe238

TEXT

http://bit.ly/alexatwilio

Page 6: Introduction to building alexa skills and putting your amazon echo to work

@abe238

TEXT

ME: “ALEXA, OPEN SMS AND TEXT MY WIFE “I LOVE YOU”!”

WIFE: “HEY, WHO THE HELL IS

TEXTING ME!”

ALEXA: “OK”

Page 7: Introduction to building alexa skills and putting your amazon echo to work

@abe238

GOT HOOK?

Page 8: Introduction to building alexa skills and putting your amazon echo to work

@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

Page 9: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 10: Introduction to building alexa skills and putting your amazon echo to work

@abe238

WHAT IS AN ALEXA

SKILL?

Page 11: Introduction to building alexa skills and putting your amazon echo to work

@abe238

SKILL SERVICE

Page 12: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 13: Introduction to building alexa skills and putting your amazon echo to work

@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?

Page 14: Introduction to building alexa skills and putting your amazon echo to work

@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

Page 15: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 16: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

DIRECTLY EDIT YOUR CODE

Page 17: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

UPLOAD YOUR CODE

Page 18: Introduction to building alexa skills and putting your amazon echo to work

@abe238

IF NOT USING AWS LAMBDA

▸ Best Resource: http://bit.ly/alexawalterquesada

Page 19: Introduction to building alexa skills and putting your amazon echo to work

@abe238

SKILL INTERFACE

MODEL

Page 20: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 21: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

WHAT COMPOSES A SKILL’S INTERFACE

Page 22: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA, ASK ONEBUSAWAY, WHERE IS MY BUS?

Me (in the morning)

SAMPLE ALEXA REQUESTINVOCATION NAME

INTENT: FIND BUS INTENT

Page 23: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 24: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

SAMPLE UTTERANCES

The words to be used to invoke a specific intent are called utterances.

Page 25: Introduction to building alexa skills and putting your amazon echo to work

@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)

Page 26: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

USER FLOW (INCLUDING CARDS)

Page 27: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

END TO END USER FLOW

Page 28: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 29: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

SLOT TYPES

Page 30: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

SLOT TYPES

Page 31: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA SKILLS

SLOT TYPES

Page 32: Introduction to building alexa skills and putting your amazon echo to work
Page 33: Introduction to building alexa skills and putting your amazon echo to work

EVERY SKILL IS DIFFERENT

Page 34: Introduction to building alexa skills and putting your amazon echo to work

@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.”

Page 35: Introduction to building alexa skills and putting your amazon echo to work

@abe238

WHAT DO WE NEED TO START?

Page 36: Introduction to building alexa skills and putting your amazon echo to work

@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

Page 37: Introduction to building alexa skills and putting your amazon echo to work

@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

Page 38: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 39: Introduction to building alexa skills and putting your amazon echo to work

@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.

Page 40: Introduction to building alexa skills and putting your amazon echo to work

@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

Page 41: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ACCOUNT LINKING

▸ If you need to authenticate users, Lambda can do so by means of Account Linking.

▸ Account linking uses OAuth 2.0

Page 42: Introduction to building alexa skills and putting your amazon echo to work

@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/

Page 43: Introduction to building alexa skills and putting your amazon echo to work

@abe238

MORE INFO

IFTTT

Page 44: Introduction to building alexa skills and putting your amazon echo to work

@abe238

MORE INFO

BUILD YOUR OWN ECHO

Page 45: Introduction to building alexa skills and putting your amazon echo to work

@abe238

MORE INFO

TEST WITHOUT A DEVICE

Page 46: Introduction to building alexa skills and putting your amazon echo to work

@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)

Page 47: Introduction to building alexa skills and putting your amazon echo to work

@abe238

ALEXA, ASK REWIND AND CAPTURE, WHY IS IT CALLED AMAZON?

DEMO

Page 48: Introduction to building alexa skills and putting your amazon echo to work

@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