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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
420
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
130
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
4
3.8k
購入ドメインでの課題と取り組み
ykagano
0
150
おそらく日本で唯一のDevRelインターン生として
husengs7
0
170
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
410
SDDの運用にめげずに向き合った話
sansantech
PRO
1
140
freeeらしさをAIとともに作る / Creating the freee Experience with AI
ymrl
0
210
今こそ知りたいAmplifyGen2
mkdev10
2
160
Essential architectural thinking (revised edition)
ufried
0
100
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
100
Featured
See All Featured
Believing is Seeing
oripsolob
1
240
Rails Girls Zürich Keynote
gr2m
96
14k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
We Are The Robots
honzajavorek
0
390
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
320
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
520
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
540
Odyssey Design
rkendrick25
PRO
2
860
A Soul's Torment
seathinner
8
3.7k
For a Future-Friendly Web
brad_frost
184
10k
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)