Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
golangで作るslackbot
Search
Takumi Yoshida
September 01, 2017
Technology
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
golangで作るslackbot
Takumi Yoshida
September 01, 2017
More Decks by Takumi Yoshida
See All by Takumi Yoshida
GKEでは StackDriver Loggingに どうやってログを送っているか
ytakky2014
3
5.5k
Auralization of Tech News +Change in technology interest for my 4 years.
ytakky2014
0
130
Webメディアでのdataflow活用
ytakky2014
1
580
睡眠をエンジニアリングする
ytakky2014
0
290
PHP7+Laravel5.3 on Google App Engine
ytakky2014
0
1.3k
DevOps In All About
ytakky2014
0
3.6k
Other Decks in Technology
See All in Technology
Codex概要
ymiya55
0
490
Loop Engineering これくらいでいい
mikanichinose
0
180
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
120
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
140
契約書画像からの情報抽出に特化した視覚接地モデルを育てる話
sansantech
PRO
1
160
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.3k
AI駆動開発、viviONの1年 ── うまくいったこと・いかなかったこと
vivion
0
280
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.5k
全人類(ほぼ)AWS Organizations の上でAWSを利用している、その世界を知る話
htan
1
130
継続的なAIコスト最適化
bgpat
1
270
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
140
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
170
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
1.9k
HDC tutorial
michielstock
2
950
エンジニアに許された特別な時間の終わり
watany
109
250k
Six Lessons from altMBA
skipperchong
29
4.5k
Deep Space Network (abreviated)
tonyrice
0
360
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
We Are The Robots
honzajavorek
0
390
Un-Boring Meetings
codingconduct
0
450
Building Adaptive Systems
keathley
44
3.2k
Abbi's Birthday
coloredviolet
4
10k
Making the Leap to Tech Lead
cromwellryan
135
10k
How to make the Groovebox
asonas
2
2.5k
Transcript
golangͰ࡞Δslack bot @y_takky2014
• εϥΠυதͷGopher Renée FrenchʹΑͬͯσβΠϯ͞Ε·ͨ͠ http://reneefrench.blogspot.com/ • εϥΠυ্ͷ GopherͷҰ෦ը૾ @tenten͞Μͷ gopher-stickersΛ༻͍ͯ͠·͢
(https://github.com/tenntenn/gopher-stickers)
ΞδΣϯμ • ͳͥ golang ͰBotΛ࡞Δͷ͔ • golangͰͷSlackBotͷ࣮ํ๏(Sample) • ※SampleϓϩάϥϜطଘͷBotΛݩʹ ۀ࣌ؒ֎Ͱͬ͘͞ͱ࡞ͬͨͷ
SlackBotͷ࡞Γํ • hubot • Botkit • API (Rest / WebSocket)
hubot • botΛ࡞͢ΔͨΊͷϑϨʔϜϫʔΫ • AdapterͷΓସ͑Ͱͦͷ··πʔϧͷҠߦ͕Մೳ • coffeescript
botkit • ಛఆͷαʔϏε(slackFacebook)ʹಛԽͨ͠ Bot࡞ϑϨʔϜϫʔΫ • Interactive Button͕ѻ͍͍͢ • Node.js
API (Rest / WebSocket) • Slack͕ఏڙ͍ͯ͠ΔAPIͰϝοηʔδΛૹ৴͢Δ • API͕ఏڙ͞Ε͍ͯΕͳΜͰͰ͖Δ • ͍ΘΏΔWebAPIϕʔεͷͷͱ
WebSocketϕʔεͷͷͷ2छྨ • ࣮ݴޠΘͣ • ࠓճgolang
ͳͥgolangͳͷ͔? • ίϯύΠϧ͠ͱ͚࣮ߦڥΘͣ • ଞγεςϜͱ࿈ܞ͢Δ࣌ʹ࣮͍͢͠
४උ • https://api.slack.com/bot-users ͷ new bot user integration͔Βslack botΛ࡞͢Δ •
API_TOKENϝϞ͓ͬͯ͘ • botͷը૾͓ΈͰ
४උ • ඞཁͳIDΛऔಘ͓ͯ͘͠ • channel IDͷऔಘ • https://api.slack.com/methods/channels.list/test • BotIDͷऔಘ
• https://api.slack.com/methods/users.list/test
golangͰͲ͏࣮͢Δ͔ • https://github.com/nlopes/slack Λ͏ • Installing • go get -u
github.com/nlopes/slack
1. ఆظతʹϝοηʔδΛૹ৴͢Δ • github.com/robfig/cronΛ͏ • golang্Ͱఆظ࣮ߦΛαϙʔτ͢ΔϥΠϒϥϦ
// slack ClientΛͭ͘Δ api : = slack.New(API_TOKEN) // slack Real
Time Messaging APIΛ͏ rtm := api.NewRTM() // webSocketΛฒྻͰ࣮ߦ͢Δ go rtm.ManageConnection() // cronΛ࡞͢Δɻ 5ຖʹRTM APIͰϝοηʔδΛಛఆCHANNEL_IDʹૹΔ c := cron.New() c.AddFunc(“0 */5 * * * *”, func () {rtm.SendMessage(rtm.NewOutgoingMessage(“test”, CHANNEL_ID))}) c.Start()
None
2. ϝϯγϣϯʹԠ͢Δ
• 1ͱಉ༷ʹSlack Client / RTMͷwebsocketΛฒྻ࣮ߦ • ແݶϧʔϓʹͯ͠ɺແݶϧʔϓͰSlackͰड͚औͬͨΠϕϯτ ຖʹॲཧΛذ • Message
EventͩͬͨΒɺMessageͷ༰Λݟͯ @BotIDʹҰக͢ΔͷͩͬͨΒॲཧΛଓߦ • botUserΛ࡞Δ • Message EventͷൃݴऀͷID͔ΒNameΛऔಘͯ͠ ड͚औͬͨϝοηʔδΛͦͷ··ฦ٫
None
3. ఱؾ༧ใػೳΛ͚Δ • ϝϯγϣϯʹԠͯ͠ఱؾΛڭ͑ͯ͘ΕΔΑ͏ʹ͢Δ • livedoorͷఏڙ͍ͯ͠ΔWeather Hacks APIΛ༻͢Δ
APIୟ͍ͨ݁ՌΛ͍͍͢ܗʹܗͯ͠ฦ٫͢Δ
• @bot ఱؾ ͷ߹ఱؾΛڭ͑ͯ͘ΕΔΑ͏ʹ͢Δ • ఱؾAPIΛୟ͍ͨ݁Ռͷmap(࿈ྻ)Λճͯ͠ ݁ՌΛPost
None
·ͱΊ • golangͰͷbot࣮ྫΛհ • golangϥΠϒϥϦ͕ଟʑ͋ΔͷͰ ֎෦APIͱͷܨ͗ࠐ͕͔ͳΓָ • ֎෦ίϚϯυ࣮ߦΓ͍͢
ࢀߟ • golang Ͱ࢝ΊΔ Slack bot ։ൃ • http://blog.kaneshin.co/entry/2016/12/03/162653 •
GolangͰSlack Interactive MessageΛͬͨBotΛॻ͘ • http://tech.mercari.com/entry/2017/05/23/095500 • Gopher Stickers • https://github.com/tenntenn/gopher-stickers
• ΦϦδφϧͷGopher Renee FrenchʹΑͬͯσβΠϯ ͞Ε·ͨ͠ɻ • εϥΠυ্ͷ GopherͷҰ෦ը૾ @tenten͞Μͷ gopher-stickersΛ༻͍ͯ͠·͢
(https://github.com/tenntenn/gopher-stickers)