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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
570
睡眠をエンジニアリングする
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
【CEDEC2026】『Relink』を拡張せよ - 『GRANBLUE FANTASY: Relink - Endless Ragnarok』の開発速度と品質を守るCI運用
cygames
PRO
0
120
ラジオの科学
frievea
0
210
toio・myCobotでフィジカルAIっぽいことを行うための検討(とりあえず調査) / フィジカルAI LT(IoTLTによる開催)
you
PRO
0
280
Redmine 7.0 新機能・機能強化解説(OSC2026京都ダイジェスト版)
vividtone
1
190
LangfuseによるLLMOps基盤の構築と活用事例
zozotech
PRO
1
280
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
230
【Google Cloud Next Tokyo'26】Gemini Enterprise と Oracle AI Database で実現する、業務データ活用を実現する AI エージェント実装
shisyu_gaku
0
210
初めてのGitHub Actions / GitHub Actions at First
tooppoo
0
140
AI ネイティブな組織に Gemini Enterprise Agent Platform がなぜ必要なのか
asei
1
170
最高のシステムプロンプトを作るためにフィードバック機能を導入した話
alchemy1115
1
330
Digitization部 紹介資料
sansan33
PRO
2
7.7k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
240
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
Building a Scalable Design System with Sketch
lauravandoore
463
34k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Prompt Engineering for Job Search
mfonobong
0
390
The Cost Of JavaScript in 2023
addyosmani
55
10k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
360
Crafting Experiences
bethany
1
240
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Raft: Consensus for Rubyists
vanstee
141
7.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
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)