Documentation
¶
Index ¶
- Constants
- Variables
- func ClassifyHTTPError(statusCode int) error
- func ClassifyNetworkError(err error) error
- func ClassifySlackError(slackError string) error
- func IsPermanentError(err error) bool
- func IsRetryableError(err error) bool
- func NewColoredLogger() *slog.Logger
- func NewColoredLoggerWithLevel(level slog.Level) *slog.Logger
- type Ack
- type Backoff
- type BackoffConfig
- type Client
- type ColoredHandler
- type ColoredHandlerOptions
- type ConnectionInfo
- type ConnectionOpenResponse
- type DebugInfo
- type DisconnectMessage
- type EmptyResponse
- type Envelope
- type EventHandler
- type HelloMessage
- type MessageResponse
- type MetricsHook
- type ModalAction
- type ModalResponse
- type NoopMetrics
- func (n *NoopMetrics) ConnectionClosed(connID string, duration time.Duration)
- func (n *NoopMetrics) ConnectionOpened(connID string)
- func (n *NoopMetrics) EnvelopeAcked(envType string, latency time.Duration)
- func (n *NoopMetrics) EnvelopeReceived(envType string)
- func (n *NoopMetrics) HandlerCompleted(envType string, duration time.Duration, err error)
- func (n *NoopMetrics) HandlerPanic(envType string, recovered any)
- func (n *NoopMetrics) HandlerStarted(envType string)
- func (n *NoopMetrics) ReconnectAttempt(attempt int, delay time.Duration)
- func (n *NoopMetrics) WriteQueueDepth(depth int)
- type Option
- type OptionsResponse
- type PermanentError
- type Response
- func NoResponse() Response
- func RespondWithBlocks(blks []blocks.Block) Response
- func RespondWithErrors(errors map[string]string) Response
- func RespondWithMessage(msg blocks.Message) Response
- func RespondWithModalClear() Response
- func RespondWithModalPush(modal blocks.Modal) Response
- func RespondWithModalUpdate(modal blocks.Modal) Response
- func RespondWithOptionGroups(groups []blocks.OptionGroup) Response
- func RespondWithOptions(opts []blocks.Option) Response
- type RetryableError
Constants ¶
const ( EnvelopeTypeHello = "hello" EnvelopeTypeDisconnect = "disconnect" EnvelopeTypeEventsAPI = "events_api" EnvelopeTypeInteractive = "interactive" EnvelopeTypeSlashCommands = "slash_commands" )
Envelope types sent by Slack.
const ( DisconnectReasonLinkDisabled = "link_disabled" DisconnectReasonWarning = "warning" DisconnectReasonRefreshRequested = "refresh_requested" )
Disconnect reasons sent by Slack.
Variables ¶
var ( ErrHelloTimeout = errors.New("timeout waiting for hello message") ErrConnectionClosed = errors.New("connection closed") ErrWriteTimeout = errors.New("write timeout") ErrShuttingDown = errors.New("client is shutting down") ErrHandlerTimeout = errors.New("handler timeout") ErrConcurrencyLimit = errors.New("concurrency limit reached") )
Error sentinel values.
Functions ¶
func ClassifyHTTPError ¶
ClassifyHTTPError classifies an HTTP response status as permanent or retryable.
func ClassifyNetworkError ¶
ClassifyNetworkError classifies a network error as retryable.
func ClassifySlackError ¶
ClassifySlackError classifies a Slack API error as permanent or retryable.
func IsPermanentError ¶
IsPermanentError returns true if the error should not be retried.
func IsRetryableError ¶
IsRetryableError returns true if the error may succeed on retry.
func NewColoredLogger ¶
NewColoredLogger creates a new slog.Logger with colored output. This is a convenience function for quick setup.
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
Backoff implements exponential backoff with jitter.
func NewBackoff ¶
func NewBackoff(cfg BackoffConfig) *Backoff
NewBackoff creates a new Backoff with the given configuration.
func (*Backoff) CheckStable ¶
CheckStable checks if the connection has been stable long enough to reset. Returns true if the backoff counter was reset.
func (*Backoff) MarkConnected ¶
func (b *Backoff) MarkConnected()
MarkConnected should be called when a connection is successfully established. It records the time for stability tracking.
type BackoffConfig ¶
type BackoffConfig struct {
BaseDelay time.Duration // Initial delay (default: 1s)
MaxDelay time.Duration // Maximum delay (default: 30s)
MaxJitter time.Duration // Maximum random jitter (default: 1s)
StableTime time.Duration // Time before resetting attempts (default: 60s)
}
BackoffConfig configures the backoff behavior.
func DefaultBackoffConfig ¶
func DefaultBackoffConfig() BackoffConfig
DefaultBackoffConfig returns the default backoff configuration.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Socket Mode client for Slack.
func (*Client) On ¶
func (c *Client) On(eventType string, handler EventHandler)
On registers a handler for the given event type.
func (*Client) OnEventsAPI ¶
func (c *Client) OnEventsAPI(handler EventHandler)
OnEventsAPI registers a handler for Events API events.
func (*Client) OnInteractive ¶
func (c *Client) OnInteractive(handler EventHandler)
OnInteractive registers a handler for interactive events (buttons, modals, etc).
func (*Client) OnSlashCommand ¶
func (c *Client) OnSlashCommand(handler EventHandler)
OnSlashCommand registers a handler for slash commands.
type ColoredHandler ¶
type ColoredHandler struct {
// contains filtered or unexported fields
}
ColoredHandler is a slog.Handler that outputs colored, human-readable logs.
func NewColoredHandler ¶
func NewColoredHandler(opts *ColoredHandlerOptions) *ColoredHandler
NewColoredHandler creates a new colored log handler. Writes to os.Stderr by default.
func NewColoredHandlerWithWriter ¶
func NewColoredHandlerWithWriter(w io.Writer, opts *ColoredHandlerOptions) *ColoredHandler
NewColoredHandlerWithWriter creates a new colored log handler with a custom writer.
type ColoredHandlerOptions ¶
type ColoredHandlerOptions struct {
// Level is the minimum level to log. Defaults to slog.LevelInfo.
Level slog.Leveler
// TimeFormat is the format for timestamps. Defaults to "15:04:05".
TimeFormat string
// ShowDate includes the date in timestamps. Defaults to false.
ShowDate bool
}
ColoredHandlerOptions configures the colored handler.
type ConnectionInfo ¶
type ConnectionInfo struct {
AppID string `json:"app_id"`
}
ConnectionInfo contains app identification from the hello message.
type ConnectionOpenResponse ¶
type ConnectionOpenResponse struct {
OK bool `json:"ok"`
URL string `json:"url"`
Error string `json:"error,omitempty"`
}
ConnectionOpenResponse is the response from apps.connections.open API.
type DebugInfo ¶
type DebugInfo struct {
Host string `json:"host"`
Started string `json:"started"`
BuildNumber int `json:"build_number"`
ApproximateConnectionTime int `json:"approximate_connection_time"`
}
DebugInfo contains connection debugging information from the hello message.
type DisconnectMessage ¶
type DisconnectMessage struct {
Type string `json:"type"`
Reason string `json:"reason"`
DebugInfo DebugInfo `json:"debug_info"`
}
DisconnectMessage is sent by Slack when requesting disconnection.
type EmptyResponse ¶
type EmptyResponse struct{}
EmptyResponse represents an acknowledgment with no payload.
type Envelope ¶
type Envelope struct {
EnvelopeID string `json:"envelope_id"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
AcceptsResponsePayload bool `json:"accepts_response_payload"`
RetryAttempt int `json:"retry_attempt,omitempty"`
RetryReason string `json:"retry_reason,omitempty"`
}
Envelope wraps all messages received from Slack via Socket Mode.
type EventHandler ¶
EventHandler processes an envelope and returns a type-safe response.
type HelloMessage ¶
type HelloMessage struct {
Type string `json:"type"`
ConnectionInfo ConnectionInfo `json:"connection_info"`
NumConnections int `json:"num_connections"`
DebugInfo DebugInfo `json:"debug_info"`
}
HelloMessage is sent by Slack upon successful WebSocket connection.
type MessageResponse ¶
type MessageResponse struct {
// contains filtered or unexported fields
}
MessageResponse responds with a message (for slash commands).
type MetricsHook ¶
type MetricsHook interface {
// ConnectionOpened is called when a WebSocket connection is established.
ConnectionOpened(connID string)
// ConnectionClosed is called when a WebSocket connection is closed.
ConnectionClosed(connID string, duration time.Duration)
// ReconnectAttempt is called before each reconnection attempt.
ReconnectAttempt(attempt int, delay time.Duration)
// EnvelopeReceived is called when an envelope is received from Slack.
EnvelopeReceived(envType string)
// EnvelopeAcked is called when an envelope acknowledgment is sent.
EnvelopeAcked(envType string, latency time.Duration)
// HandlerStarted is called when a handler begins processing.
HandlerStarted(envType string)
// HandlerCompleted is called when a handler finishes processing.
HandlerCompleted(envType string, duration time.Duration, err error)
// HandlerPanic is called when a handler panics.
HandlerPanic(envType string, recovered any)
// WriteQueueDepth is called periodically with the current write queue depth.
WriteQueueDepth(depth int)
}
MetricsHook allows users to collect metrics from the socket mode client. Implement this interface and pass it via WithMetrics() to receive callbacks. All methods should be non-blocking and safe for concurrent use.
type ModalAction ¶
type ModalAction int
ModalAction specifies what to do with a modal response.
const ( // ModalActionUpdate replaces the current modal view. ModalActionUpdate ModalAction = iota // ModalActionPush pushes a new modal onto the stack. ModalActionPush // ModalActionClear closes all modal views. ModalActionClear // ModalActionErrors returns validation errors. ModalActionErrors )
type ModalResponse ¶
type ModalResponse struct {
// contains filtered or unexported fields
}
ModalResponse responds with a modal action (for view submissions).
type NoopMetrics ¶
type NoopMetrics struct{}
NoopMetrics is a no-op implementation of MetricsHook. Use this as a default when no metrics collection is needed.
func (*NoopMetrics) ConnectionClosed ¶
func (n *NoopMetrics) ConnectionClosed(connID string, duration time.Duration)
func (*NoopMetrics) ConnectionOpened ¶
func (n *NoopMetrics) ConnectionOpened(connID string)
func (*NoopMetrics) EnvelopeAcked ¶
func (n *NoopMetrics) EnvelopeAcked(envType string, latency time.Duration)
func (*NoopMetrics) EnvelopeReceived ¶
func (n *NoopMetrics) EnvelopeReceived(envType string)
func (*NoopMetrics) HandlerCompleted ¶
func (n *NoopMetrics) HandlerCompleted(envType string, duration time.Duration, err error)
func (*NoopMetrics) HandlerPanic ¶
func (n *NoopMetrics) HandlerPanic(envType string, recovered any)
func (*NoopMetrics) HandlerStarted ¶
func (n *NoopMetrics) HandlerStarted(envType string)
func (*NoopMetrics) ReconnectAttempt ¶
func (n *NoopMetrics) ReconnectAttempt(attempt int, delay time.Duration)
func (*NoopMetrics) WriteQueueDepth ¶
func (n *NoopMetrics) WriteQueueDepth(depth int)
type Option ¶
type Option func(*Client)
Option configures the Client.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client for API calls.
func WithHandlerTimeout ¶
WithHandlerTimeout sets the timeout for handler execution.
func WithHelloTimeout ¶
WithHelloTimeout sets the timeout for waiting for the hello message.
func WithLogger ¶
WithLogger sets the logger for the client.
func WithMaxConcurrency ¶
WithMaxConcurrency sets the maximum number of concurrent handlers.
func WithMetrics ¶
func WithMetrics(hook MetricsHook) Option
WithMetrics sets the metrics hook for the client.
type OptionsResponse ¶
type OptionsResponse struct {
// contains filtered or unexported fields
}
OptionsResponse responds with options (for block_suggestion/dynamic menus).
type PermanentError ¶
PermanentError represents an error that should not be retried. Examples: invalid auth token, revoked app, app not installed.
func (*PermanentError) Error ¶
func (e *PermanentError) Error() string
func (*PermanentError) Unwrap ¶
func (e *PermanentError) Unwrap() error
type Response ¶
type Response interface {
// contains filtered or unexported methods
}
Response is the interface for all handler responses. The unexported method seals the interface to this package.
func NoResponse ¶
func NoResponse() Response
NoResponse returns an empty response (ack only, no payload).
func RespondWithBlocks ¶
RespondWithBlocks creates a message response from blocks directly. Convenience wrapper around RespondWithMessage.
func RespondWithErrors ¶
RespondWithErrors creates a response with validation errors. Use for view_submission when form validation fails. The errors map keys are block_ids, values are error messages.
func RespondWithMessage ¶
RespondWithMessage creates a response with a message. Use for slash commands that accept response payloads.
func RespondWithModalClear ¶
func RespondWithModalClear() Response
RespondWithModalClear creates a response that closes all modals. Use for view_submission when you want to dismiss the modal stack.
func RespondWithModalPush ¶
RespondWithModalPush creates a response that pushes a new modal. Use for view_submission when you want to add a modal to the stack.
func RespondWithModalUpdate ¶
RespondWithModalUpdate creates a response that updates the current modal. Use for view_submission when you want to replace the modal content.
func RespondWithOptionGroups ¶
func RespondWithOptionGroups(groups []blocks.OptionGroup) Response
RespondWithOptionGroups creates a response with grouped options. Use for block_suggestion when populating an external select with groups.
func RespondWithOptions ¶
RespondWithOptions creates a response with options for dynamic menus. Use for block_suggestion when populating an external select.
type RetryableError ¶
RetryableError represents an error that may succeed on retry. Examples: network blip, rate limit, server error.
func (*RetryableError) Error ¶
func (e *RetryableError) Error() string
func (*RetryableError) Unwrap ¶
func (e *RetryableError) Unwrap() error