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

aws chaliceで作るslack翻訳bot

uchimanajet7
January 26, 2018

aws chaliceで作るslack翻訳bot

MasterCloud #9 新春クラウドLT大会 (マスタークラウド) - connpass
https://mastercloud.connpass.com/event/74392/

でのLT発表資料になります

#mastercloud
#aws
#slack

uchimanajet7

January 26, 2018
Tweet

More Decks by uchimanajet7

Other Decks in Technology

Transcript

  1. BXTDIBMJDFͰ࡞Δ TMBDL຋༁CPU ೥݄೔ ಺ాֶ !.BTUFS$MPVE৽य़Ϋϥ΢υ-5େձ

  2. 2 ࣗݾ঺հ ಺ా ֶʢ͏ͪͩ ·ͳͿʣ uchimanajet7 JAWS-UG΍SORACOM UGʹࢀՃͯ͠·͢ AWSͱGolang͕޷͖Ͱ͢ ࣗࣾαʔϏεΛ։ൃ͢ΔνʔϜʹॴଐ͍ͯ͠·͢

    SORACOM UG
  3. ͜Μͳܦݧ͋Γ·ͤΜ͔ʁ 1IPUPDSFEJU#FSOJF(PMECBDIPO7JTVBMIVOU$$#:/$/%

  4. ͜Μͳܦݧ͋Γ·ͤΜ͔ʁ 4 8IBUEPZPVEPXIFO ZPVSFDFJWF4MBDL NFTTBHFJO&OHMJTI

  5. ͜Μͳܦݧ͋Γ·ͤΜ͔ʁ 5 :PV ӳޠͷϝοηʔδ͔ɾɾɾ Α͘Θ͔Βͳ͍͔Β(PPHMF ຋༁ʹίϐϖͯ֬͠ೝ͠Α ͏

  6. ͜Μͳܦݧ͋Γ·ͤΜ͔ʁ 6 :PV ͜Ε͔Βຖճίϐϖͯ͠ ຋༁͢Δͷ͸ͪΐͬͱखؒ ͕͔͔Δͳ͊ɾɾɾ

  7. ໘౗Λղܾ͢Δʹ͸ʁ

  8. ໘౗Λղܾ͢Δʹ͸ʁ 8 :PV ӳޠ͕Ͱ͖Ε͹໰୊ͳ͍ ͠ɺ͜ΕΛ͖͔͚ͬʹӳޠ ͷษڧΛ࢝ΊΑ͏͔ͳ͊

  9. ໘౗Λղܾ͢Δʹ͸ʁ 9 :PV ίϐϖ͠ͳ͍Ͱ຋༁Ͱ͖ Ε͹ɺखܰͩ͠໘౗͡Όͳ ͍͔΋͠Εͳ͍

  10. ͙͢ʹࢼͤΔ͜ͱ

  11. ͙͢ʹࢼͤΔ͜ͱ ‣ ࢒೦ͳ͕Β͙͢ʹӳޠ͕Ͱ͖ΔΑ͏ʹ͸ͳΒͳ͍ɾɾɾ ‣ ίϐϖΛ͠ͳ͍Ͱ຋༁Ͱ͖ΔΑ͏ͳ࢓૊Έ͕͋Ε͹Α͞ ͦ͏ ‣ Slack͕ࣾެ։͍ͯ͠ΔSlack App͕खܰͰศརͦ͏ ‣

    slackapi/reacjilator: A translation bot that translates a message when a user reacted with an emoji ! " # $ % & ' ( ) * + - https://github.com/slackapi/reacjilator 11
  12. ͙͢ʹࢼͤΔ͜ͱ ‣ ͜ͷSlack AppΛ࢖͑͹ϝοηʔδʹରͯ͠ࠃضͷ ֆจࣈͰϦΞΫγϣϯ͢Δ͜ͱͰɺͦͷࠃͷݴޠʹ ຋༁͞ΕͯεϨουͱͯ͠ฦ৴͞ΕΔΑ͏ʹͳΔ ‣ GitHubϦϙδτϦʹ͸HerokuͷDeployϘλϯ΋ ͋ΔͷͰNode.jsͱGoogle຋༁APIͰ໰୊ͳ͚Ε͹ खܰʹ࢖͑Δ

    12
  13. ࢼͯ͠Έͨ

  14. 14 IUUQVDIJNBOBKFUIBUFOBCMPHDPNFOUSZ

  15. มߋͨ͠ͷ͸

  16. มߋͨ͠ͷ͸ ‣ ϓϩάϥϜ͸Node.js͕ಘҙͰ͸ͳ͍ͷͰ׳Ε͍ͯΔݴޠʹ͍ͨ͠ ‣ ಈ࢈؀ڥ͸࢖͍׳Ε͍ͯΔAWS্Ͱಈ࡞͍ͤͨ͞ ‣ AWS Chalice (Python Serverless

    Microframework for AWS)Λར ༻ͯ͠Pythonʹมߋ ‣ AWS LambdaΛར༻ͯ͠ಈ࡞͢ΔΑ͏ʹมߋ ‣ aws/chalice: Python Serverless Microframework for AWS - https://github.com/aws/chalice 16
  17. มߋͨ͠ͷ͸ ‣ Your app should respond to the event request

    with an HTTP 2xx within three seconds. If it does not, we'll consider the event delivery attempt failed. After a failure, we'll retry three times, backing off exponentially. ‣ Events API | Slack - https://api.slack.com/events-api#responding_to_events ‣ AWS Lambdaͷίʔϧυελʔτ࣌΍຋༁APIͷԠ౴Λ଴͍ͬͯΔͱ3 ඵͷϦϛοτΛ௒͑Δ͜ͱ͕͋Δ ‣ ϦϛοτΛ௒͑Δͱૹ৴ݩͰࣦഊͱͳΓΠϕϯτ͕࠶ૹ͞ΕΔͷͰɺෳ ਺ճಉ͡ϝοηʔδ͕຋༁͞ΕΔ͜ͱʹͳΔ 17
  18. มߋͨ͠ͷ͸ ‣ Amazon API Gatewayܦ༝Ͱslack͔ΒͷΠϕϯτΛड͚ ෇͚ͯAmazon SNSʹૹ৴͢ΔAWS Lambdaͱɺ Amazon SNS͔ΒϝοηʔδΛड͚औͬͯॲཧΛߦ͏

    AWS Lambdaͷ2ͭʹ෼͚ͯඇಉظͰॲཧ ‣ AWS LambdaͷίʔϧυελʔτͰ3ඵҎ্͔͔ͬͨ৔߹ ʹ͸ޮՌ͕ͳ͍͕ɺ຋༁APIͷॲཧ଴ͪͰΠϕϯτ͕ෳ਺ ճૹ৴͞ΕΔ͜ͱ͸ͳ͘ͳͬͨ 18
  19. มߋͨ͠ͷ͸ ‣ ຋༁API͸ແྉͰ࢖͑Δ࿮͕͋Γ͔ͭɺొ࿥΋؆୯ͳ ͱ͜Ζͷํ͕͋Γ͕͍ͨ ‣ Microsoft Translator API ͸ແྉ࿮͕͋Δ͕ɺΞΧ΢ ϯτొ࿥ʹΫϨδοτΧʔυొ࿥͕͋Γଟগ໘౗

    ‣ Translator Text API - ࣗಈ຋༁ | Microsoft Azure - https://azure.microsoft.com/ja-jp/services/ cognitive-services/translator-text-api/ 19
  20. มߋͨ͠ͷ͸ ‣ Yandex Translate API ͳΒ͹ɺطଘͷGoogleΞΧ΢ϯτ ͰαΠϯΞοϓͰ͖Δ ‣ ແྉ࿮΋͋ΓαΠϯΞοϓͨ͠ޙɺAPI KeyΛ෷͍ग़ͤ͹ར

    ༻Մೳ ‣ ରԠ͍ͯ͠Δݴޠ਺΋ଟ͘ɺೖྗจࣈྻͷݴޠࣗಈ൑ผ΋ Մೳ ‣ Translate API — Yandex Technologies - https://tech.yandex.com/translate/ 20
  21. มߋͨ͠ͷ͸ ‣ ͔͠͠ɺͲ͏΍ΒYandex͸ϩγΞൃͷاۀ ‣ ຋༁APIΛར༻͢Δʹจࣈྻ͕APIʹૹ৴͞ΕΔ ‣ ͢΂ͯͷslackνϟϯωϧͰϝοηʔδ͕ૹ৴͞ΕΔͷ ͸ෆ͕҆͋Δ ‣ ຋༁͕࣮ߦ͞ΕΔνϟϯωϧΛݶఆ͍ͨ͠

    ‣ Yandex - Wikipedia - https://ja.wikipedia.org/wiki/Yandex 21
  22. มߋͨ͠ͷ͸ ‣ Πϕϯτͷૹ৴ݩͰίϯτϩʔϧ͢Δ͜ͱ͸Ͱ͖ͳ͍༷ࢠ ‣ ΠϕϯτΛड͚ͨํͰࢦఆͷνϟϯωϧҎ֎͸ड͚෇͚ͳ͍Α͏ʹ͢ Δ ‣ slack্Ͱදࣔ͞Ε͍ͯΔνϟϯωϧ໊Ͱ͸ͳ͘IDͰ؅ཧ͞Ε͍ͯΔ ‣ νϟϯωϧͷIDΛௐ΂Δͷʹ͸channels.list

    APIΛ࢖͑͹Α͍ ‣ खܰͳͷ͸channels.list APIͷಈ࡞ςετϖʔδͰ࣮ߦͯ݁͠ՌΛ֬ ೝ͢Δ͜ͱ ‣ channels.list method | Slack - https://api.slack.com/methods/channels.list/test 22
  23. ·ͱΊ *NBHFWJB"UUSJCVUJPO&OHJOF-JDFOTFEVOEFS$$

  24. ·ͱΊ ‣ Node.js, Google຋༁API, Heroku Ͱ໰୊ͳ͚Ε͹ެࣜ ͦͷ··Ͱ͓खܰʹ࢖͑Δ ‣ ίʔυ΋؆୯Ͱಈ࡞΋͍ܰͷͰFaaSͰͷಈ࡞΋໰୊ແ͠ ‣

    AWS Chalice͸୯७ͳ΋ͷΛ࡞Δͷʹ͸खܰͰศར ‣ YandexͷAPI͸Ṗ຋༁͢Δ৔߹΋͋Δ͕खܰ ‣ ֎෦ͷAPIΛݺͼग़͢৔߹͸ॲཧ࣌ؒʹ஫ҙ ‣ ͕͔͔࣌ؒΔ৔߹ʹ͸ඇಉظॲཧʹͯ͠ରԠ͢Δ 24
  25. ·ͱΊ ‣ ຋༁APIʹؔͯ͠͸Amazon Translateʹظ଴ ‣ Amazon Translate – χϡʔϥϧػց຋༁ –

    AWS - https://aws.amazon.com/jp/translate/ ‣ AWSͷαʔϏεͰ͋Ε͹SDKΛར༻Ͱ͖Δ ‣ IAMೝূ΋ར༻Ͱ͖ΔͷͰAPIΩʔͷ؅ཧ΋ෆཁͱͳΔ ‣ ֎෦APIʹจࣈྻΛૹ৴͢Δඞཁ͕ͳ͘ͳΔ ‣ ݱࡏ͸ϓϨϏϡʔͳͷͰར༻͍ͨ͠৔߹ʹ͸ਃ੥͕ඞཁ 25
  26. Appendix ‣ aws chaliceΛ࢖ͬͯslackͷ຋༁botΛ࡞ͬͯΈͨ #aws #chalice #slack #bot - uchimanajet7ͷϝϞ

    - http://uchimanajet7.hatenablog.com/entry/2017/12/18/102237 ‣ aws/chalice: Python Serverless Microframework for AWS - https://github.com/aws/chalice ‣ slackapi/reacjilator: A translation bot that translates a message when a user reacted with an emoji ! " # $ % & ' ( ) * + - https://github.com/slackapi/reacjilator ‣ [Japanese] Developing a bot for your workspace ຋༁ϘοτΛ࡞Δ! - https://www.slideshare.net/tomomi/japanese-developing-a-bot-for-your- workspace-82133038 26
  27. Appendix ‣ JAWS-UGʢAWS Users Group – Japanʣ - https://jaws-ug.jp/ ‣

    SORACOM User Group ͱ͸ - https://pages.soracom.jp/usergroup.html ‣ ޮՌతͳಋೖɾӡ༻ͷͨΊͷ Amazon Web Services׆༻ೖ໳ | ϚΠ φϏϒοΫε - https://book.mynavi.jp/ec/products/detail/id=54224 ‣ Who am I? - https://uchimanajet7.github.io/whoami/ 27