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 Slack API and LINE bot to not forget ideal myself
Search
Anntoque
February 27, 2019
Programming
0
830
理想の自分を忘れないために 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
160
【istyle Data Talk #01】越境できるデータの組織・人材を目指して/ istyle data talk 01 Data Organization
anntoque
1
830
what Azure Synapse
anntoque
0
2.8k
REDASH JOURNEY
anntoque
0
1.2k
データドリブンを提供するサービス Brand Officialのアーキテクチャ / brand official architecture
anntoque
0
1.4k
redash運用アンチパターン
anntoque
0
3.1k
SQL実践入門night_LT資料_YASU11552288
anntoque
0
480
Other Decks in Programming
See All in Programming
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
330
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
340
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
ONE WEDGE_company_guide
1wedge_one
0
480
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
790
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.4k
Apache Hive 4 on Treasure Data
ryukobayashi
0
320
Fast JSX: Don't clone props object #28768
yossydev
1
100
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
380
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
930
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
670
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
73
5.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Being A Developer After 40
akosma
57
580k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
Designing with Data
zakiwarfel
96
4.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
The Cult of Friendly URLs
andyhume
74
5.7k
KATA
mclloyd
15
12k
For a Future-Friendly Web
brad_frost
172
9k
The Illustrated Children's Guide to Kubernetes
chrisshort
31
46k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
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