Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
理想の自分を忘れないために Slack and LINE bot を作った話 / Make S...
Search
Anntoque
February 27, 2019
Programming
0
880
理想の自分を忘れないために Slack and LINE bot を作った話 / Make Slack API and LINE bot to not forget ideal myself
https://github.com/anntoque/commit-gypsum
Anntoque
February 27, 2019
Tweet
Share
More Decks by Anntoque
See All by Anntoque
【Sapporo Data Pioneers #1 】データのライフサイクルとSapporo Data Pioneersの思いについて
anntoque
1
410
【istyle Data Talk #01】越境できるデータの組織・人材を目指して/ istyle data talk 01 Data Organization
anntoque
1
990
what Azure Synapse
anntoque
0
3k
REDASH JOURNEY
anntoque
0
1.4k
データドリブンを提供するサービス Brand Officialのアーキテクチャ / brand official architecture
anntoque
0
1.6k
redash運用アンチパターン
anntoque
0
3.3k
SQL実践入門night_LT資料_YASU11552288
anntoque
0
540
Other Decks in Programming
See All in Programming
從零到一:搭建你的第一個 Observability 平台
blueswen
1
900
Passkeys for Java Developers
ynojima
3
850
Cline指示通りに動かない? AI小説エージェントで学ぶ指示書の書き方と自動アップデートの仕組み
kamomeashizawa
1
470
XSLTで作るBrainfuck処理系
makki_d
0
200
GoのWebAssembly活用パターン紹介
syumai
3
10k
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfold' relates to 'iterate'"
philipschwarz
PRO
0
190
2度もゼロから書き直して、やっとブラウザでぬるぬる動くAIに辿り着いた話
tomoino
0
160
人には人それぞれのサービス層がある
shimabox
3
670
Benchmark
sysong
0
160
Perlで痩せる
yuukis
1
680
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
120
Haskell でアルゴリズムを抽象化する / 関数型言語で競技プログラミング
naoya
17
4.3k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
53
11k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
650
Embracing the Ebb and Flow
colly
86
4.7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Documentation Writing (for coders)
carmenintech
71
4.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Automating Front-end Workflow
addyosmani
1370
200k
Transcript
ཧͷࣗΛΕͳ͍ͨΊʹ Slack and LINE bot Λ࡞ͬͨ @YASU11552288
ΤϯδχΞ=ͷ৬ۀ
ʮΤϯδχΞʯͱͯ͢͠Δ ͨΊʹΒͳ͖Ό͍͚ͳ͍͜ͱ ʢݸਓͷݟղʣ - ࠷৽ใͷΩϟονΞοϓ - ษڧձͷࢀՃ - ΞτϓοτʢLT,
ϒϩά etcʣ - ίʔυΛॻ͘
ΤϯδχΞͱ͍ͯͨ͠͠ ΤϯδχΞҎ֎ͷ໘ͰΓ͍ͨ͜ͱ͋Δ ʢීஈͷۀͪΖΜ͋Δʣ
ཧ ଉൈ͖ VS VS ࣄ Lv 99 Lv 99 Lv
10
ͷલͷࣄͰࡴ… ଵଦͷ༠ʹෛ͚ͯ͠·͏… Ͳ͏͢Δ͔
ཧΛҙࣝ͢Δ࣌ؒΛ૿͢ - ࣄ18࣌ؒඞͣҙࣝ͢Δ - ଵଦৗʹແҙࣝʹߦ͏ - ཧ͚͕ͩෆఆظͰνΣοΫϙΠϯτ͕ͳ͍
ʮΤϯδχΞʯͱͯ͢͠Δ ͨΊʹΒͳ͖Ό͍͚ͳ͍͜ͱ ʢݸਓͷݟղʣ - ࠷৽ใͷΩϟονΞοϓ - ษڧձͷࢀՃ - ΞτϓοτʢLT,
ϒϩά etcʣ - ίʔυΛॻ͘
1ͷऴΘΓʹίʔυΛॻ͍͔ͨ ࣗʹ͏ΈΛ࡞Ζ͏ʂʂ
ཁ݅ఆٛ - ίʔυΛॻ͍ͯΔ͔Λஅ - ࢦఆ࣌ࠁʹνΣοΫ - ॻ͍͍ͯΔ߹๙ΊΔ ɹʮຖ1commit…ͦͷੵΈॏͶ͕େࣄʂ͓ർΕ༷ࣗʂʯ - ॻ͍͍ͯͳ͍߹࠵ଅ
ɹʮͳͥcommit͠ͳ͍͍͍͍͍ʂࠓ͙͢͠Ζ͓͓͓͓͓ʂʂ
ୈ1ষ shell GitHub × Slack API ×EC2 - GitHubͰͦͷevent͕ൃੜͯ͠Δ͔֬ೝ -
௨ରSlackʹ - ࣮ߦڥEC2ͷt2.microͰ
Github API ͔ΒeventsΛऔಘ LATEST_COMMIT_DATE=`curl -u :${ACCESS_TOKEN} https:// api.github.com/users/anntoque/events | jq
'.[0] | select(. ["type"]=="PushEvent")' | jq '.["created_at"]' | cut -c 2-11`
Slack ʹ௨͢ΔʹIncoming Webhook͕ศར 4FDSFU
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 = ૹ৴͢Δϝοηʔδͷ༰
͜Μͳײ͡Ͱ௨͕དྷΔ
ൃੜͨ͠՝ - SlackΛ։͔ͳ͍ͷͰ௨ʹؾ͔ͮͳ͍ - EC2ͷٻ͕݄1000ԁ͘Β͍ - ։ൃڥͷmacͱec2ͷcentosͷshell ͷҧ͍ʹΑΓඍົʹdateͷڍಈ͕ҧ͏ ※1 ˞.BDͰEBUFίϚϯυ͕ҧ͏݅ʹ͍ͭͯcגࣜձࣾཾใγεςϜ
IUUQTUBUTVOPTZTUFNDPKQ NBD&"EBUF&#&&&#&&$&&&### &"#&"&&"
ୈ2ষ python(Flask) GitHub × LINE Message API ×Heroku - ௨ΛSlack͔Βੜ׆ʹۙͳLINEʹ
- AWS͔ΒແྉͷHerokuʹҠߦ (lamdaͱ͔ECRͷଘࡏΛ͍ͬͯͨΒ͔ͦͬͪ͋ͬͨ) - shell͔Βςετॻ͖͍͢pythonʹҠߦ
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()
LINE DevelopersͰMessaging APIΛ༻͢ΔΞϓϦΛొ
ϙνϙν͢ΔͱΞΫηετʔ ΫϯͳͲ͕खʹೖΔ 4FDSFU
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))
Herokuʹڥมͷηοτ 4FDSFU
GitHubϦϙδτϦͱͷ ࿈ܞΛઃఆ
ఆظ࣮ߦͷͨΊͷHeroku SchedulerΛՃ
ൃੜͨ͠՝ᶃ - ࣗͰϝοηʔδΛඈ͞ͳ ͍ͱԠ͠ͳ͍ػೳΛ࡞ͬͯͨ
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))
ൃੜͨ͠՝ᶄ - ࣮ߦΛ11ճʹઃఆͨ͠ͷʹ 110ճ͘Β͍௨͕དྷΔڪා
None
HerokuʹProcfileͱݺΕΔαʔόىಈ࣌ʹ࣮ߦ͢ΔίϚ ϯυΛఆٛ͢ΔϑΝΠϧ͕͋Δ Procfile+Heroku SchedulerͰ࣮ߦ͕ॏෳ͍ͯͨ͠ ͱΓ͋͑ͣProcfileΛదͳ࣮ߦʹมߋ # มߋલ web: python commit-gypsum.py
# มߋޙ web: python --version
Α͏͘
݁ՌຖίʔυΛॻ͍ͨͷ͔…
TMBDL ਖ਼݄ -*/& ˞࣌
None
TMBDL ਖ਼݄ -*/& ˞࣌ Ͳ͏͍͏͜ͱ͔ QZUIPO Ҡߦظؒ ผͷίʔυ ˞ࣗવݴޠॲཧຊϊοΫ ͳΜ͔
ΔؾͰ ͳ͔ͬͨ
ͭ·ΓɺΞϓϦέʔγϣϯ͕ ͨ͠ͷ͕ࠓिͰ ·ͩӡ༻ͯ͠Ͱ͢ʂ
·ͱΊ ࠓޙͷల - όον࣮ߦ࣌commitใͳͲใΛ͏গ͍ͨ͠͠ - commit͍ͯ͠ͳ͍߹issueͷϦετΛૹ৴͢ΔͳͲ͍ͨ͠ - ςετॻ͘ ײ -
ຖcommit͢ΔͨΊͷΞϓϦΛ࡞ΔͨΊʹຖ commitͯͨ͠www - bot؆୯ͳίʔυͰΊΔ͠ɺϥΠϑϋοΫ͍͢͠ - ॳΊͯࣗͷͨΊͷΞϓϦέʔγϣϯΛ࡞͚ͬͨͲϞνϕʔγϣϯ͕ҧͬͨ - ࠷ޙʹࣗռࠐΊͯҎԼͷݴ༿Λ…
– 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@
ࢀߟࢿྉ // anntoque/commit-gypsum https://github.com/anntoque/commit-gypsum // LineBot(MessageApi)Λࢼͯ͠ΈΔ-heroku൛ - Qiita https://qiita.com/skycat_me/items/9f27cbd9354515df744a //
line-bot-sdk-pythonΛͬͯΈͨ - ࡶ৯ࢽ https://keinumata.hatenablog.com/entry/ 2018/05/08/122348