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
850
理想の自分を忘れないために 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
0
300
【istyle Data Talk #01】越境できるデータの組織・人材を目指して/ istyle data talk 01 Data Organization
anntoque
1
930
what Azure Synapse
anntoque
0
2.9k
REDASH JOURNEY
anntoque
0
1.3k
データドリブンを提供するサービス Brand Officialのアーキテクチャ / brand official architecture
anntoque
0
1.5k
redash運用アンチパターン
anntoque
0
3.2k
SQL実践入門night_LT資料_YASU11552288
anntoque
0
510
Other Decks in Programming
See All in Programming
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
Beyond ORM
77web
2
290
Go の GC の不得意な部分を克服したい
taiyow
2
770
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
700
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Full stack testing :: basic to basic
up1
1
930
Recoilを剥がしている話
kirik
5
6.6k
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
GitHub's CSS Performance
jonrohan
1030
460k
Writing Fast Ruby
sferik
628
61k
Visualization
eitanlees
146
15k
For a Future-Friendly Web
brad_frost
175
9.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Designing for Performance
lara
604
68k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
How STYLIGHT went responsive
nonsquared
95
5.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
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