+0
Daily
4,973
stars
1,203
forks
50
watchers
1,113
prs
574
issues
79
releases
README
Slack API in Go
===============
You can chat with us on the slack-go, slack-go-ja Slack channel on the Gophers Slack.
!logo
This library supports most if not all of the api.slack.com REST
calls, as well as the Real-Time Messaging protocol over websocket, in
a fully managed way.
Project Status
There is currently no major version released.
Therefore, minor version releases may include backward incompatible changes.
See Releases for more information about the changes.
Go Versions supported
We support the same versions of Go as the officially supported Go versions (see Go
Release Policy).
Installing
go get
bash
go get -u github.com/slack-go/slack
Example
Getting all groups
golang
import (
"fmt"
"github.com/slack-go/slack"
)
func main() {
api := slack.New("YOUR_TOKEN_HERE")
// If you set debugging, it will log all requests to the console
// Useful when encountering issues
// slack.New("YOUR_TOKEN_HERE", slack.OptionDebug(true))
groups, err := api.GetUserGroups(slack.GetUserGroupsOptionIncludeUsers(false))
if err != nil {
fmt.Printf("%s\n", err)
return
}
for _, group := range groups {
fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name)
}
}
Getting User Information
golang
import (
"fmt"
"github.com/slack-go/slack"
)
func main() {
api := slack.New("YOUR_TOKEN_HERE")
user, err := api.GetUserInfo("U023BECGF")
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Printf("ID: %s, Fullname: %s, Email: %s\n", user.ID, user.Profile.RealName, user.Profile.Email)
}
HTTP retries
Retries are off by default. Use OptionRetry(n) for 429-only retries, or OptionRetryConfig(cfg) for full control (connection, 429, opt-in 5xx). With a custom client, pass retry options after OptionHTTPClient. See package slack doc for handler details.
golang
api := slack.New("YOUR_TOKEN_HERE", slack.OptionRetry(3))
Minimal Socket Mode usage:
See https://github.com/slack-go/slack/blob/master/examples/socketmode/socketmode.go
Minimal RTM usage:
As mentioned in https://api.slack.com/rtm - for most applications, Socket Mode is a better way to communicate with Slack.
See https://github.com/slack-go/slack/blob/master/examples/websocket/websocket.go
Minimal EventsAPI usage:
See https://github.com/slack-go/slack/blob/master/examples/eventsapi/events.go
Socketmode Event Handler (Experimental)
When using socket mode, dealing with an event can be pretty lengthy as it requires you to route the event to the right place.
Instead, you can use SocketmodeHandler much like you use an HTTP handler to register which event you would like to listen to and what callback function will process that event when it occurs.
See ./examples/socketmode_handler/socketmode_handler.go
Contributing
You are more than welcome to contribute to this project. Fork and
make a Pull Request, or create an Issue if you see any problem.
Before making any Pull Request pDiscussions
#1455How do I get additional user properties?1 comments · 2025-07-01#1454socketmode_handler.go:47: Unexpected event type received: events_api2 comments · 2025-06-30#1420Not receiving response from button click1 comments · 2025-05-12#1337v0.15.00 comments · 2024-10-14#1335GitHub Sponsors1 comments · 2024-10-14#1313v0.14.00 comments · 2024-08-15#1305v0.13.10 comments · 2024-07-16#1294Any suggestions on a way to run local copies on each developers machine without conflict?1 comments · 2024-06-24
Latest release
v0.36.0 v0.36.0 2026-11-14Thanks again to Michal (@akfaew) for another round of fixes in this release. Breaking changes — read before upgrading [!WARNING] v0.36.0 includes breaking API, decoding, and serialization changes. Your code may fail to compile. Code that still compiles may decode or serialize differently. Events API URL-verification responses now use a different JSON key. Review every item below before upgrading, including RTM and Events API handlers, tests that build or compare event payloads, and code that decodes into reused values. 1. RTM group_rename event types have changed - slack.GroupRen