socket

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package socket keeps a Slack Socket Mode connection.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAuth = errors.New("slack socket: invalid auth")

Functions

func RedactURL

func RedactURL(u string) string

RedactURL keeps scheme, host and path; the query (ticket, app_id) never leaves the package.

Types

type Conn

type Conn struct {
	Open    func(ctx context.Context) (wssURL string, err error)  // apps.connections.open with the app token
	Dial    func(ctx context.Context, url string) (Socket, error) // nil uses coder/websocket
	OnState func(State)                                           // nil ignores
	Log     func(format string, args ...any)
	Queue   int // handler buffer, default 4096
	// contains filtered or unexported fields
}

func (*Conn) Run

func (c *Conn) Run(ctx context.Context, handle func(Envelope)) error

Run acks every envelope on the read loop before it is queued; handle runs on its own goroutine, so a slow handle never delays an ack. A full queue drops the envelope and reports State{Kind: "overflow"}. Backoff 1 s doubling to 30 s, reset after a hello. Returns ctx.Err() when ctx ends, after the running handle returns, or ErrInvalidAuth.

type Envelope

type Envelope struct {
	ID, Type, EventID string // EventID from payload.event_id ("" for non-events_api)
	RetryAttempt      int
	RetryReason       string
	Payload           json.RawMessage
}

type Socket

type Socket interface {
	Read(ctx context.Context) ([]byte, error)
	Write(ctx context.Context, frame []byte) error
	Close(reason string) error
}

type State

type State struct {
	Kind           StateKind
	Reason         string        // disconnect reason ("warning", "refresh_requested", "link_disabled") or the drop error, URL-redacted
	NumConnections int           // from hello
	ApproxConnTime time.Duration // hello's debug_info.approximate_connection_time
	At             time.Time
}

type StateKind

type StateKind string // "dialing", "hello", "disconnect", "dropped", "overflow"
const (
	StateDialing    StateKind = "dialing"
	StateHello      StateKind = "hello"
	StateDisconnect StateKind = "disconnect"
	StateDropped    StateKind = "dropped"
	StateOverflow   StateKind = "overflow"
)

Directories

Path Synopsis
Package sockettest is a fake Slack Socket Mode server for tests.
Package sockettest is a fake Slack Socket Mode server for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL