MCPcopy Index your code
hub / github.com/slack-go/slack

github.com/slack-go/slack @v0.27.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.27.0 ↗
2,953 symbols 9,416 edges 266 files 1,595 documented · 54% 26 cross-repo links
README

Slack API in Go Go Reference CI

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

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

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.

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

make pr-prep

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

License

BSD 2 Clause license

Extension points exported contracts — how you extend this code

Block (Interface)
Block defines an interface all block types should implement to ensure consistency between blocks. [23 implementers]
block.go
BlockElement (Interface)
BlockElement defines an interface that all block element types should implement. [20 implementers]
block_element.go
StreamChunk (Interface)
StreamChunk represents a single chunk in the streaming-message chunks array. [4 implementers]
chat_stream_chunks.go
DataVisualizationChart (Interface)
DataVisualizationChart is implemented by every chart payload valid inside a DataVisualizationBlock: pie, bar, area, and [4 …
block_data_visualization.go
RichTextSectionElement (Interface)
(no doc) [11 implementers]
block_rich_text.go
TableCell (Interface)
TableCell is implemented by every cell type valid inside a TableBlock row: TableRichTextCell, TableRawTextCell, and Tabl [3 …
block_table.go
DataTableCell (Interface)
DataTableCell is implemented by every cell type valid inside a DataTableBlock row: DataTableRawTextCell, DataTableRawNum [3 …
block_data_table.go
IDGenerator (Interface)
IDGenerator provides an interface for generating integer ID values. [3 implementers]
messageID.go

Core symbols most depended-on inside this repo

Printf
called by 345
socketmode/log.go
New
called by 265
slack.go
OptionAPIURL
called by 214
slack.go
Println
called by 211
socketmode/log.go
NewTextBlockObject
called by 200
block_object.go
Do
called by 182
slack.go
Write
called by 180
security.go
Err
called by 175
misc.go

Shape

Function 1,255
Method 849
Struct 702
TypeAlias 80
FuncType 43
Interface 24

Languages

Go100%

Modules by API surface

slackevents/inner_events.go122 symbols
block_element.go118 symbols
chat.go102 symbols
conversation.go85 symbols
slackevents/inner_events_test.go74 symbols
users.go68 symbols
conversation_test.go63 symbols
block_rich_text.go63 symbols
admin_conversations.go63 symbols
usergroups.go57 symbols
misc.go45 symbols
users_test.go41 symbols

Dependencies from manifests, versioned

github.com/go-test/deepv1.1.1 · 1×
github.com/pmezard/go-difflibv1.0.0 · 1×
gopkg.in/yaml.v3v3.0.1 · 1×

For agents

$ claude mcp add slack \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact