暇だからLINE BOT AWARDSに 作品を出す話

暇だからLINE BOT AWARDSに 作品を出す話

45f1c882172f26941daa2d864d4ff502?s=128

しょぼっち

February 18, 2017
Tweet

Transcript

  1. Ջ͔ͩΒLINE BOT AWARDSʹ ࡞඼Λग़͢(·ͩग़ͯ͠ͳ͍)࿩ 15FR125 2016/02/18 Hojiro LT

  2. PROFILE w ޷͖ͳ΋ͷژ౎ᨅΓͷ؟ڸ່ͬ ,PUMJO 3FBDUJWF9
 ίʔυΰϧϑ Ϋϥϑτδϯ ۚʹͳΓͦ͏ͳࣄۀ w ݏ͍ͳ΋ͷ̍ݶ

    Ԍ্Ҋ݅ ࠷௿௞ۚͰಇ͔ͤΑ͏ͱ͢Δελʔ τΞοϓ w ؾʹͳͬͯΔ΋ͷ%FFQ-FBSOJOH #MPDL$IBJO w 5XJUUFS͠ΐ΅ͬͪɹ!%-- w 'BDFCPPL (JU)VC ˠ!LZ
  3. PROFILE ΩʔϘʔυ͕յΕͨ 21:39 - 2017೥2݄15೔

  4. PROFILE ΩʔϘʔυ͕յΕͨ 21:54 - 2017೥2݄15೔

  5. PROFILE ΩʔϘʔυ͕յΕͨ 1:49 - 2017೥1݄24೔

  6. PROFILE ΩʔϘʔυ͕յΕͨ 12:12 - 2017೥2݄17೔

  7. PROFILE ΩʔϘʔυ͕յΕͨ

  8. ຊ୊

  9. WHAT IS “LINE BOT AWARDS”?

  10. WHAT IS “LINE BOT AWARDS”? https://botawards.line.me/ja/

  11. WHAT IS “LINE BOT AWARDS”? https://botawards.line.me/ja/

  12. WHAT IS “LINE BOT AWARDS”? https://botawards.line.me/ja/

  13. HOW TO MAKE A BOT

  14. HOW TO MAKE A BOT ɾLineͷαʔόʔʹbotͷ௨஌Λ஌ΒͤΔͨΊͷURLΛొ࿥͢Δ ɾbotʹϝοηʔδ͕ૹΒΕΔͱɺొ࿥ͨ͠URLʹϝοηʔδ಺༰͕POST͞ΕΔ { "events" :

    [ { "type" : "message", "replyToken" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "source" : { "userId" : "xxxxxxxxxxxxxxxxxxxxxxxx", "type" : "user" }, "timestamp" : 1487345968820, "message" : { "type" : "text", "id" : "5662473270152", "text" : “Hello World!!” } } ] }
  15. HOW TO MAKE A BOT ɾLineͷαʔόʔʹbotͷ௨஌Λ஌ΒͤΔͨΊͷURLΛొ࿥͢Δ ɾbotʹϝοηʔδ͕ૹΒΕΔͱɺొ࿥ͨ͠URLʹϝοηʔδ಺༰͕POST͞ΕΔ ɾϔομʔʹγάωνϟ͕ೖ͍ͬͯΔͷͰݕূ͓ͯ͘͠(վ᜵ݕग़) x-line-signature: xxxxxxxxxxxxxxx(γάωνϟ)

    content-type: application/json;charset=UTF-8 content-length: 233 host: dll7.ngrok.io accept: */* user-agent: LineBotWebhook/1.0 x-forwarded-proto: https x-forwarded-for: 203.104.146.152
  16. HOW TO MAKE A BOT fun confirmSignature(channelSecret: String, httpRequestBody: String,

    signature: String?): Boolean { if (signature.isNullOrEmpty()) return false val key = SecretKeySpec(channelSecret.toByteArray(), "HmacSHA256") val mac = Mac.getInstance("HmacSHA256") mac.init(key) val source = httpRequestBody.toByteArray() val sig = Base64.getEncoder().encode(mac.doFinal(source)) return String(sig) == signature } ɾLineͷαʔόʔʹbotͷ௨஌Λ஌ΒͤΔͨΊͷURLΛొ࿥͢Δ ɾbotʹϝοηʔδ͕ૹΒΕΔͱɺొ࿥ͨ͠URLʹϝοηʔδ಺༰͕POST͞ΕΔ ɾϔομʔʹγάωνϟ͕ೖ͍ͬͯΔͷͰݕূ͓ͯ͘͠(վ᜵ݕग़)
  17. COMPARE THE FUNCTION Line API (Free) Line API (Pro) Slack

    Reply (౤ߘʹରͯ͠ฦ৴) ⭕ ⭕ ⭕ Push (ࣗൃతʹૹ৴) ❌ ⭕ ⭕ Price ແྉ ༗ྉ (ˇ10kʙ20k / month) ແྉ
  18. WE MADE A BOT… QUIZ PLATFORM

  19. None
  20. WHAT IS QUIZZLY • n୒໰୊ɺචه໰୊ͳͲΛLineͷτʔΫ্Ͱߦ͑ΔBOT • બ୒ࢶͳͲ͸LineͷTemplateAPIΛ࢖༻ • ϩάΠϯͳͲ͸WebViewΛ։͍ͯ੒੷ͳͲΛݟΕΔΑ͏ʹ(࣮૷్த) •

    LineAPIʹ೉͕͋ΔͷͰGoogleAlloͳͲଞͷϓϥοτϑΥʔϜͰ΋
 ల։͍ͨ͠(ຊԻ)ɹˡ͜͜ॏཁ
  21. WHAT IS QUIZZLY • ύιίϯ͔Β͸બ୒ࢶͳͲΛදࣔ͢Δ͜ͱ͕Ͱ͖ͳ͍ˡ࠷ߴʹΞϗ • άϧʔϓʹBOTΛೖΕͨ࣌ɺάϧʔϓID͔͠औಘͰ͖ͳͯ͘୭ͷൃݴͳͷ ͔Θ͔Βͳ͍
 ˡάϧʔϓ಺Ͱૣԡ͠ΫΠζͱ͔΍Ζ͏ͱࢥ͚ͬͨͲɺ੒੷͕ग़ͤͳ͍ •

    બ୒ࢶΛग़͢ʮTemplateʯػೳ͕ը໘αΠζʹΑͬͯදࣔͰ͖Δจࣈ਺͕ Մมͷ͍ͤͰදࣔͰ͖Δจࣈ਺ʹ͔ͳΓ੍ݶ͕͋Δ • LINE BOT AWARDSʹਃ͠ࠐΉͱΞΧ΢ϯτΛظؒத͚ͩ༗ྉ൛ʹͯ͘͠ ΕΔΒ͍͠Μ͚ͩͲɺະͩʹదԠ͞Εͯͳ͍ ͕ͩ͜͜ΊͩΑLINE API
  22. BACKEND

  23. HOW TO MAKE A BOT

  24. HOW TO CREATE LINE ͷαʔόʔ͔Βϝοηʔδ͕഑ྻͰૹΒΕͯ͘Δ ϝοηʔδʹରͯ͠Ϣχίʔυਖ਼نԽΛߦ͍ɺදهͷ༳ΕΛͳ͘͢ Ex: ΢ʃΣˠϰΣ, ᶿˠԼ, ᶯˠϛϦόʔϧ,

    ŜūˠΧφ etc ฦ৴͢ΔͳΓɺࣽΔͳΓম͘ͳΓ޷͖ʹ͢Δ ഑ྻʹೖͬͨϝοηʔδΛΩϡʔʹೖΕͯॱ࣍ॲཧͤ͞Δ (lineͷḉ͸ಉ࣌઀ଓ਺͕ݶΒΕ͍ͯΔͷͰɺ ฦ৴͢Δͱ͖΋ΩϡʔʹೖΕΔͳͲͯ͠ɺḉʹಉ࣌ʹܨ͕ͳ͍Α͏ʹ͢Δ)
  25. HOW TO CREATE ࠓճ࡞੒ͨ͠BOTͷ৔߹ • MessageΛsplit(Regex("[ ,\n]”)).filter(String::isNotEmpty)͢Δ͜ͱͰ ίϚϯυΛर͑ΔγεςϜΛߏங • ίϚϯυΛ༏ઌͯ͠ॲཧͨ͠ΓɺRedisͰηογϣϯΛ؅ཧͨ͠Γ͢

    Ε͹ɺ͍͍ײ͡ͷର࿩γεςϜ͕࡞ΕΔ͔΋ʁ • SlackͳͲͰ͋Γ͕ͪͳbotͱҧͬͯର࿩ੑ͕ॏࢹ͞ΕΔͷͰॏ͘ͳ Γ͕ͪɻ • ࣗવݴޠॲཧ೉͍͠ɻ
  26. HOW TO CREATE ࠓճ࡞੒ͨ͠BOTͷ৔߹ • ϩάΠϯͷ࢓૊Έ ϩάΠϯURLཁٻˠ ←ϩάΠϯURLฦ٫ ྫ: http://quizzly.local/login/xxxxxxxx(token)

    URLΛ౿ΜͰϩάΠϯ(WebView)→ ←ϩάΠϯ׬ྃͷࢫΛPush௨஌ • token͸ϢʔβʔͷLINEͷuser idͱඥ෇͍͍ͯΔ • ϩάΞ΢τ΋τʔΫ͔Βߦ͑ΔͷͰɺ͜ͷ͋ͨΓ͸ָ
  27. HOW TO CREATE ࠓճ࡞੒ͨ͠BOTͷ৔߹ • ໰୊બ୒ͷ࢓૊Έ ݕࡧը໘ΛWebViewͰ։͘ˠ ໰୊Λબ୒(WebView)→ ←ϩάΠϯ࣌ʹඥ෇͚ͨ lineͷuser

    idʹରͯ͠໰୊ղ౴։࢝ • Push APIΛ࢖͏ͷͰɺLineʹ՝ۚ͸ඞਢ • ඇϩάΠϯ࣌ͷϢʔβʔʹؔͯ͠͸ɺ໘౗͔ͩΒߟ͑ΔͷΛ΍Ίͨ • σόοά༻ʹτʔΫը໘͔ΒίϚϯυ࣮ߦͰ΋։࢝Ͱ͖ΔΑ͏ʹ͠ ͍ͯΔ
  28. HOW TO CREATE ࠓճ࡞੒ͨ͠BOTͷ৔߹ • ର࿩ܕͷγεςϜΛͦΕͬΆ͘࡞Δ • ௚લʹ౤࣭͛ͨ໰ͳͲΛεςʔλεͱ͓ͯ࣋ͬͯ͘͠
 ɹEx: ໰୊ग़୊த(n໰໨)

    • ༏ઌ͢ΔίϚϯυ(σόοά,sesssionϦηοτ,ϝχϡʔදࣔͱ͔)
 Λઌʹॲཧ͓ͯ͘͠ͱͦΕͬΆ͘ಈ͘ɻ • ࠓճ΍ͬͨ͜ͱ • RedisͰηογϣϯ؅ཧ • ໰୊ղ౴ͳͲ΋Redisʹ͢΂ͯೖΕͯ͠·͏͜ͱͰ໰୊ͳͲΛ͓͍ ͍ͯΔαʔόͷෛՙܰݮɺΫϥελϦϯά΋Մೳ
  29. ·ͱΊ • LINEͷAPI͸Ϋι(࢓ࣄͰ΋࢖ͬͯΔ͚Ͳ) • ΋͏͙͢αʔϏεΛϩʔϯν͢ΔͷͰɺੋඇ࢖͍ͬͯͩ͘͞ • BOT࡞Δ͚ͩͳͷʹWebଆͷ΄͏͕ॏ͔ͬͨ • ֶੜ৆Λ͔ͬ͞Βͬͯ͏·͍೑͕৯΂͍ͨ…৯΂ͨ͘ͳ͍ʁ •

    ҰਓͰશ෦΍Δͷ͸ॏ͗ͨ͢ͷͰɺ
 Kotlinॻ͚ΔΤϯδχΞͱσβΠϯͰ͖ΔਓΛืूதͰ͢ • BlockChainͷ࣮૷पΓ(PoWͱ͔PoSͱ͔ͦͷ͋ͨΓ)ৄ͍͠ਓ΋ืूͯ͠·͢