Slacker is a Golang package to interface with Slack's API and Real Time Messaging API.
For full documentation, always check godoc.
It's always fun to see quick ways to use a package. Here are some examples of how to use slacker for simple things.
c := slacker.NewAPIClient("your-slack-token", "")
channels, err := c.ChannelsList()
if err != nil {
panic(err)
}
// Map channels so we can easily retrieve a channel by name.
mappedChannels := map[string]*slacker.Channel{}
for _, channel := range channels {
mappedChannels[channel.Name] = channel
}
fmt.Printf("Channels: %+v", mappedChannels)
c := slacker.NewAPIClient("your-slack-token", "")
users, err := c.UsersList()
if err != nil {
panic(err)
}
mappedUsers := map[string]*slacker.User{}
for _, user := range users {
mappedUsers[user.ID] = user
}
This example starts a websocket to Slack's RTM API and displays events as they come in.
c := slacker.NewAPIClient("your-slack-token", "")
rtmStart, err := c.RTMStart()
if err != nil {
panic(err)
}
broker := slacker.NewRTMBroker(rtmStart)
broker.Connect()
for {
event := <-broker.Events()
fmt.Println(event.Type)
if event.Type == "message" {
msg, err := event.Message()
if err != nil {
panic(err)
}
fmt.Println(msg.Text)
}
}
Slacker is released under the MIT License.