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
280
【istyle Data Talk #01】越境できるデータの組織・人材を目指して/ istyle data talk 01 Data Organization
anntoque
1
920
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
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
CSC509 Lecture 12
javiergs
PRO
0
160
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Remix on Hono on Cloudflare Workers
yusukebe
1
280
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fireside Chat
paigeccino
34
3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
4 Signs Your Business is Dying
shpigford
180
21k
Done Done
chrislema
181
16k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
RailsConf 2023
tenderlove
29
900
Large-scale JavaScript Application Architecture
addyosmani
510
110k
YesSQL, Process and Tooling at Scale
rocio
169
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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