Skip to content

slack-go/slack

Folders and files

NameName
Last commit message
Last commit date
Aug 20, 2024
Oct 14, 2024
Aug 22, 2022
Nov 6, 2024
Aug 15, 2024
Mar 9, 2022
Apr 24, 2023
Apr 26, 2024
Nov 5, 2020
Nov 14, 2024
Jan 24, 2015
Mar 8, 2020
Nov 14, 2024
Apr 4, 2019
Jul 15, 2024
Jan 5, 2021
Nov 12, 2024
Nov 6, 2024
Apr 18, 2021
Oct 7, 2020
Apr 23, 2022
Nov 16, 2020
Jul 15, 2024
Dec 7, 2022
Oct 14, 2024
Nov 24, 2020
May 8, 2019
Oct 14, 2024
Oct 14, 2024
Aug 19, 2021
May 8, 2019
Oct 14, 2024
May 8, 2019
Feb 27, 2019
Oct 14, 2024
Feb 10, 2024
Feb 19, 2020
Feb 19, 2020
Jul 30, 2020
Nov 5, 2020
Aug 15, 2024
Aug 18, 2020
Oct 14, 2024
Sep 7, 2021
Mar 15, 2024
Mar 15, 2024
Nov 12, 2024
Nov 12, 2024
Nov 6, 2024
Nov 5, 2020
May 8, 2019
Feb 27, 2020
Oct 21, 2023
Oct 21, 2023
Jul 15, 2024
Apr 18, 2022
Jul 15, 2024
Apr 26, 2024
Oct 14, 2024
Oct 14, 2024
Oct 14, 2024
Oct 14, 2024
Aug 15, 2024
Nov 14, 2024
Aug 15, 2024
Jul 22, 2015
Oct 14, 2024
Oct 14, 2024
Oct 9, 2020
May 31, 2021
Apr 13, 2019
Aug 9, 2019
Aug 22, 2022
Aug 9, 2019
Jul 15, 2024
Apr 4, 2019
Jul 15, 2024
Apr 4, 2019
May 11, 2020
Aug 21, 2024
Aug 15, 2024
Oct 14, 2024
Oct 14, 2024
Feb 28, 2022
Feb 28, 2022
Mar 16, 2021
Nov 2, 2019
Mar 16, 2021
Aug 31, 2022
Aug 31, 2022
Feb 1, 2024
Jul 14, 2023
Jul 26, 2015
Jul 22, 2015
Dec 7, 2020
Oct 6, 2018
Oct 2, 2020
Jul 15, 2024
Aug 4, 2023
Feb 24, 2022
Feb 14, 2022
Apr 13, 2023
Oct 8, 2021
Jun 23, 2022
Aug 15, 2024
Jun 1, 2022
Jul 15, 2024
Jan 27, 2015
Jul 15, 2024
Apr 4, 2019
Jul 15, 2024
Apr 4, 2019
Jul 15, 2024
Aug 15, 2024
Aug 15, 2024
Apr 22, 2022
Nov 2, 2019
Apr 26, 2024
Dec 7, 2020
Nov 4, 2018
Aug 4, 2023
Jan 24, 2015
Feb 20, 2024
Feb 20, 2024
Jan 18, 2021
Jul 15, 2024
Apr 4, 2019
Jun 1, 2022
Jul 15, 2024
Aug 15, 2022
Jul 15, 2024
Aug 4, 2023
Jul 15, 2024
Jul 25, 2022
Jul 15, 2024
Aug 15, 2024
Jul 15, 2024
Jun 2, 2022
Aug 15, 2024
Nov 3, 2022
Nov 2, 2019
Mar 2, 2020
Nov 6, 2019
Aug 3, 2015
Mar 5, 2016
Jan 30, 2016
Aug 16, 2015
Feb 25, 2021
Jul 6, 2022
Jul 6, 2022
Nov 2, 2019
Jan 22, 2020
Jan 30, 2016
Aug 10, 2022
Jan 30, 2016
May 17, 2022
Mar 5, 2016
Jul 15, 2024
Nov 18, 2022
Jun 14, 2022
Jun 2, 2022

Repository files navigation

Slack API in Go Go Reference

This is the original Slack library for Go created by Norberto Lopes, transferred to a GitHub organization.

You can also 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.

Installing

go get

$ go get -u github.com/slack-go/slack

Example

Getting all groups

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

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)
}

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 please run the following:

make pr-prep

This will check/update code formatting, linting and then run all tests

License

BSD 2 Clause license