slack

package
v0.4.0-rc.13-linux-arm64 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 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 slack implements Slack's OAuth and incoming-webhook protocol boundary.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidGrant identifies a rejected or expired OAuth authorization code.
	ErrInvalidGrant = xerror.New(xerror.KindInvalidInput, "SLACK_INVALID_GRANT", "Slack OAuth grant was rejected")
	// ErrRateLimited identifies a Slack response that may be retried after the returned delay.
	ErrRateLimited = xerror.New(xerror.KindUnavailable, "SLACK_RATE_LIMITED", "Slack request was rate limited")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*WebhookClient
	// contains filtered or unexported fields
}

Client performs Slack OAuth and revocation requests.

func New

func New(config Config) (*Client, error)

New validates deployment configuration and creates a client that never follows redirects.

func (*Client) AuthorizationURL

func (c *Client) AuthorizationURL(state string) string

AuthorizationURL builds a consent URL requesting only Slack's incoming-webhook scope.

func (*Client) ExchangeCode

func (c *Client) ExchangeCode(ctx context.Context, code string) (Install, error)

ExchangeCode exchanges an OAuth authorization code for its Slack installation data.

func (*Client) Revoke

func (c *Client) Revoke(ctx context.Context, accessToken string) error

Revoke revokes an access token. Slack's invalid_auth response is already the desired state.

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	HTTPClient   *http.Client
}

Config contains deployment-owned Slack OAuth settings.

type Install

type Install struct {
	AccessToken string
	Scope       string
	TeamID      string
	TeamName    string
	ChannelID   string
	ChannelName string
	WebhookURL  string
}

Install contains the fields from a successful incoming-webhook OAuth installation. WebhookURL is a credential and must only be persisted in secret storage.

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
}

RateLimitError is safe to return to callers and preserves Slack's retry instruction.

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) Unwrap

func (e *RateLimitError) Unwrap() error

type WebhookClient

type WebhookClient struct {
	// contains filtered or unexported fields
}

WebhookClient sends messages to Slack incoming-webhook URLs.

func NewWebhookClient

func NewWebhookClient(client *http.Client) *WebhookClient

NewWebhookClient constructs a bounded client that never follows redirects.

func (*WebhookClient) SendWebhook

func (c *WebhookClient) SendWebhook(ctx context.Context, webhookURL, text string) error

SendWebhook posts plain text to a webhook returned by Slack's OAuth response.

Jump to

Keyboard shortcuts

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