aws chaliceで作るslack翻訳bot

68f1ac5343869bf471bb238e46c5c989?s=47 uchimanajet7
January 26, 2018

aws chaliceで作るslack翻訳bot

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

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

#mastercloud
#aws
#slack

68f1ac5343869bf471bb238e46c5c989?s=128

uchimanajet7

January 26, 2018
Tweet

Transcript

  1. 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
  2. 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
  3. 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
  4. 18.

    มߋͨ͠ͷ͸ ‣ Amazon API Gatewayܦ༝Ͱslack͔ΒͷΠϕϯτΛड͚ ෇͚ͯAmazon SNSʹૹ৴͢ΔAWS Lambdaͱɺ Amazon SNS͔ΒϝοηʔδΛड͚औͬͯॲཧΛߦ͏

    AWS Lambdaͷ2ͭʹ෼͚ͯඇಉظͰॲཧ ‣ AWS LambdaͷίʔϧυελʔτͰ3ඵҎ্͔͔ͬͨ৔߹ ʹ͸ޮՌ͕ͳ͍͕ɺ຋༁APIͷॲཧ଴ͪͰΠϕϯτ͕ෳ਺ ճૹ৴͞ΕΔ͜ͱ͸ͳ͘ͳͬͨ 18
  5. 19.

    มߋͨ͠ͷ͸ ‣ ຋༁API͸ແྉͰ࢖͑Δ࿮͕͋Γ͔ͭɺొ࿥΋؆୯ͳ ͱ͜Ζͷํ͕͋Γ͕͍ͨ ‣ Microsoft Translator API ͸ແྉ࿮͕͋Δ͕ɺΞΧ΢ ϯτొ࿥ʹΫϨδοτΧʔυొ࿥͕͋Γଟগ໘౗

    ‣ Translator Text API - ࣗಈ຋༁ | Microsoft Azure - https://azure.microsoft.com/ja-jp/services/ cognitive-services/translator-text-api/ 19
  6. 20.

    มߋͨ͠ͷ͸ ‣ Yandex Translate API ͳΒ͹ɺطଘͷGoogleΞΧ΢ϯτ ͰαΠϯΞοϓͰ͖Δ ‣ ແྉ࿮΋͋ΓαΠϯΞοϓͨ͠ޙɺAPI KeyΛ෷͍ग़ͤ͹ར

    ༻Մೳ ‣ ରԠ͍ͯ͠Δݴޠ਺΋ଟ͘ɺೖྗจࣈྻͷݴޠࣗಈ൑ผ΋ Մೳ ‣ Translate API — Yandex Technologies - https://tech.yandex.com/translate/ 20
  7. 22.

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

    APIΛ࢖͑͹Α͍ ‣ खܰͳͷ͸channels.list APIͷಈ࡞ςετϖʔδͰ࣮ߦͯ݁͠ՌΛ֬ ೝ͢Δ͜ͱ ‣ channels.list method | Slack - https://api.slack.com/methods/channels.list/test 22
  8. 24.

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

    AWS Chalice͸୯७ͳ΋ͷΛ࡞Δͷʹ͸खܰͰศར ‣ YandexͷAPI͸Ṗ຋༁͢Δ৔߹΋͋Δ͕खܰ ‣ ֎෦ͷAPIΛݺͼग़͢৔߹͸ॲཧ࣌ؒʹ஫ҙ ‣ ͕͔͔࣌ؒΔ৔߹ʹ͸ඇಉظॲཧʹͯ͠ରԠ͢Δ 24
  9. 25.

    ·ͱΊ ‣ ຋༁APIʹؔͯ͠͸Amazon Translateʹظ଴ ‣ Amazon Translate – χϡʔϥϧػց຋༁ –

    AWS - https://aws.amazon.com/jp/translate/ ‣ AWSͷαʔϏεͰ͋Ε͹SDKΛར༻Ͱ͖Δ ‣ IAMೝূ΋ར༻Ͱ͖ΔͷͰAPIΩʔͷ؅ཧ΋ෆཁͱͳΔ ‣ ֎෦APIʹจࣈྻΛૹ৴͢Δඞཁ͕ͳ͘ͳΔ ‣ ݱࡏ͸ϓϨϏϡʔͳͷͰར༻͍ͨ͠৔߹ʹ͸ਃ੥͕ඞཁ 25
  10. 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
  11. 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