| 1 | Slack API in Go [](https://pkg.go.dev/github.com/slack-go/slack) |
| 2 | =============== |
| 3 | |
| 4 | This is the original Slack library for Go created by Norberto Lopes, transferred to a GitHub organization. |
| 5 | |
| 6 | You can also chat with us on the #slack-go, #slack-go-ja Slack channel on the Gophers Slack. |
| 7 | |
| 8 |  |
| 9 | |
| 10 | This library supports most if not all of the `api.slack.com` REST |
| 11 | calls, as well as the Real-Time Messaging protocol over websocket, in |
| 12 | a fully managed way. |
| 13 | |
| 14 | ## Project Status |
| 15 | There is currently no major version released. |
| 16 | Therefore, minor version releases may include backward incompatible changes. |
| 17 | |
| 18 | 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. |
| 19 | |
| 20 | ## Installing |
| 21 | |
| 22 | ### *go get* |
| 23 | |
| 24 | $ go get -u github.com/slack-go/slack |
| 25 | |
| 26 | ## Example |
| 27 | |
| 28 | ### Getting all groups |
| 29 | |
| 30 | ```golang |
| 31 | import ( |
| 32 | "fmt" |
| 33 | |
| 34 | "github.com/slack-go/slack" |
| 35 | ) |
| 36 | |
| 37 | func main() { |
| 38 | api := slack.New("YOUR_TOKEN_HERE") |
| 39 | // If you set debugging, it will log all requests to the console |
| 40 | // Useful when encountering issues |
| 41 | // slack.New("YOUR_TOKEN_HERE", slack.OptionDebug(true)) |
| 42 | groups, err := api.GetUserGroups(slack.GetUserGroupsOptionIncludeUsers(false)) |
| 43 | if err != nil { |
| 44 | fmt.Printf("%s\n", err) |
| 45 | return |
| 46 | } |
| 47 | for _, group := range groups { |
| 48 | fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name) |
| 49 | } |
| 50 | } |
| 51 | ``` |
| 52 | |
| 53 | ### Getting User Information |
| 54 | |
| 55 | ```golang |
| 56 | import ( |
| 57 | "fmt" |
| 58 | |
| 59 | "github.com/slack-go/slack" |
| 60 | ) |
| 61 | |
| 62 | func main() { |
| 63 | api := slack.New("YOUR_TOKEN_HERE") |
| 64 | user, err := api.GetUserInfo("U023BECGF") |
| 65 | if err != nil { |
| 66 | fmt.Printf("%s\n", err) |
| 67 | return |
| 68 | } |
| 69 | fmt.Printf("ID: %s, Fullname: %s, Email: %s\n", user.ID, user.Profile.RealName, user.Profile.Email) |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | ## Minimal Socket Mode usage: |
| 74 | |
| 75 | See https://github.com/slack-go/slack/blob/master/examples/socketmode/socketmode.go |
| 76 | |
| 77 | |
| 78 | ## Minimal RTM usage: |
| 79 | |
| 80 | As mentioned in https://api.slack.com/rtm - for most applications, Socket Mode is a better way to communicate with Slack. |
| 81 | |
| 82 | See https://github.com/slack-go/slack/blob/master/examples/websocket/websocket.go |
| 83 | |
| 84 | |
| 85 | ## Minimal EventsAPI usage: |
| 86 | |
| 87 | See https://github.com/slack-go/slack/blob/master/examples/eventsapi/events.go |
| 88 | |
| 89 | ## Socketmode Event Handler (Experimental) |
| 90 | |
| 91 | When using socket mode, dealing with an event can be pretty lengthy as it requires you to route the event to the right place. |
| 92 | |
| 93 | 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. |
| 94 | |
| 95 | See [./examples/socketmode_handler/socketmode_handler.go](./examples/socketmode_handler/socketmode_handler.go) |
| 96 | ## Contributing |
| 97 | |
| 98 | You are more than welcome to contribute to this project. Fork and |
| 99 | make a Pull Request, or create an Issue if you see any problem. |
| 100 | |
| 101 | Before making any Pull Request please run the following: |
| 102 | |
| 103 | ``` |
| 104 | make pr-prep |
| 105 | ``` |
| 106 | |
| 107 | This will check/update code formatting, linting and then run all tests |
| 108 | |
| 109 | ## License |
| 110 | |
| 111 | BSD 2 Clause license |