Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

APL使ってみた

gaomar
December 17, 2018

 APL使ってみた

APL(Alexa Presentation Language)使ってみた。
スマートスピーカーを遊びたおす会 vol.4の登壇資料です。

gaomar

December 17, 2018
Tweet

More Decks by gaomar

Other Decks in Technology

Transcript

  1. λονॲཧ 5PVDI8SBQQFS λονϥούʔ Λ࢖͏ { "type": "TouchWrapper", "onPress": { "type":

    "SendEvent", "arguments": [ "top" ] }, "item": { "type": "AlexaHeader", "headerTitle": "@skillName", "headerAttributionImage": "@skillIcon" } } ɾUZQF͸5PVDI8SBQQFSΛࢦఆ ɾPO1SFTTͰ൓Ԡͤ͞Δ ɾBSHVNFOUTͰ౉͍ͨ͠ύϥϝʔλʔΛࢦఆ ɾJUFN͕൓Ԡ͢Δର৅ IUUQTEFWFMPQFSBNB[PODPNKBEPDTBMFYBQSFTFOUBUJPOMBOHVBHFBQMUPVDIXSBQQFSIUNM
  2. λονॲཧ "4, "MFYB4LJMMT,JU Ͱͷड͚औΓํ // ը໘λονॲཧ const TouchEventHandler = {

    canHandle(handlerInput) { return ((handlerInput.requestEnvelope.request.type === 'Alexa.Presentation.APL.UserEvent' && (handlerInput.requestEnvelope.request.source.handler === 'Press' || handlerInput.requestEnvelope.request.source.handler === 'onPress'))); }, handle(handlerInput) { let choice = handlerInput.requestEnvelope.request.arguments[0]; var speechText = “”; if (choice === 'top') { // λΠτϧ΁໭Δ speechText = “λΠτϧ΁໭ΔΑ”; } else if (choice === 'game_word') { // ΧʔϦϯά༻ޠදࣔ speechText = “ΧʔϦϯά༻ޠը໘΁ߦ͘Α”; } else { // ͦͷଞ speechText = “ͦͷଞͩΑ”; } return handlerInput.responseBuilder .speak(speechText) .getResponse(); } }; ɾUZQF͸"MFYB1SFTFOUBUJPO"1-6TFS&WFOU ɾIBOEMFSʹʮ1SFTTʯ͔ʮPO1SFTTʯ͕ೖΔ ɾBSHVNFOUTͷ഑ྻΛऔಘ
  3. Ϧετॲཧ 4FRVFODF γʔΫΤϯε Λ࢖͏ { "type": "Sequence", "scrollDirection": "horizontal", "data":

    "${listData}", "height": "100%", "width": "100%", "numbered": true, "item": [ { … } ] } ɾUZQF͸4FRVFODFΛࢦఆ ɾTDSPMM%JSFDUJPOͰํ޲Λࢦఆ IPSJ[POUBMԣ޲͖WFSUJDBMॎ޲͖ ɾEBUBͰϦετදࣔ͢ΔݩσʔλΛ౉͢ ɾOVNCFSFE͕USVFͳΒࣗಈ࠾൪͢Δ \PSEJOBM^ʹ࠾൪͞Εͨ஋͕ೖΔ IUUQTEFWFMPQFSBNB[PODPNKBEPDTBMFYBQSFTFOUBUJPOMBOHVBHFBQMTFRVFODFIUNM
  4. "1-ద༻ํ๏ EPDVNFOU෦෼ͱEBUB4PVSDFT෦෼Λ෼͚Δ { “document”: { … }, “dataSouces”: { …

    } } return handlerInput.responseBuilder .speak(speechText) .addDirective({ type : 'Alexa.Presentation.APL.RenderDocument', version: '1.0', document: require('./document/apl_top.json'), datasources: require('./data/apl_top.json') }) .getResponse(); μ΢ϯϩʔυͨ͠KTPOϑΝΠϧ "4,Ͱͷॲཧ BEE%JSFDUJWFʹࢦఆ͢Δ
  5. "1-ҋͷ࿩ EBUBTPVSDFT͸͜͏͠ͳ͍ͱΤϥʔʹͳΔ ʢ-BNCEB͸4VDDFTTͰฦ͖͔ͬͯͨΒ༨ܭϋϚͬͨʜʣ { "listPage": { "listData": [ { "text":

    "1ͭΊ" }, { "text": "2ͭΊ" }, { "text": "3ͭΊ" } ] } } { "listData": [ { "text": "1ͭΊ" }, { "text": "2ͭΊ" }, { "text": "3ͭΊ" } ] } 0,ύλʔϯ /(ύλʔϯ