>100 Views
September 21, 17
スライド概要
AWS Community Day APAC
2017/09/21
Developer
How to develop Alexa Skills Kit based on Serverless Architecture Hidetaka Okamoto Digitalcube / JAWS-UG © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hidetaka Okamoto • Digitalcube Co. Ltd. • JAWS-UG Kyoto, Kobe • WordCamp Kyoto 2017
I’ll introduce… • Alexa Skills Kit can easy to make voice application • AWS Lambda help you to create the Skill more easier • Serverless Framework can manage your app code • Node.js is good for making Alexa Skill
AGENDA 1. What is Alexa & Alexa Skills Kit ? 2. How to develop the Alexa Skill 3. How to test & deployment your Skill
What is Alexa And Alexa Skills Kit
Alexa is… • The voice service that powers Amazon Echo • Can interact with devices using voice • Can build new voice experiences https://developer.amazon.com/alexa
https://developer.amazon.com/alexa-skills-kit/
Alexa Skills Kit (ASK) is… • Can build engaging skills more easily. • Collect APIs, tools, docs, examples. • Can leverage Amazon’s knowledge of voice. https://developer.amazon.com/alexa-skills-kit
Alexa Skills Kit documentations • Webinars • Training videos • Developer blog • Podcast • Events • and more… https://developer.amazon.com/alexa-skills-kit/learn
Alexa Skills Kit examples https://developer.amazon.com/alexa-skills-kit/tutorials
Published our custom Skills https://www.amazon.com/Digitalcube-Inc-Shifter-man/dp/B07572D7N8/
Shifter man skills is … • Talking about our service • Speech out our blog content • Source code is open. • https://github.com/getshifter/alexa-shifterman
Check point • Alexa is the voice service • Alexa Skills Kit helps us to create App easily • We can easy to create & deploy App by AWS
How to develop the Alexa Skill
Ta l k somthing Responce Audio Capture Audio Playback Speech to Te x t Te x t t o Speech Call some API
Ta l k somthing Responce Audio Capture Audio Playback Alexa Skills Kit Speech to Te x t Te x t t o Speech Call some API
Ta l k somthing Responce Audio Capture Audio Playback Alexa Skills Kit Speech to Te x t Te x t t o Speech AWS Lambda Web API Call some API
AWS Lambda is great Alexa’s backend https://aws.amazon.com/lambda/
Lambda get JSON from Alexa Skills
{
"request": {
"type": "IntentRequest",
"requestId": "",
"intent": {
"name": "AskPriceIntent",
"slots": {}
},
"locale": "en-US",
"timestamp": "2017-08-29T08:26:02Z"
},
"context": {
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXXXX"
},
"user": {
…
Lambda should return valid JSON { "version": "string", "response": { "outputSpeech": { "type": "string", "text": "string", "ssml": "string" }, "card": { "type": "string", "image": { "smallImageUrl": "string", "largeImageUrl": "string" } …
Alexa has SDK (Node.js) https://www.npmjs.com/package/alexa-sdk
npm init -y npm install -S alexa-sdk
We can easy to write Alexa code
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function () {
this.emit(':tell', 'Hello');
},
};
module.exports.hello = (event, context, callback) => {
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
We can easy to write Alexa code
Load alexa-sdk
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function () {
this.emit(':tell', 'Hello');
},
};
module.exports.hello = (event, context, callback) => {
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
We can easy to write Alexa code
Load alexa-sdk
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function () {
this.emit(':tell', 'Hello');
},
};
Define response
module.exports.hello = (event, context, callback) => {
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
We can easy to write Alexa code
Load alexa-sdk
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function () {
this.emit(':tell', 'Hello');
},
};
Define response
Execute application
module.exports.hello = (event, context, callback) => {
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
tell or ask alexa.emit( ‘:tell’, ‘Talk something, and end session’ ); alexa.emit( ‘:ask’, ‘Talk something, and wait user input’, ‘and ask again’ );
Can call another API (like WP API) https://github.com/getshifter/alexa-shifterman/blob/master/index.js#L44-L67
Many Skills examples in GitHub • https://github.com/alexa/ • “step-by-step” help us to know how to deploy • All example has comment (How to customize) • We can easy to create own Alexa Skills
How to test & deployment your Skill
Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.
Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.
Alexa Conversation: Tests for your Alexa skills https://www.npmjs.com/package/alexa-conversation
npm install -g mocha npm install --save-dev alexa-conversation
We can easy to test own Alexa code
const conversation = require('alexa-conversation');
const app = require('../index.js');
const opts = {
name: 'Alexa Shifter man',
appId: 'your-app-id',
app: app,
handler: app.hello
};
conversation(opts)
.userSays('GetNewFactIntent')
.plainResponse
.shouldContain("Here\'s the shifter")
.end();
We can easy to test own Alexa code
Load lib & test target
const conversation = require('alexa-conversation');
const app = require('../index.js');
const opts = {
name: 'Alexa Shifter man',
appId: 'your-app-id',
app: app,
handler: app.hello
};
conversation(opts)
.userSays('GetNewFactIntent')
.plainResponse
.shouldContain("Here\'s the shifter")
.end();
We can easy to test own Alexa code
Load lib & test target
const conversation = require('alexa-conversation');
const app = require('../index.js');
const opts = {
name: 'Alexa Shifter man',
appId: 'your-app-id',
app: app,
handler: app.hello
};
conversation(opts)
.userSays('GetNewFactIntent')
.plainResponse
.shouldContain("Here\'s the shifter")
.end();
Init test
We can easy to test own Alexa code
Load lib & test target
const conversation = require('alexa-conversation');
const app = require('../index.js');
const opts = {
name: 'Alexa Shifter man',
appId: 'your-app-id',
app: app,
handler: app.hello
};
conversation(opts)
.userSays('GetNewFactIntent')
.plainResponse
.shouldContain("Here\'s the shifter")
.end();
Init test
Define test
Running test by mocha
$ mocha tests
E x e c u t i n g c o n v e r s a t i o n : H e l l o A l e x a Te s t
✓ Finished executing conversation
C o n v e r s a t i o n : H e l l o A l e x a Te s t
User triggers: HelloIntent
✓ Alexa's plain text response should contain: Hello. I'm example skills
for your serverless projects.
✓ Alexa's plain text response should contain: Please tell me your
name.
U s e r t r i g g e r s : N a m e I n t e n t S L O T S : { N a m e S l o t : Ts u y o s h i }
✓ Alexa's plain text response should contain: Nice to meet you,
Ts u y o s h i . E n j o y A l e x a w o r l d !
4 passing (16ms)
ESLint help you to check your code https://eslint.org/
“Shifter man” is tested two way # Check the code syntax by ESLint $ npm run lint # Test the conversation by alexa-conversation $ npm test https://github.com/getshifter/alexa-shifterman/blob/master/README.md
Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.
Serverless Framework: create & manage app https://serverless.com/
$ npm install -g serverless $ serverless create -t aws-nodejs $ serverless deploy
We can define AWS resources as YAML service: alexa-shifter provider: name: aws runtime: nodejs6.10 package: include: - node_modules/ functions: hello: handler: index.hello events: - alexaSkill
We can define AWS resources as YAML Define provider service: alexa-shifter provider: name: aws runtime: nodejs6.10 package: include: - node_modules/ functions: hello: handler: index.hello events: - alexaSkill
We can define AWS resources as YAML Define provider service: alexa-shifter provider: name: aws runtime: nodejs6.10 package: include: - node_modules/ functions: hello: handler: index.hello events: - alexaSkill Include libraries
We can define AWS resources as YAML Define provider service: alexa-shifter provider: name: aws runtime: nodejs6.10 Include libraries package: include: - node_modules/ Define Lambda functions: hello: handler: index.hello events: - alexaSkill
Easy to rollback & checking CloudWatch logs # Rollback $ serverless rollback --timestamp timestamp # Tail the Lamdbda’s log $ serverless logs -f hello -t https://serverless.com/framework/docs/providers/aws/cli-reference/
Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.
Serverless FW using CloudFormation https://serverless.com/
We can define custom resources custom: stage: ${opt:stage, self:provider.stage} defaultProfile: default logRetentionInDays: development: "14" production: "90" default: "3" resources: Resources: HelloLogGroup: Properties: RetentionInDays: ${self:custom.logRetentionInDays.${self:custom.stage}, self:custom.logRetentionInDays.default}
We can define custom resources Define params custom: stage: ${opt:stage, self:provider.stage} defaultProfile: default logRetentionInDays: development: "14" production: "90" default: "3" resources: Resources: HelloLogGroup: Properties: RetentionInDays: ${self:custom.logRetentionInDays.${self:custom.stage}, self:custom.logRetentionInDays.default}
We can define custom resources Define params custom: stage: ${opt:stage, self:provider.stage} defaultProfile: default logRetentionInDays: development: "14" production: "90" default: "3" Update CWL props resources: Resources: HelloLogGroup: Properties: RetentionInDays: ${self:custom.logRetentionInDays.${self:custom.stage}, self:custom.logRetentionInDays.default}
Easy to customize our AWS resources https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/
All examples are in our GitHub https://github.com/getshifter/alexa-shifterman
Conclusion • We can easy to make voice app by Alexa • AWS help us to create & manage Alexa app • Let’s create own Alexa Skills !
Join ! https://jaws-ug-kobe.doorkeeper.jp/events/64712
Q&A #AWSCommunityDay