2021-05-05 20:03:28 +00:00
Slack API in Go [![Go Reference ](https://pkg.go.dev/badge/github.com/slack-go/slack.svg )](https://pkg.go.dev/github.com/slack-go/slack)
2018-08-06 19:47:05 +00:00
===============
2021-05-05 20:03:28 +00:00
2022-03-12 18:41:07 +00:00
This is the original Slack library for Go created by Norberto Lopes, transferred to a GitHub organization.
2018-08-06 19:47:05 +00:00
2022-03-12 18:41:07 +00:00
You can also chat with us on the #slack -go, #slack -go-ja Slack channel on the Gophers Slack.
2018-08-06 19:47:05 +00:00
2020-10-11 21:07:00 +00:00
![logo ](logo.png "icon" )
2018-08-06 19:47:05 +00:00
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.
2020-10-11 21:07:00 +00:00
## Project Status
There is currently no major version released.
Therefore, minor version releases may include backward incompatible changes.
2018-08-09 22:38:19 +00:00
2021-05-05 20:03:28 +00:00
See [CHANGELOG.md ](https://github.com/slack-go/slack/blob/master/CHANGELOG.md ) or [Releases ](https://github.com/slack-go/slack/releases ) for more information about the changes.
2018-08-06 19:47:05 +00:00
## Installing
### *go get*
2020-03-01 19:59:19 +00:00
$ go get -u github.com/slack-go/slack
2018-08-06 19:47:05 +00:00
## Example
### Getting all groups
```golang
import (
"fmt"
2020-03-01 19:59:19 +00:00
"github.com/slack-go/slack"
2018-08-06 19:47:05 +00:00
)
func main() {
api := slack.New("YOUR_TOKEN_HERE")
// If you set debugging, it will log all requests to the console
// Useful when encountering issues
2019-09-07 20:46:58 +00:00
// slack.New("YOUR_TOKEN_HERE", slack.OptionDebug(true))
2022-06-24 22:36:16 +00:00
groups, err := api.GetUserGroups(slack.GetUserGroupsOptionIncludeUsers(false))
2018-08-06 19:47:05 +00:00
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"
2020-03-01 19:59:19 +00:00
"github.com/slack-go/slack"
2018-08-06 19:47:05 +00:00
)
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)
}
```
2022-03-12 18:41:07 +00:00
## Minimal Socket Mode usage:
See https://github.com/slack-go/slack/blob/master/examples/socketmode/socketmode.go
2018-08-06 19:47:05 +00:00
## Minimal RTM usage:
2022-03-12 18:41:07 +00:00
As mentioned in https://api.slack.com/rtm - for most applications, Socket Mode is a better way to communicate with Slack.
2020-03-01 19:59:19 +00:00
See https://github.com/slack-go/slack/blob/master/examples/websocket/websocket.go
2018-08-06 19:47:05 +00:00
2018-08-09 22:38:19 +00:00
## Minimal EventsAPI usage:
2020-03-01 19:59:19 +00:00
See https://github.com/slack-go/slack/blob/master/examples/eventsapi/events.go
2018-08-09 22:38:19 +00:00
2022-06-24 22:36:16 +00:00
## Socketmode Event Handler (Experimental)
2018-08-09 22:38:19 +00:00
2022-06-24 22:36:16 +00:00
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 ](./examples/socketmode_handler/socketmode_handler.go )
2018-08-06 19:47:05 +00:00
## 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.
2020-03-01 19:59:19 +00:00
Before making any Pull Request please run the following:
```
make pr-prep
```
This will check/update code formatting, linting and then run all tests
2018-08-06 19:47:05 +00:00
## License
BSD 2 Clause license