Alexaスキル開発で TypeScriptをはじめよう / kansaits01

Alexaスキル開発で TypeScriptをはじめよう / kansaits01

kansai.ts #1

75486cbfd37125f121cf4a6c5614601c?s=128

Hidetaka Okamoto

June 10, 2019
Tweet

Transcript

  1. A l e x a εΩϧ ։ ൃ Ͱ Ty

    p e S c r i p t Λ ͸ ͡ Ί Α ͏ k a n s a i . t s # 1 #kansaits
  2. · ͱ Ί • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ •

    ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  3. A l e x a εΩϧΞ ϫ ʔ υϋο Χ

    ι ϯ @ ά ϥ ϑ ϩ
  4. ࠷༏ल৆: ෭৆ɿAmazonΪϑτ݊10ສԁ෼ ෦໳৆: ෭৆ɿAmazonΪϑτ݊5ສԁ෼ • ήʔϜ෦໳ 1࡞඼ • Ωοζ෦໳ 1࡞඼

    • ϔϧεέΞ෦໳ 1࡞඼ • γχΞ෦໳ 1࡞඼
 ಛผ৆: ෭৆ɿAmazonΪϑτ݊3ສԁ෼ • ϚϧνϞʔμϧ৆
 Ի੠ͱը૾ͷ྆ํͰ༏ΕͨΠϯλʔϑΣʔεΛAPLͰ ࣮ݱ͍ͯ͠ΔεΩϧɺ1࡞඼ɻ • ΫϦΤΠςΟϏςΟ৆
 ΞΠσΞ͕ಛʹಠ૑తͳεΩϧɺ1࡞඼ɻ
  5. https://bit.ly/2WvQg6O

  6. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  7. A l e x a ͸ ʮ Ի ੠ -

    > จ ࣈ - > J S O N ʯ ͷ 2 ε ς ο ϓ • ASR (Auto Speech Recognition)ͱNLU (Natural Language Understanging) • Echo͕ฉ͖औͬͨԻ੠ΛASR͕จࣈʹม׵͢Δ • ม׵͞ΕͨจࣈྻΛNLU͕JSONʹม׵͢Δ • Lambda͸JSONΛड͚औΓɺJSONΛฦ͚ͩ͢ #kansaits
  8. A l e x a ͷ S D K (

    N o d e ) ͸ Ty p e S c r i p t
  9. ͩ ͍ ͨ ͍ ͜ Μ ͳ ײ ͡ import

    { Response } from 'ask-sdk-model'; import { RequestHandler, HandlerInput } from ‘ask-sdk-core’; interface MineHandler extends RequestHandler { // ॲཧ͢ΔϦΫΤετ͔ͷ൑ఆ canHandle(handlerInput: HandlerInput): Promise<boolean> | boolean // ϦΫΤετॲཧʴϨεϙϯε࡞੒ handle(handlerInput: HandlerInput): Promise<Response> | Response } #kansaits
  10. ͩ ͍ ͨ ͍ ͜ Μ ͳ ײ ͡ import

    { Response } from 'ask-sdk-model'; import { RequestHandler, HandlerInput } from ‘ask-sdk-core’; interface MineHandler extends RequestHandler { // ॲཧ͢ΔϦΫΤετ͔ͷ൑ఆ canHandle(handlerInput: HandlerInput): Promise<boolean> | boolean // ϦΫΤετॲཧʴϨεϙϯε࡞੒ handle(handlerInput: HandlerInput): Promise<Response> | Response } #kansaits
  11. ͩ ͍ ͨ ͍ ͜ Μ ͳ ײ ͡ import

    { Response } from 'ask-sdk-model'; import { RequestHandler, HandlerInput } from ‘ask-sdk-core’; interface MineHandler extends RequestHandler { // ॲཧ͢ΔϦΫΤετ͔ͷ൑ఆ canHandle(handlerInput: HandlerInput): Promise<boolean> | boolean // ϦΫΤετॲཧʴϨεϙϯε࡞੒ handle(handlerInput: HandlerInput): Promise<Response> | Response } #kansaits
  12. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  13. ͢ ͝ ͍ J S O N { "version": "1.0",

    "session": { "new": true, "sessionId": "amzn1.echo-api.session.[unique-value-here]", "application": { "applicationId": "amzn1.ask.skill.[unique-value-here]" }, "attributes": { "key": "string value" }, "user": { "userId": "amzn1.ask.account.[unique-value-here]", "accessToken": "Atza|AAAAAAAA...", "permissions": { "consentToken": "ZZZZZZZ..." } } }, "context": { "System": { "device": { "deviceId": "string", "supportedInterfaces": { "AudioPlayer": {} } }, "application": { "applicationId": "amzn1.ask.skill.[unique-value-here]" }, "user": { "userId": "amzn1.ask.account.[unique-value-here]", "accessToken": "Atza|AAAAAAAA...", "permissions": { "consentToken": "ZZZZZZZ..." } }, "apiEndpoint": "https://api.amazonalexa.com", "apiAccessToken": "AxThk..." }, "AudioPlayer": { "playerActivity": "PLAYING", "token": "audioplayer-token", "offsetInMilliseconds": 0 } }, "request": {} } https://developer.amazon.com/ja/docs/custom-skills/request-and-response-json-reference.html #kansaits
  14. ֮ ͑Β Ε ͳ ͍ #kansaits

  15. #alexaday2019

  16. ↑ ೖ ྗ ิ ׬ ͷ ྫ

  17. ↓ ೖ ྗ ஋ ͷ ν Σ ο Ϋ

  18. ˚ ֮ ͑ Β Ε ͳ ͍ ̋ ֮ ͑

    ͳ ͘ ͯ ͍ ͍ #kansaits
  19. ઃ ܭ ཧ ղ ͸ Q i i t a

    ͷ ͜ ͷ ه ࣄ Λ https://qiita.com/shinichi-takahashi/items/7191d3d393e08b2746f0 #kansaits
  20. T i p s : Ty p e S c

    r i p t Ͱ ͸ ɺ ͜ Ε ͕ ܕ Τ ϥ ʔ ʹ ͳ Δ .addRequestHandler('ExampleIntent', async (handlerInput) => { const testSlot = handlerInput.requestEnvelope.request.intent.slots.hoge.value return handlerInput.responseBuilder.speak(`You choose ${testSlot}`).getResponse() })
  21. None
  22. R e q u e s t ͷ ܕ ͕

    ͭ Β ͍ ߹ Θ ͳ ͍ ࣌ ͸ a s Λ ࢖ ͏ import { IntentRequest } from ‘ask-sdk-model’ … const request = handlerInput.requestEnvelope.request as IntentRequest const testSlot = request.intent.slots.hoge.value
  23. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  24. A S K C L I Ͱ ͷ σ ϓ

    ϩ Π • ࣄલʹ.ts -> .jsͷม׵͕ඞཁ • hooks/pre_deploy_hook.shΛ׆༻͢Δͱɺ
 ask deployͰϏϧυ -> σϓϩΠΛ࣮ߦՄೳ • npm prune —production΋ೖΕΔ͜ͱͰɺdevআ֎ #kansaits
  25. / h o o k s / p re _

    d e p l o y _ h o o k . s h install_dependencies() { npm install --prefix "$1" >/dev/null 2>&1 # Լͷ3ߦΛ௥Ճ͢Δ npm run build --prefix "$1" rm -rf "$1/node_modules" >/dev/null 2>&1 npm install --prefix "$1" --only=production >/dev/null 2>&1 return $? } #kansaits
  26. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  27. ܕ ͕ ͋ ͬͯ ΋ ύ ϥϝ ʔ λ ୳

    ͢ ͷ Ί Μ Ͳ ͍ #kansaits
  28. T S Ͱ S D K ͷ S D K

    ͭ ͬ͘ ͨ • ASK SDK޲͚Utility npm i -S ask-utils • Proactive Event޲͚SDK npm i -S @ask-utils/proactive-event • Amazon Pay޲͚Ϗϧμʔ npm i -S @ask-utils/amazon-pay • εΩϧ՝ۚ޲͚ϔϧύʔ npm i -S @ask-utils/isp
  29. C F P ௨ ͬ ͨ Β ৄ ղ ൛

    ΍ Γ · ͢
  30. C F P ௨ ͬ ͨ Β ৄ ղ ൛

    ΍ Γ · ͢
  31. Ty p e S c r i p t Ͱ

    L a m b d a Ϳ Μ ճ ͠ ͨ ͍ ํ ͸ ͜ ͪ Β
  32. Ty p e S c r i p t Ͱ

    L a m b d a Ϳ Μ ճ ͠ ͨ ͍ ํ ͸ ͜ ͪ Β https://bit.ly/2WvQg6O
  33. ͓ Θ Γ k a n s a i .

    t s # 1 #kansaits