slack

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 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 is a thin client for the Slack Web API.

Index

Constants

View Source
const DefaultBaseURL = "https://slack.com/api/"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Method, Code     string
	Needed, Provided string
}

func (*APIError) Error

func (e *APIError) Error() string

Error is "slack <method>: <code>", plus the needed scope for missing_scope; never the args.

type Client

type Client struct {
	BaseURL string // "https://slack.com/api/" by default; tests point it at fake Slack
	HTTP    *http.Client
	Tokens  TokenSource // the user token; ConnectionsOpen takes the app token explicitly
	Limits  *Limiter    // per method, honors Retry-After; nil uses the default tiers
	// RequestLog, when set, gets one call per request: method and HTTP status only,
	// never args, bodies, URLs with queries or tokens. Config plugins.slack.request_log turns it on.
	RequestLog func(method string, status int)
	// OnRateLimited, when set, is called once per HTTP 429 with the method name.
	OnRateLimited func(method string)
	// contains filtered or unexported fields
}

func (*Client) AddReaction

func (c *Client) AddReaction(ctx context.Context, channel, ts, name string) error

func (*Client) AuthTest

func (c *Client) AuthTest(ctx context.Context) (Identity, error)

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, args url.Values, out any) error

Call posts form-encoded args to method and decodes the JSON body into out. A body with "ok": false becomes *APIError; HTTP 429 waits Retry-After once and retries.

func (*Client) ConnectionsOpen

func (c *Client) ConnectionsOpen(ctx context.Context, appToken string) (string, error)

ConnectionsOpen calls apps.connections.open with the app-level token as bearer.

func (*Client) ConversationInfo

func (c *Client) ConversationInfo(ctx context.Context, id string) (ConversationInfo, error)

func (*Client) ConversationMembers added in v0.4.0

func (c *Client) ConversationMembers(ctx context.Context, id, cursor string) (MembersPage, error)

ConversationMembers pages conversations.members of the conversation id, 1000 ids a page.

func (*Client) DeleteMessage added in v0.4.0

func (c *Client) DeleteMessage(ctx context.Context, channel, ts string) error

DeleteMessage removes the message at ts in channel (chat.delete).

func (*Client) History

func (c *Client) History(ctx context.Context, channel string, a PageArgs) (MessagesPage, error)

func (*Client) ListConversations

func (c *Client) ListConversations(ctx context.Context, types, cursor string) (ConversationsPage, error)

ListConversations pages conversations.list, archived ones excluded; types is Slack's comma-separated list ("public_channel,private_channel,mpim,im").

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, cursor string) (UsersPage, error)

func (*Client) OAuthAccess

func (c *Client) OAuthAccess(ctx context.Context, a OAuthArgs) (OAuthResponse, error)

OAuthAccess calls oauth.v2.access without a bearer, so a TokenSource may call it while refreshing.

func (*Client) OpenDM

func (c *Client) OpenDM(ctx context.Context, user string) (string, error)
func (c *Client) Permalink(ctx context.Context, channel, ts string) (string, error)

func (*Client) PostMessage

func (c *Client) PostMessage(ctx context.Context, a PostArgs) (Posted, error)

func (*Client) Reactions

func (c *Client) Reactions(ctx context.Context, channel, ts string) ([]Reaction, error)

Reactions reads a message's reactions with every user (reactions.get, full=true).

func (*Client) RemoveReaction

func (c *Client) RemoveReaction(ctx context.Context, channel, ts, name string) error

func (*Client) Replies

func (c *Client) Replies(ctx context.Context, channel, ts string, a PageArgs) (MessagesPage, error)

func (*Client) Revoke

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

Revoke revokes the user token (auth.revoke).

func (*Client) SearchMessages

func (c *Client) SearchMessages(ctx context.Context, a SearchArgs) (SearchPage, error)

SearchMessages sorts by timestamp unless a.Sort says otherwise.

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(ctx context.Context, channel, ts, text string) error

UpdateMessage replaces the text of the message at ts in channel (chat.update); its blocks go, since Slack keeps a message's blocks unless the update replaces them, and a client renders the blocks over the text.

func (*Client) UserByEmail

func (c *Client) UserByEmail(ctx context.Context, email string) (UserInfo, error)

func (*Client) UserInfo

func (c *Client) UserInfo(ctx context.Context, id string) (UserInfo, error)

type ConversationInfo

type ConversationInfo struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	IsChannel  bool   `json:"is_channel"`
	IsGroup    bool   `json:"is_group"`
	IsIM       bool   `json:"is_im"`
	IsMPIM     bool   `json:"is_mpim"`
	IsPrivate  bool   `json:"is_private"`
	IsArchived bool   `json:"is_archived"`
	IsMember   bool   `json:"is_member"`
	User       string `json:"user"` // the other party of an im
}

type ConversationsPage

type ConversationsPage struct {
	Conversations []ConversationInfo
	NextCursor    string
}

type Identity

type Identity struct {
	Team, TeamName, User, URL string
	Scopes                    []string
}

type Limiter

type Limiter struct {
	// PerMinute overrides the budget of the methods it names.
	PerMinute map[string]int
	// contains filtered or unexported fields
}

Limiter paces each method with a token bucket of one minute's budget and holds it for the Retry-After window of an HTTP 429. The zero value uses the default tiers.

func (*Limiter) Low

func (l *Limiter) Low(method string) bool

Low reports whether method is inside a Retry-After window or its tier budget for the minute is spent.

func (*Limiter) Wait

func (l *Limiter) Wait(ctx context.Context, method string) error

Wait blocks until method may be called, then spends one unit of its budget.

type MembersPage added in v0.4.0

type MembersPage struct {
	Members    []string
	NextCursor string
}

MembersPage is a page of conversations.members: the member user ids.

type MessagesPage

type MessagesPage struct {
	Messages   []json.RawMessage
	NextCursor string
	HasMore    bool
}

type OAuthArgs

type OAuthArgs struct {
	ClientID, Code, CodeVerifier, RedirectURI, RefreshToken string
}

OAuthArgs exchanges Code (with CodeVerifier and RedirectURI, PKCE) when set, else refreshes with RefreshToken. No client secret is ever sent.

type OAuthResponse

type OAuthResponse struct {
	AccessToken, RefreshToken string
	ExpiresIn                 int
	Scope, User, Team         string
}

OAuthResponse is the user token, read under authed_user or at the top level. Its String and GoString never print the tokens.

func (OAuthResponse) GoString

func (r OAuthResponse) GoString() string

func (OAuthResponse) String

func (r OAuthResponse) String() string

type PageArgs

type PageArgs struct {
	Oldest, Latest, Cursor string
	Limit                  int
	Inclusive              bool
}

type PostArgs

type PostArgs struct {
	Channel, Text, ThreadTS string
	Broadcast               bool
}

type Posted

type Posted struct{ Channel, TS string }

type Reaction

type Reaction struct {
	Name  string   `json:"name"`
	Users []string `json:"users"`
	Count int      `json:"count"`
}

type SearchArgs

type SearchArgs struct {
	Query, Sort, SortDir string
	Page, Count          int
}

type SearchPage

type SearchPage struct {
	Matches            []json.RawMessage
	Total, Page, Pages int
}

SearchPage holds the raw matches of search.messages; each carries a channel object besides the message fields.

type TokenSource

type TokenSource interface {
	// Token returns a valid access token, refreshing it when needed.
	Token(ctx context.Context) (string, error)
}

type UserInfo

type UserInfo struct {
	ID, Name, RealName, DisplayName, Email, TZ string
	IsBot, Deleted                             bool
}

type UsersPage

type UsersPage struct {
	Users      []UserInfo
	NextCursor string
}

Jump to

Keyboard shortcuts

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