ClaspとTypescriptで Google Apps Scriptを動かす / serverlesskobe20200125

ClaspとTypescriptで Google Apps Scriptを動かす / serverlesskobe20200125

Serverless Meetup Kobe vol1 2020/01/25
#serverlesskobe

75486cbfd37125f121cf4a6c5614601c?s=128

Hidetaka Okamoto

January 25, 2020
Tweet

Transcript

  1. ClaspͱTypescriptͰ Google Apps ScriptΛಈ͔͢ Serverless Meetup Kobe vol1 2020/01/25 #serverlesskobe

  2. About: Hidetaka Okamoto גࣜձࣾσδλϧΩϡʔϒ "MFYB$IBNQJPOT 3FBDU5ZQF4DSJQU"84 #serverlesskobe

  3. About: Hidetaka Okamoto גࣜձࣾσδλϧΩϡʔϒ "MFYB$IBNQJPOT 3FBDU5ZQF4DSJQU"84 #serverlesskobe

  4. #serverlesskobe

  5. Agenda ΍Γ͔ͨͬͨ͜ͱ (PPHMF"QQT4DSJQUͷίʔυΛϩʔΧϧͰ։ൃ͢Δ 5ZQF4DSJQUΛ࢖ͬͯ։ൃΛΑΓศརʹ͢Δ ͓ΘΓʹ #serverlesskobe

  6. Agenda ΍Γ͔ͨͬͨ͜ͱ (PPHMF"QQT4DSJQUͷίʔυΛϩʔΧϧͰ։ൃ͢Δ 5ZQF4DSJQUΛ࢖ͬͯ։ൃΛΑΓศརʹ͢Δ ͓ΘΓʹ #serverlesskobe

  7. ΍Γ͔ͨͬͨ͜ͱ ؆୯ͳCPUʢ-*/&PS"MFYBΛ૝ఆʣ (PPHMFΧϨϯμʔ΁ͷ༧ఆ௥ՃΛτϦΨʔʹ͢Δ มߋ͞Εͨ಺༰Λνϟοτ΍76*Ͱ௨஌͢Δ ࢖͍׳Εͨ5ZQF4DSJQUΛ࢖͍͍ͨ #serverlesskobe

  8. ࣮૷ͨ͠΋ͷ (PPHMF"QQT4DSJQUͰ࣮૷ (PPHMFΧϨϯμʔΛτϦΨʔʹ࣮ߦ -*/&ͷ.FTTBHF"1*ʹ1045ϦΫΤετ #serverlesskobe

  9. Agenda ΍Γ͔ͨͬͨ͜ͱ (PPHMF"QQT4DSJQUͷίʔυΛϩʔΧϧͰ։ൃ͢Δ 5ZQF4DSJQUΛ࢖ͬͯ։ൃΛΑΓศརʹ͢Δ ͓ΘΓʹ #serverlesskobe

  10. GOOGLE APPS SCRIPT HTTPS://DEVELOPERS.GOOGLE.COM/APPS-SCRIPT?HL=JA #serverlesskobe

  11. • Google͕ఏڙ͢ΔFaaS • 6෼ఔ౓ͷScript͕࣮ߦՄೳ • ੍ݶࣄ߲͸G Suite Planґଘ • script.google.comͰ؅ཧ

    • GUIͰ΋ίʔυΛฤूՄೳ • Google Appsͱͷ਌࿨ੑ #serverlesskobe
  12. • Google͕ఏڙ͢ΔFaaS • 6෼ఔ౓ͷScript͕࣮ߦՄೳ • ੍ݶࣄ߲͸G Suite Planґଘ • script.google.comͰ؅ཧ

    • GUIͰ΋ίʔυΛฤूՄೳ • Google Appsͱͷ਌࿨ੑ #serverlesskobe
  13. GUI্Ͱ࣮૷ɾ؅ཧͨ͘͠ͳ͍ʂ #serverlesskobe

  14. npm I -g @google/ clasp C ommand L ine A

    pps S cript P roject #serverlesskobe
  15. claspͱ͸ (PPHMF͕ϦϦʔε͍ͯ͠Δ("4޲͚$-*πʔϧ σϓϩΠ΍ෳ੡ɺεςʔλεͷ֬ೝͳͲͷૢ࡞͕Մೳ DMBTQMPHJOͰϩάΠϯ͢ΔͱɺDMBTQSDKTPOʹೝূ৘ใΛه࿥ ("4Λ։ൃ͢ΔͳΒ$MBTQҰ୒ʢඪຊ਺ʣ #serverlesskobe

  16. Google Apps Script APIΛ༗ޮԽ͓ͯ͘͠ https://script.google.com/home/usersettings #serverlesskobe

  17. $ clasp loginͰ ϩάΠϯը໘͕ ্ཱ͕ͪΔ #serverlesskobe

  18. ͍Ζ͍Ζͱݖݶ͸ ཁٻ͞ΕΔ Serverless Framework͕ AdministratorAccessཁٻ͢Δͷʹ ͍ۙΑ͏ͳҹ৅ #serverlesskobe

  19. $ cat ~/.clasprc.json tokenͳͲ͸࿙Β͞ͳ͍Α͏ʹ஫ҙ͢Δ #serverlesskobe

  20. $ clasp createͰϓϩδΣΫτΛ࡞੒͢Δ https://github.com/google/clasp#create #serverlesskobe

  21. createޙʹpullͰ entrypointΛऔಘ Code.jsʹίʔυΛॻ͍ͯ push͢Ε͹OK #serverlesskobe

  22. claspͰͰ͖Δ͜ͱʢҰ෦ʣ DMBTQQVTIͰσϓϩΠ DMBTQWFSTJPOlzͰόʔδϣϯઃఆ DMBTQWFSTJPOTͰόʔδϣϯҰཡऔಘ DMBTQMPHTͰ࣮ߦϩάͷදࣔʢGSPN4UBDL%SJWFSʣ #serverlesskobe

  23. claspΛ࢖ͬͯϩʔΧϧͰGAS։ൃ ެࣜπʔϧͷ҆৺ײ όʔδϣχϯά΍$MPOFͳͲ΋͋Γखް͍ ("4ͳΒͰ͸ϓϩύςΟʹ͍ͭͯ͸ࣗྗͰௐ΂Δඞཁ͋Γ ͠ΐ͏͖͡ΊΜͲ͍͘͞ #serverlesskobe

  24. Agenda ΍Γ͔ͨͬͨ͜ͱ (PPHMF"QQT4DSJQUͷίʔυΛϩʔΧϧͰ։ൃ͢Δ 5ZQF4DSJQUΛ࢖ͬͯ։ൃΛΑΓศརʹ͢Δ ͓ΘΓʹ #serverlesskobe

  25. ͳͥTypeScriptΛ࢖͍͍ͨͷ͔ (PPHMF"QQT͔Β͘Δσʔλͷܕ͕஌Γ͍ͨ ("4Ͱར༻Ͱ͖Δάϩʔόϧม਺ܥΛ஌Γ͍ͨ ("4ʹ͸'FUDI΍"QQT઀ଓܥͷಠࣗม਺ɾΫϥε͕ଟ਺͋Δ Կ͕͋Δͷ͔ɺͲ͏࢖͑͹͍͍ͷ͔ΛάάΓͨ͘ͳ͍ ܕ͕ͳ͍··ॻ͍ͨࣗ෼ͷίʔυΛ৴༻Ͱ͖ͳ͍ #serverlesskobe

  26. clasp͸TypeScript ϑϨϯυϦʔ #serverlesskobe

  27. ܕ৘ใͷऔಘɿnpm install --save @types/google-apps-script #serverlesskobe

  28. Clasp push࣌ʹτϥϯεύΠϧͯ͘͠ΕΔͷͰɺͦͷ··pushͰ͖Δ #serverlesskobe

  29. Google AppsܥͷAPIʹର͢Δೖྗิ׬΋ڧྗ #serverlesskobe

  30. GoogleΧϨϯμʔ͔ΒͷΠϕϯτσʔλΛ੔ܗ͢Δαϯϓϧ #serverlesskobe

  31. LINEͷMessage APIܦ༝ͰϝοηʔδΛૹ৴͢Δαϯϓϧ #serverlesskobe

  32. Claspͷ஫ҙ఺ 3FRVJSFJNQPSU͸࢖Θͳ͍ʢ࢖͏ͳΒXFCQBDLͳͲͰϏϧυʣ ॏ͍ͨ4%,ΛCVOEMF͢ΔͱΞοϓϩʔυͰ͖ͳ͍͜ͱ͕͋Δ -*/&4%,͕μϝͩͬͨͷͰ1045PS"1*(8௥ՃͰରԠͨ͠ (PPHMFͷυΩϡϝϯτͷάάϥϏϦςΟ͕௿͍ ʮ("4Ͱۀ຿ޮ཰Խʂʯܥهࣄʹຒ΋ΕͯΔͷͰݕࡧͭΒ͍ #serverlesskobe

  33. ݸਓతGAS(Clasp)࢖͍ॴ (PPHMFܥαʔϏεͷΠϕϯτϒϦοδͱͯ͠ͷ("4 "84ͷΠϕϯτ͸&WFOU#SJEHF(PPHMF"QQT͸("4 ۩ମతͳॲཧܥΛ୲͏"1*΍'BB4Λ༻ҙ͢Δ ("4ͰΠϕϯτσʔλΛ੔ཧͯ͠ɺॲཧܥʹ౤͚͛ͭΔ (PPHMF"QQTܥͷσʔλऩूʹઐ೦͢Δͷ΋Ұͭ #serverlesskobe

  34. Agenda ΍Γ͔ͨͬͨ͜ͱ (PPHMF"QQT4DSJQUͷίʔυΛϩʔΧϧͰ։ൃ͢Δ 5ZQF4DSJQUΛ࢖ͬͯ։ൃΛΑΓศརʹ͢Δ ͓ΘΓʹ #serverlesskobe

  35. ͓ΘΓʹ (PPHMF"QQTܥΛτϦΨʔʹ͢ΔͳΒ("4 (PPHMF"QQT4DSJQU  $MBTQΛ࢖͑͹ϩʔΧϧͰॻ͍ͨίʔυΛσϓϩΠͰ͖Δ 5ZQF4DSJQUͰͷ࣮૷΋؆୯ ͨͩ͠༰ྔ੍ݶ͕͋ΔͷͰ%JTQBDIFSҎ্ͷ༻్͸ผ'BB4Λ #serverlesskobe