Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Alexa SDK V2基礎講座

46e8de7d6e95be6327e8c49bf3b0c028?s=47 chao2suke
October 26, 2018
65

Alexa SDK V2基礎講座

2018/10/26 Alexa Salon vol.3 資料

46e8de7d6e95be6327e8c49bf3b0c028?s=128

chao2suke

October 26, 2018
Tweet

Transcript

  1. Alexa-SDK V2 基礎講座 Alexa-SDK V2 Training course 1 Classmethod, Inc.

    せーの
  2. #AlexaSalon 2

  3. !3 ( ) A I A l e x a

    & V U I / O /
  4. ί ϛ ϡ χ ς Ο [ A l e

    x a S a l o n ] ओ ࠵ A m a z o n ެ ࣜ ϋ ϯ ζ Φ ϯ τ Ϩ ʔ χ ϯ ά ς Ϋ χ Χ ϧ α ϙ ʔ τ A m a z o n ެ ࣜ τ Ϩ ʔ χ ϯ άϖ ʔ δ ੍ ࡞ A l e x a S k i l l A w a r d s ެ ࣜ ϋ ο Χ ι ϯ : ς Ϋ χ Χ ϧ α ϙ ʔ τ ܾ উ ৹ ࠪ һ ॳ ৺ ऀ ޲ ͚ A l e x a ຊ ࣥ ච !4
  5. Agenda • • S k i l l B u

    i l d e r • • H a n d l e r • R e s p o n s e B u i l d e r • A t t r i b u t e M a n a g e r 5
  6. 6

  7. Hello World 7 const MyHandler = { canHandle(handlerInput) { return

    true; }, handle(handlerInput) { return handlerInput.responseBuilder .speak('͜Μʹͪ͸') .getResponse(); } };
  8. 8

  9. 9

  10. 10

  11. Skill Builder 11

  12. Skill Builder 12 Skill

  13. Skill Instance 13 const skillBuilder = Alexa.SkillBuilders.custom(); exports.handler = skillBuilder

    .addRequestHandlers( LaunchRequestHandler, HelpIntentHandler, CancelAndStopIntentHandler, SessionEndedRequestHandler ) .addErrorHandlers(ErrorHandler) .lambda();
  14. Skill Instance 14 const skillBuilder = Alexa.SkillBuilders.custom(); exports.handler = skillBuilder

    .addRequestHandlers( LaunchRequestHandler, HelpIntentHandler, CancelAndStopIntentHandler, SessionEndedRequestHandler ) .addErrorHandlers(ErrorHandler) .lambda(); ͜Εɻ
  15. Skill Builder 15 Standard Custom શ෦ೖΓ ཉ͍͠ͱ͜Ζ͚ͩ

  16. 16 Skill Builder(Custom) Core Model

  17. 17 Skill Builder(Custom) Core DB Model Persistant Adapter

  18. 18 Skill Builder(Custom) Core DB API Model Persistant Adapter APIClient

  19. 19 Skill Builder(Custom) Custom Core 基本機能 Model 定義情報 Dynamodb-persistance-adapter DynamoDBによる永続化

    S3-peresistance-adapter S3による永続化 Api-client AlexaサービスAPIの使⽤
  20. 20 インストール

  21. インストール 21 $ npm install --save ask-sdk

  22. インストール(Coreのみ) 22 $ npm install --save ask-sdk-model $ npm install

    --save ask-sdk-core
  23. Customビルダーでの宣⾔ 23 ライブラリのインストール コード冒頭でrequired Skill Builderにメソッド追加

  24. Ex.CustomでDynamoDBを使う 24 ライブラリのインストール $ npm install --save ask-sdk-dynamodb- persistence-adapter $

    npm install --save ask-sdk-model $ npm install --save ask-sdk-core
  25. Ex.CustomでDynamoDBを使う 25 'use strict'; const aws = require('aws-sdk-core'); const Adapter

    = require('ask-sdk-dynamodb- persistence-adapter'); コード冒頭でrequired
  26. Ex.CustomでDynamoDBを使う 26 const config = {tableName: 'alexa-salon-vol3', createTable: true}; const

    DynamoDBAdapter = new Adapter.DynamoDbPersistenceAdapter(config); Skill Builderにメソッド追加
  27. Ex.CustomでDynamoDBを使う 27 const skillBuilder = Alexa.SkillBuilders.custom(); exports.handler = skillBuilder .addRequestHandlers(

    LaunchRequestHandler, ) .withPersistenceAdapter(DynamoDBAdapter) .addErrorHandlers(ErrorHandler) .lambda(); Skill Builderにメソッド追加
  28. H a n d l e r 28

  29. Handler 29 CanHandle Handle

  30. canHandle 30 Handler Intent True / False

  31. canHandle 31 Handler Intent canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'IntentRequest'

    && handlerInput.requestEnvelope.request.intent.name === 'MenuIntent'; },
  32. 32 CanHandle Tips Handler CanHandle exports.handler = skillBuilder .addRequestHandlers( LaunchRequestHandler,

    OrderProgressIntentHandler, OrderCompletedIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler, SessionEndedRequestHandler )
  33. Handler Tips 33 Handler-A: Slot Handler-B: Slot Handler-C: 近くの店舗をお知らせする 郵便番号を調べて確認する

    郵便番号を聞く
  34. handle 34 handle(handlerInput) { return setMenu(handlerInput, null); }

  35. Slotのとり⽅ 35 handlerInput.requestEnvelope.request.intent.slots.hand.value

  36. 36 Slot Tips requestまでは⼀緒なので変数化する handlerInput.requestEnvelope.request.intent.slots.hand.value var request = handlerInput.requestEnvelope.request; var

    slot = request.intent.slots.hand.value;
  37. Response 37

  38. 38 Response Builder Tips ResponseBuilderはチェーンで書く return handlerInput.responseBuilder .speak('͢Έ·ͤΜɺΑ͘ฉ͖औΕ·ͤΜͰͨ͠ɻ΋͏Ұ౓ݴͬͯ ΋Β͑·͔͢?') .reprompt('΋͏Ұ౓ݴͬͯ΋Β͑·͔͢?')

    .getResponse();
  39. Response Builder 39 ଟ͗͢Δ

  40. カテゴリに分けてみる。 40

  41. Response Builder 41

  42. Response Builder 42 発話系 speak/response カード系 withXXXcard Dialog Model系 delegate/ElicitXXX/addConfirmXXX

    AudioPlayer系 addAudioPlayerXXX Display系 addRenderTemplateDirective Video系 addVideoAppLaunchDirective セッション管理系 withShouldEndSession
  43. Ex.BodyTemplate 43 handlerInput.responseBuilder .speak(speechText) .reprompt(speechText) .addRenderTemplateDirective({ type: 'ListTemplate1', backButton: 'HIDDEN',

    backgroundImage: logoImage, listItems: listitems, title: 'ϝχϡʔ', token : gToken, }) .getResponse();
  44. 44 Response Builder Tips ResponseBuilderはバラバラに書いて良い

  45. 45 Response Builder Tips handlerInput.responseBuilder .speak(‘͜Ε͚ͩͩͱ࿩͚ͩ͢’); if (canReprompt) { .reprompt(‘͜Ε͕ೖΔͱ໰͍͔͚ʹͳΔ’);

    } handlerInput.responseBuilder.getResponse();
  46. Response Builder Tips じゃんけんであいこの時だけ
 もう⼀度聞き直す ディスプレイのついているデバイスからのリ クエストのみDisplayRenderをつける 46

  47. Attribute Manager 47

  48. 48 AttributeManager RequestAttributes SessionAttributes PersistentAttributes

  49. ࢖͍ํ 49 let attributes = await handlerInput.attributesManager.getPersistentAttributes() handlerInput.attributesManager.setPersistentAttributes(a ttributes); await

    handlerInput.attributesManager.savePersistentAttributes( );
  50. 50 ࢖͍ํ

  51. 51 ࢖͍ํ

  52. 52

  53. None