Last active
December 5, 2018 04:34
-
-
Save leedohyung-dba/9eada05052fdef72b8214f42d65350c9 to your computer and use it in GitHub Desktop.
注目されるAlexa、そして開発中引っかかった話 ref: https://qiita.com/leedohyung-dba/items/d5471b21f09a667f4835
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
'AskForTheMeetingRoomReservation': function() { | |
const mr = this.event.request.intent.slots.meeting_room || false; | |
const t = this.event.request.intent.slots.time || false; | |
const aipoObj = Aipo.new(AIPO_KEY); | |
const requestId = this.event.request.requestId; | |
const token = this.event.context.System.apiAccessToken; | |
const endpoint = this.event.context.System.apiEndpoint; | |
const ds = new Alexa.services.DirectiveService(); | |
const audio = 'https://s3-ap-northeast-1.amazonaws.com/devio-blog-data/output.mp3'; //30秒 | |
const ssmlTA = '<speak>確認しますので、少々お待ち下さい<audio src="' + audio + '" /></speak>'; | |
const ssmlBA = '<speak><break time="10s"/><audio src="' + audio + '" /></speak>'; | |
const directive1 = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssmlTA); | |
const directive2 = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssmlBA); | |
const directive3 = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssmlBA); | |
const directive4 = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssmlBA); | |
const directive5 = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssmlBA); | |
const progressiveRes1 = ds.enqueue(directive1, endpoint, token); | |
const progressiveRes2 = ds.enqueue(directive2, endpoint, token); | |
const progressiveRes3 = ds.enqueue(directive3, endpoint, token); | |
const progressiveRes4 = ds.enqueue(directive4, endpoint, token); | |
const progressiveRes5 = ds.enqueue(directive5, endpoint, token); | |
const serviceCall = aipoObj.isEmpty(mr, t); // use Promise | |
Promise.race([progressiveRes1, progressiveRes2, progressiveRes3, progressiveRes4, progressiveRes5, serviceCall]) | |
.then( speakValue => { | |
this.emit(':tell', speakValue); | |
}); | |
}, | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- EndpointのLambda関数を生成して、 | |
➔ 関数をデプロイする。 | |
- Skillを生成して、 | |
➔ 基本設定を行って、 | |
➔ 設計したモデルを設定して、 | |
➔ スキルをビルドする |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: sigdemo | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
stage: dev | |
region: ap-northeast-1 | |
environment: | |
APP_ID: ${env:ALEXA_SKILL_ID} | |
AIPO_KEY: ${env:AIPO_KEY} | |
package: | |
include: | |
- node_modules/ | |
functions: | |
skillHandler: | |
name: sigdemo | |
description: sig demo | |
handler: src/index.handler | |
memorySize: 128 | |
timeout: 60 | |
events: | |
- alexaSkill: | |
appId: ${env:ALEXA_SKILL_ID} | |
enabled: true | |
plugins: | |
- serverless-alexa-skills | |
custom: | |
alexa: | |
vendorId: ${env:YOUR_AMAZON_VENDOR_ID} | |
clientId: ${env:YOUR_AMAZON_CLIENT_ID} | |
clientSecret: ${env:YOUR_AMAZON_CLIENT_SECRET} | |
skills: | |
- id: ${env:ALEXA_SKILL_ID} | |
skillManifest: | |
publishingInformation: | |
locales: | |
ja-JP: | |
name: sample | |
apis: | |
custom: { | |
"endpoint": { | |
"uri": "${env:LAMBDA_FUNCTION_URI}" | |
} | |
} | |
manifestVersion: '1.0' | |
models: | |
ja-JP: | |
interactionModel: | |
languageModel: | |
invocationName: sigmon | |
intents: | |
- name: SkillIntroduceIntent | |
samples: | |
- '何ができますか' | |
- name: AskForTheMeetingRoomReservation | |
slots: | |
- name: meeting_room | |
type: MEETING_ROOM | |
- name: time | |
type: AMAZON.TIME | |
samples: | |
- "{time} に {meeting_room} の会議室は空いていますか" | |
- "{meeting_room} の会議室は {time} に空いていますか" | |
- "会議室 {meeting_room} は {time} に空いていますか" | |
- "会議室 {meeting_room} はいつ空きますか" | |
- "{time} に空いている会議室を教えてください" | |
types: | |
- values: | |
- name: | |
value: 'mercury' | |
synonyms: | |
- 'マーキュリー' | |
- name: | |
value: 'mars' | |
synonyms: | |
- 'マース' | |
- name: | |
value: 'neptune' | |
synonyms: | |
- 'ネプチューン' | |
- name: | |
value: 'jupiter' | |
synonyms: | |
- 'ジュピター' | |
- name: | |
value: 'pluto' | |
synonyms: | |
- 'プルートー' | |
name: MEETING_ROOM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.専用Skillで自分のハード登録リクエスト ➔ ユーザーコード、生年月日をスピーチ | |
ㄴ Skill ➔ 一致するユーザーに対するメールに認証コード送信 | |
2.専用Skillで自分のハード登録認証コード確認 ➔ メールから確認した認証コードをスピーチ | |
ㄴ Skill ➔ userIdを取得してDBに入力 | |
3.専用Skillで一般機能使う | |
ㄴ 対話中のuserIdに対するUser情報を取得 | |
ㄴ そのuserIdに対するセッション情報(sessionAttributes)のDynamoDBレコードにUser情報を入れ込む |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.専用Skillで自分のハード登録リクエスト ➔ ユーザーコード、生年月日をスピーチ | |
ㄴ Skill ➔ 一致するユーザーに対するメールに認証コード送信 | |
2.専用Skillで自分のハード登録認証コード確認 ➔ メールから確認した認証コードをスピーチ | |
ㄴ Skill ➔ userIdを取得してDBに入力 | |
3.専用Skillで一般機能使う | |
ㄴ 対話中のuserIdに対するUser情報を取得 | |
ㄴ そのuserIdに対するセッション情報(sessionAttributes)のDynamoDBレコードにUser情報を入れ込む |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.handler = (event, context, callback) => { | |
let alexa = Alexa.handler(event, context, callback); | |
alexa.dynamoDBTableName = 'sigdemo'; | |
alexa.registerHandlers(defaultHandler); | |
alexa.APP_ID = APP_ID; | |
alexa.execute(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: sigdemo | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
stage: dev | |
region: ap-northeast-1 | |
environment: | |
APP_ID: ${env:ALEXA_SKILL_ID} # empty | |
AIPO_KEY: ${env:AIPO_KEY} | |
package: | |
include: | |
- node_modules/ | |
functions: | |
skillHandler: | |
name: sigdemo | |
description: sig demo | |
handler: src/index.handler | |
memorySize: 128 | |
timeout: 60 | |
events: | |
- alexaSkill: | |
appId: ${env:ALEXA_SKILL_ID} # empty | |
enabled: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment