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
420
【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
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
240
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
220
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
1.4k
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
800
NPOでのDevinの活用
codeforeveryone
0
240
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
110
GoのGenericsによるslice操作との付き合い方
syumai
3
690
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.6k
童醫院敏捷轉型的實踐經驗
cclai999
0
190
「ElixirでIoT!!」のこれまでとこれから
takasehideki
0
370
Featured
See All Featured
Designing for humans not robots
tammielis
253
25k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
For a Future-Friendly Web
brad_frost
179
9.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
A designer walks into a library…
pauljervisheath
207
24k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
Scaling GitHub
holman
459
140k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
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