How to develop Alexa Skill Kit based on Serverless Architecture

>100 Views

September 21, 17

スライド概要

AWS Community Day APAC
2017/09/21

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

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.

2.

Hidetaka Okamoto • Digitalcube Co. Ltd. • JAWS-UG Kyoto, Kobe • WordCamp Kyoto 2017

3.

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

4.

AGENDA 1. What is Alexa & Alexa Skills Kit ? 2. How to develop the Alexa Skill 3. How to test & deployment your Skill

5.

What is Alexa And Alexa Skills Kit

7.

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

9.

https://developer.amazon.com/alexa-skills-kit/

10.

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

11.

Alexa Skills Kit documentations • Webinars • Training videos • Developer blog • Podcast • Events • and more… https://developer.amazon.com/alexa-skills-kit/learn

12.

Alexa Skills Kit examples https://developer.amazon.com/alexa-skills-kit/tutorials

13.

Published our custom Skills https://www.amazon.com/Digitalcube-Inc-Shifter-man/dp/B07572D7N8/

14.

Shifter man skills is … • Talking about our service • Speech out our blog content • Source code is open. • https://github.com/getshifter/alexa-shifterman

15.

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

16.

How to develop the Alexa Skill

17.

Ta l k somthing Responce Audio Capture Audio Playback Speech to Te x t Te x t t o Speech Call some API

18.

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

19.

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

20.

AWS Lambda is great Alexa’s backend https://aws.amazon.com/lambda/

21.
[beta]
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": {
…

22.

Lambda should return valid JSON { "version": "string", "response": { "outputSpeech": { "type": "string", "text": "string", "ssml": "string" }, "card": { "type": "string", "image": { "smallImageUrl": "string", "largeImageUrl": "string" } …

23.

Alexa has SDK (Node.js) https://www.npmjs.com/package/alexa-sdk

24.

npm init -y npm install -S alexa-sdk

25.
[beta]
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();
};

26.
[beta]
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();
};

27.
[beta]
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();
};

28.
[beta]
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();
};

29.

tell or ask alexa.emit( ‘:tell’, ‘Talk something, and end session’ ); alexa.emit( ‘:ask’, ‘Talk something, and wait user input’, ‘and ask again’ );

30.

Can call another API (like WP API) https://github.com/getshifter/alexa-shifterman/blob/master/index.js#L44-L67

31.

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

33.

How to test & deployment your Skill

34.

Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.

35.

Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.

36.

Alexa Conversation: Tests for your Alexa skills https://www.npmjs.com/package/alexa-conversation

37.

npm install -g mocha npm install --save-dev alexa-conversation

38.
[beta]
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();

39.
[beta]
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();

40.
[beta]
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

41.
[beta]
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

42.
[beta]
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)

43.

ESLint help you to check your code https://eslint.org/

44.

“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

45.

Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.

46.

Serverless Framework: create & manage app https://serverless.com/

47.

$ npm install -g serverless $ serverless create -t aws-nodejs $ serverless deploy

48.

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

49.

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

50.

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

51.

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

52.

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/

53.

Easy to create Alexa Skills, but We want to … • Test our code in local environment • Deploy our code automatically • Manage our resources in AWS.

54.

Serverless FW using CloudFormation https://serverless.com/

55.

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}

56.

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}

57.

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}

58.

Easy to customize our AWS resources https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/

59.

All examples are in our GitHub https://github.com/getshifter/alexa-shifterman

60.

Conclusion • We can easy to make voice app by Alexa • AWS help us to create & manage Alexa app • Let’s create own Alexa Skills !

61.

Join ! https://jaws-ug-kobe.doorkeeper.jp/events/64712

62.

Q&A #AWSCommunityDay