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

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

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

kansai.ts #1

Hidetaka Okamoto

June 10, 2019
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Programming

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. ࠷༏ल৆: ෭৆ɿAmazonΪϑτ݊10ສԁ෼ ෦໳৆: ෭৆ɿAmazonΪϑτ݊5ສԁ෼ • ήʔϜ෦໳ 1࡞඼ • Ωοζ෦໳ 1࡞඼

    • ϔϧεέΞ෦໳ 1࡞඼ • γχΞ෦໳ 1࡞඼
 ಛผ৆: ෭৆ɿAmazonΪϑτ݊3ສԁ෼ • ϚϧνϞʔμϧ৆
 Ի੠ͱը૾ͷ྆ํͰ༏ΕͨΠϯλʔϑΣʔεΛAPLͰ ࣮ݱ͍ͯ͠ΔεΩϧɺ1࡞඼ɻ • ΫϦΤΠςΟϏςΟ৆
 ΞΠσΞ͕ಛʹಠ૑తͳεΩϧɺ1࡞඼ɻ
  4. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  5. 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
  6. A l e x a ͷ S D K (

    N o d e ) ͸ Ty p e S c r i p t
  7. ͩ ͍ ͨ ͍ ͜ Μ ͳ ײ ͡ 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
  8. ͩ ͍ ͨ ͍ ͜ Μ ͳ ײ ͡ 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
  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. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

    / Output͕΄΅ݻఆͳͷͰɺTypeScriptೖ໳޲͚ • ASK CLIͰ΋hookΛ࢖͑͹σϓϩΠՄೳ • ϥΠϒϥϦ࡞ͬͯΔ͔ΒΈΜͳ࢖ͬͯ #kansaits
  11. ͢ ͝ ͍ 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
  12. ˚ ֮ ͑ Β Ε ͳ ͍ ̋ ֮ ͑

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

    ͷ ͜ ͷ ه ࣄ Λ https://qiita.com/shinichi-takahashi/items/7191d3d393e08b2746f0 #kansaits
  14. 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() })
  15. 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
  16. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

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

    ϩ Π • ࣄલʹ.ts -> .jsͷม׵͕ඞཁ • hooks/pre_deploy_hook.shΛ׆༻͢Δͱɺ
 ask deployͰϏϧυ -> σϓϩΠΛ࣮ߦՄೳ • npm prune —production΋ೖΕΔ͜ͱͰɺdevআ֎ #kansaits
  18. / 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
  19. A g e n d a • AlexaΧελϜεΩϧ͸TypeScriptͰॻ͚Δ • Input

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

    ͢ ͷ Ί Μ Ͳ ͍ #kansaits
  21. 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
  22. Ty p e S c r i p t Ͱ

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

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

    t s # 1 #kansaits