Upgrade to Pro — share decks privately, control downloads, hide ads and more …

golangで作るslackbot

Takumi Yoshida
September 01, 2017

 golangで作るslackbot

Takumi Yoshida

September 01, 2017
Tweet

More Decks by Takumi Yoshida

Other Decks in Technology

Transcript

  1. // 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() 

  2. • 1ͱಉ༷ʹSlack Client / RTMͷwebsocketΛฒྻ࣮ߦ • ແݶϧʔϓʹͯ͠ɺແݶϧʔϓ಺ͰSlackͰड͚औͬͨΠϕϯτ ຖʹॲཧΛ෼ذ • Message

    EventͩͬͨΒɺMessageͷ಺༰Λݟͯ
 @BotIDʹҰக͢Δ΋ͷͩͬͨΒॲཧΛଓߦ • botUserΛ࡞Δ • Message Event಺ͷൃݴऀͷID͔ΒNameΛऔಘͯ͠
 ड͚औͬͨϝοηʔδΛͦͷ··ฦ٫

  3. ࢀߟ • 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