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
golangで作るslackbot
Search
Takumi Yoshida
September 01, 2017
Technology
190
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
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
2
240
サイバー捜査員研修(前半)
nomizone
1
2k
モダンフロントエンド 開発研修
recruitengineers
PRO
4
640
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
9k
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
Genie Codeハンズオン基礎編
taka_aki
1
120
関東Kaggler会発表資料
takoi
1
230
Breaking the Seal: Static Deobfuscation of Compiled V8 JavaScript Bytecode Malware
hshrzd
0
760
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
DatadogのBits Chatが開発組織にもたらしたもの / What Bits Chat Has Brought Us
sms_tech
1
270
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
100
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
240
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
240
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.8k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
390
Testing 201, or: Great Expectations
jmmastey
46
8.2k
A Tale of Four Properties
chriscoyier
163
24k
Designing for humans not robots
tammielis
254
26k
Chasing Engaging Ingredients in Design
codingconduct
0
270
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)