Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

How to Build An Alexa Skill

Presented at Code Camp 2017.1 in Malvern, PA, this presentation walks you through building an Alexa skill that interfaces with Twitter using the Alexa Skills Kit, alexa-app, and a template and workflow I developed to make development easier and more predictable, sustainable, and reliable. Rich with links to download code and get more information.

  • Login to see the comments

How to Build An Alexa Skill

  2. 2. 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
  3. 3. 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. 3
  4. 4. 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
  5. 5. BUILD AN ALEXA SKILL HOW CAN YOU BUILD AN ALEXA SKILL? ▸ Node.js, Python, Ruby, C#, Java ▸ AWS Lambda, Self-Hosted ▸ Various Frameworks ▸ alexa-app ▸ flask-ask ▸ AlexaSkillsKit.NET ▸ Other Tools ▸ PullString ▸ Conversable ▸ Bespoken Tools 5
  6. 6. 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
  7. 7. BUILD AN ALEXA SKILL IN THIS SESSION… ▸ We’ll use: ▸ Tests ▸ Lint ▸ Promises ▸ Node.js ▸ Lambda - serverless compute service (CaaS) 7
  8. 8. 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
  9. 9. BUILD AN ALEXA SKILL AMAZON’S 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
  10. 10. 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 ( 10
  11. 11. 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
  12. 12. Twitter API User Voice Request Audio Stream Code-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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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);
 ▸ Create new Twitter App ▸ Get Keys and Access Tokens and Save to Environment 17
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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 ▸ ▸ 21
  22. 22. BUILD AN ALEXA SKILL CONTACT ME ▸ ▸ ▸ ▸ ▸ @rickwargo ▸ ▸ 22