Backend (backend/go.mod): - github.com/go-pkgz/auth/v2 v2.1.2 → v2.1.4 - github.com/klauspost/compress v1.18.5 → v1.18.6 - github.com/redis/go-redis/v9 v9.18.0 → v9.19.0 - github.com/slack-go/slack v0.21.1 → v0.23.1 - golang.org/x/crypto v0.50.0 → v0.51.0 - golang.org/x/image v0.39.0 → v0.40.0 - golang.org/x/net v0.53.0 → v0.54.0 - golang.org/x/sys v0.43.0 → v0.44.0 - golang.org/x/text v0.36.0 → v0.37.0 Example (backend/_example/memory_store/go.mod): - golang.org/x/crypto v0.50.0 → v0.51.0 - golang.org/x/image v0.39.0 → v0.40.0 - golang.org/x/net v0.53.0 → v0.54.0 - golang.org/x/sys v0.43.0 → v0.44.0 Transitive cleanup: github.com/dgryski/go-rendezvous is no longer required after redis/go-redis bump and gets pruned by `go mod tidy`. `go mod tidy` + `go mod vendor` run on both modules. Both build with -race and full test suites pass.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package slack
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
)
|
|
|
|
// SocketModeConnection contains various details about the SocketMode connection.
|
|
// It is returned by an "apps.connections.open" API call.
|
|
type SocketModeConnection struct {
|
|
URL string `json:"url,omitempty"`
|
|
Data map[string]interface{} `json:"-"`
|
|
}
|
|
|
|
type openResponseFull struct {
|
|
SlackResponse
|
|
SocketModeConnection
|
|
}
|
|
|
|
// StartSocketModeContext calls the "apps.connections.open" endpoint and returns the provided URL and the full Info block with a custom context.
|
|
//
|
|
// To have a fully managed Socket Mode connection, use `socketmode.New()`, and call `Run()` on it.
|
|
func (api *Client) StartSocketModeContext(ctx context.Context) (info *SocketModeConnection, websocketURL string, err error) {
|
|
response := &openResponseFull{}
|
|
err = api.postJSONMethod(ctx, "apps.connections.open", api.appLevelToken, nil, response)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
if response.Err() == nil {
|
|
api.Debugln("Using URL:", response.SocketModeConnection.URL)
|
|
}
|
|
|
|
// According to the API documentation at https://api.slack.com/apis/socket-mode, we
|
|
// can add a query parameter `debug_reconnects=true` to the URL to make the connection
|
|
// time significantly shorter (360 seconds).
|
|
if api.debug {
|
|
u, _ := url.Parse(response.SocketModeConnection.URL)
|
|
q := u.Query()
|
|
q.Set("debug_reconnects", "true")
|
|
u.RawQuery = q.Encode()
|
|
response.SocketModeConnection.URL = u.String()
|
|
}
|
|
return &response.SocketModeConnection, response.SocketModeConnection.URL, response.Err()
|
|
}
|