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

理想の自分を忘れないために Slack and LINE bot を作った話 / Make S...

Anntoque
February 27, 2019

理想の自分を忘れないために Slack and LINE bot を作った話 / Make Slack API and LINE bot to not forget ideal myself

Anntoque

February 27, 2019
Tweet

More Decks by Anntoque

Other Decks in Programming

Transcript

  1. Incoming WebhookͰ
 Slack ΁ϝοηʔδΛૹ৴ curl -X POST --data-urlencode "payload={\"channel\": \"#test-

    webhook\", \"username\":\"webhookbot\",\"text\": \"$ {COMMITED_MESSAGE}\", \"icon_emoji\": \":man-lifting-weights:\"}" ${WEBHOOK_URL} ※ COMMITED_MESSAGE = ૹ৴͢Δϝοηʔδͷ಺༰
  2. ൃੜͨ͠՝୊ - SlackΛ։͔ͳ͍ͷͰ௨஌ʹؾ͔ͮͳ͍ - EC2ͷ੥ٻ͕݄1000ԁ͘Β͍ - ։ൃ؀ڥͷmacͱec2ͷcentosͷshell ͷҧ͍ʹΑΓඍົʹdateͷڍಈ͕ҧ͏ ※1 ˞.BDͰEBUFίϚϯυ͕ҧ͏݅ʹ͍ͭͯcגࣜձࣾཾ໺৘ใγεςϜ

    IUUQTUBUTVOPTZTUFNDPKQ NBD&"EBUF&#&&&#&&$&&&### &"#&"&&"
  3. ୈ2ষ python(Flask)
 GitHub × LINE Message API ×Heroku - ௨஌ΛSlack͔Βੜ׆ʹ਎ۙͳLINEʹ

    - AWS͔ΒແྉͷHerokuʹҠߦ
 (lamdaͱ͔ECRͷଘࡏΛ஌͍ͬͯͨΒͦͬͪ΋͔͋ͬͨ΋) - shell͔Βςετ΋ॻ͖΍͍͢pythonʹҠߦ
  4. Github API ͔ΒeventsΛऔಘ ʢpythonʣ headers = {'Authorization': 'token ' +

    github_token} def get_github_events(): response = requests.get( 'https://api.github.com/users/anntoque/events', headers=headers) return response.json()
  5. LINE Message APIͰ
 ϝοηʔδΛૹ৴ʢFlaskʣ @handler.add(MessageEvent, message=TextMessage) def handle_message(event): events =

    get_github_events() last_commit_date = get_last_commit(events) message_text = fix_message(last_commit_date) line_bot_api.reply_message( event.reply_token, TextSendMessage(text=message_text))
  6. LINE Message APIͰϝοηʔδΛૹ৴ʢվʣ - APIͰ͋Δඞཁͳ͍ͷͰFlaskഉআ - reply_messageͰ͸push_messageΛ࢖༻ def main(): events

    = get_github_events() last_commit_date = get_last_commit(events) message_text = fix_message(last_commit_date) line_bot_api.push_message( LINE_USER_ID, TextSendMessage(text=message_text))
  7. ·ͱΊ ࠓޙͷల๬ - όον࣮ߦ೔࣌΍commit৘ใͳͲ৘ใΛ΋͏গ͠଍͍ͨ͠ - commit͍ͯ͠ͳ͍৔߹͸issueͷϦετΛૹ৴͢ΔͳͲ͍ͨ͠ - ςετॻ͘ ײ૝ -

    ຖ೔commit͢ΔͨΊͷΞϓϦΛ࡞ΔͨΊʹຖ೔ commitͯͨ͠www - bot͸؆୯ͳίʔυͰ૊ΊΔ͠ɺϥΠϑϋοΫ͠΍͍͢
 - ॳΊͯࣗ෼ͷͨΊͷΞϓϦέʔγϣϯΛ࡞͚ͬͨͲϞνϕʔγϣϯ͕ҧͬͨ - ࠷ޙʹࣗռ΋ࠐΊͯҎԼͷݴ༿Λ…
  8. – Leonardo da Vinci “Iron rusts from disuse; water loses

    its purity from stagnation ... even so in inaction sap the vigor of the mind.” “మ΋࢖Θͳ͍ͱḊͼΔɻਫ΋ྲྀΕͳ͚Ε͹ཎΉɻ ଵଦ΋·ͨɺ৺ͷ׆ྗΛୣͬͯ͠·͏ɻ” -FPOBSEPEB7JODJ*SPOSVTUTGSPNEJTVTFXBUFSMPTFTJUT IUUQTXXXCSBJOZRVPUFDPNRVPUFTMFPOBSEP@EB@WJODJ@