22
RICK WARGO - FEB 2017 BUILD AN ALEXA SKILL 1

How to Build An Alexa Skill

Embed Size (px)

Citation preview

Page 1: How to Build An Alexa Skill

RICK WARGO - FEB 2017

BUILD AN ALEXA SKILL

1

Page 2: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

WHY BUILD AN ALEXA SKILL?

▸ Alexa Fund (voice technology innovation) - $100M VC Fund

▸ Alexa Prize (must be a full-time university student)

▸ Free Hoodie (just for submitting an approved skill)

▸ Opportunity! (only 10k skills as of Feb 24, 2017)

▸ It’s Fun!

2

Page 3: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

ECHO IS EVERYWHERE

▸ Slide from April 2016 Talk at Hardwired NYC (a monthly event hosted by FirstMark in New York covering the intersection of hardware and software) by Donn Morrill, Sr. Manager of Solution Architecture for Amazon’s Alexa.

https://www.slideshare.net/firstmarkcap/amazons-echo-the-present-and-future-of-alexa-donn-morrill-amazon-firstmarks-hardwired-nyc

3

Page 4: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

WHAT CAN YOU BUILD FOR THE ECHO?

▸ The platform that drives the Echo ecosystem is the Alexa Skills Kit.

▸ Custom Skills - transactional, conversational, audio player

▸ Smart Home Skills - control cloud-connected devices

▸ Flash Briefing Skills - daily content feed for pre-recorded audio clips and text-to-speech updates

▸ There is also the Alexa Voice Service to bring voice capabilities to IoT.

4

Page 6: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

SO…

▸ It is (relatively) easy to create a new basic skill.

▸ It requires lots of diligence to get it right.

▸ AWS Lambda, Node.js, alexa-js, alexa-app-root, and this template make it easier…

▸ by simplifying Behavior Driven Design and making it part of the process.

6

Page 7: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

IN THIS SESSION…

▸ We’ll use:

▸ Tests

▸ Lint

▸ Promises

▸ Node.js

▸ Lambda - serverless compute service (CaaS)

7

Page 8: How to Build An Alexa Skill

ALEXA, ASK CODE CAMP TWEETS…

BUILD AN ALEXA SKILL

for the most popular items.

who tweeted recently?

what were the last three messages?

to tell me the last tweet from Rick.

8

Page 9: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

AMAZON’S QUICK START TUTORIAL

▸ https://developer.amazon.com/alexa-skills-kit/alexa-skill-quick-start-tutorial

▸ Step 1: Sign in to Amazon Web Services (AWS) and create a function

▸ Step 2: Use the Amazon developer portal to configure your skill

▸ Step 3: Test your Alexa skill

Let’s Do This! ‣ Pluralsight has C#/Azure Alexa Training: Developing Alexa Skills for Amazon Echo

9

Page 10: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

DEVELOPMENT RESOURCES

AWS Management Console

▸ AWS Lambda - Server-less compute platform that runs a function as a response to a request. Easy to create JavaScript, Python, Java, C# functions.

▸ CloudWatch - Check logs to see what went wrong (if anything). Also see metrics of skill performing in real time

Amazon Developer Portal

▸ Alexa Skills Kit

Test

▸ Echo Simulator Community Edition (echosim.io)

10

Page 11: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

ALEXA SKILLS KIT - CONCEPTS

▸ Intent Schema - JSON structure defining interactions

▸ Custom Slot Types - lists of specific items (akin to a variable)

▸ Standard Slot Types - growing list of slot types you can use in your skills. Ex:

▸ DATE, DURATION, NUMBER, TIME

▸ Animal, Book, Color, Dessert, Event Type, Festival, Game, Movie, Sport

▸ Sample Utterances - connects intents to likely spoken phrases (be verbose)

▸ alexa-utterances makes it easy to be verbose through alternation (in alexa-js)

11

Page 12: How to Build An Alexa Skill

Twitter API

User

Voice Request Audio StreamCode-Camp-Tweets

Skill

Lambda

JSON Request

Node.js

JSON Response (SSML+Card)

Response (Audio)

Response (Text/Graphics)

Audio Response

App/Web

JSON Response (statuses)

GET search/tweets

BUILD AN ALEXA SKILL

USER INTERACTION FLOW

12

Page 13: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

BRAINSTORMING - PRE-VISUALIZE YOUR SKILL

▸ Q: What's the latest news?

▸ A: The last 1 tweet was: Rick Wargo tweeted: Join me this Sat at 11:30am - we'll build an Alexa skill that interfaces with Twitter at #PhillyCode @PhillyDotNet.

▸ Q: What's the latest popular tweet?

▸ A: There were no matching tweets.

▸ Q: What is the last 5 tweets?

▸ A: The last 5 tweets were: Rick Wargo tweeted: Join me this Sat at 11:30am - we'll build an Alexa skill that interfaces with Twitter at #PhillyCode @PhillyDotNet. Alina retweeted Stratisplatform's tweet: #Stratis are gold sponsors @PhillyDotNet on 24th-25th February explaining our #blockchain t…

▸ Q: What is the last tweet from Rick?

▸ A: The last 1 tweet was: Rick Wargo tweeted: Join me this Sat at 11:30am - we'll build an Alexa skill that interfaces with Twitter at #PhillyCode @PhillyDotNet.

▸ Q: Who tweeted?

▸ A: Recent tweets were from: Rick Wargo, Kucilo Oro, Alina, XTexplorer, and Mohammad Khalid.

▸ Q: Who shared?

▸ A: Recent tweets were from: Rick Wargo, Kucilo Oro, Alina, XTexplorer, and Mohammad Khalid.

13

Page 14: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

CONFIGURE YOUR ENVIRONMENT

‣ Need to configure environment for keys for access to the Twitter API

# Keys for code-camp-tweets skill

export TWITTER_CONSUMER_KEY=hSYvOtda3Ri74PkyuTOHrLMdf

export TWITTER_CONSUMER_SECRET=LXHvTRShADq0s8lOlHCPodPw1smNeJ5p6E8GyOlY9cM0Ti5QSX

export TWITTER_ACCESS_TOKEN_KEY=WVUXxMzZPrszP2AO3eQIogJNFIA2vqkO5bmRkCiO1zCdr7KSt6

export TWITTER_ACCESS_TOKEN_SECRET=tMOuVnb3nrlwtNgUtr9qCZTdEqj6SpqbJrt7uysGuf5oU

Not my real keys :)

14

Page 15: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

AWS CREDENTIALS

‣ Need to configure access to AWS for command line usage.

$ cat ~/.aws/credentials

[default]

aws_access_key_id = OATLIM5W7KKX1V6PQ792

aws_secret_access_key = I2WiUyTkPI7b36PQnin11oUqgZVX575tSUAB1FOm

Not my real credentials :)

15

Page 16: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

THE INTERACTION MODEL

▸ Build the Intent Schema

▸ LatestTweets

▸ WhoTweeted

▸ Build the Sample Utterances

▸ Understanding How Users Invoke Custom Skills

▸ Alexa Skills Kit Voice Design Handbook

▸ Alexa Skills Kit Voice Design Best Practices

▸ Build the Custom Slots

▸ Tweet Category (latest, popular)

▸ Test Schema, Custom Slot Types, and Utterances

16

Page 17: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

HANDLE THE REQUEST

app.intent('WhoTweeted', { utterances: [ 'Who {tweeted|shared} {recently|}', 'Who recently {tweeted|shared}' ] }, function (request, response) { return Twitter.get('search/tweets', TwitterParams) .then(function (tweets) { var users = uniqueTwitterers(tweets.statuses, Constants.MAX_USERS); var msg = Text.recentTweetsFrom(users); response.say(msg); }); });

▸ Create new Twitter App

▸ Get Keys and Access Tokens and Save to Environment

17

Page 18: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

TEST THE INTENT

1. Start the server

2. Go to http://localhost:8003/test

3. Select app

4. Select Intent

5. Submit

18

Page 19: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

BUILD TESTS

▸ Basic tests and structure already defined

▸ Create BDD-style test(s) for each intent and specific way to invoke it

▸ Same test can run against mock server, local server, remote (Lambda)

▸ gulp test-mock

▸ Sample test:

describe('against the Twitter API', function () { describe('#LatestTweets', function () { describe('response', function () { it('contains the latest tweets', function () { var result = request.intentRequest({name: 'LatestTweets'}); return result.should.eventually.match(/<speak>The last [1-9]/); }); }); });});

19

Page 20: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

PUSH TO LAMBDA

▸ Configure package.json, config/app-config.js, config/aws-config.js

▸ gulp push

▸ lint

▸ test-mock

▸ test-local

▸ build-zip

▸ javascript (lib, config, vendor); images; node_modules; assets (schema, custom slot types, utterances)

▸ upload

▸ test-lambda

20

Page 21: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

MOVE IT FORWARD

▸ Use this to write your own Twitter-based skill!

▸ Would need to cache tweets due to Twitter API throttling

▸ Cache would get around seven day tweet archive limitation

▸ Could also authenticate user’s Twitter account and interface directly

▸ Or keep it private and add more personal functionality

▸ https://github.com/rickwargo/code-camp-tweets

▸ https://github.com/rickwargo/alexa-app-root

21

Page 22: How to Build An Alexa Skill

BUILD AN ALEXA SKILL

CONTACT ME

▸ https://www.rickwargo.com/

▸ https://github.com/rickwargo

▸ https://linkedin.com/in/rickwargo

[email protected]

▸ @rickwargo

▸ https://github.com/rickwargo/code-camp-tweets

▸ https://github.com/rickwargo/alexa-app-root

22