Documentation
¶
Overview ¶
Package slack is a thin client for the Slack Web API.
Index ¶
- Constants
- type APIError
- type Client
- func (c *Client) AddReaction(ctx context.Context, channel, ts, name string) error
- func (c *Client) AuthTest(ctx context.Context) (Identity, error)
- func (c *Client) Call(ctx context.Context, method string, args url.Values, out any) error
- func (c *Client) ConnectionsOpen(ctx context.Context, appToken string) (string, error)
- func (c *Client) ConversationInfo(ctx context.Context, id string) (ConversationInfo, error)
- func (c *Client) ConversationMembers(ctx context.Context, id, cursor string) (MembersPage, error)
- func (c *Client) DeleteMessage(ctx context.Context, channel, ts string) error
- func (c *Client) History(ctx context.Context, channel string, a PageArgs) (MessagesPage, error)
- func (c *Client) ListConversations(ctx context.Context, types, cursor string) (ConversationsPage, error)
- func (c *Client) ListUsers(ctx context.Context, cursor string) (UsersPage, error)
- func (c *Client) OAuthAccess(ctx context.Context, a OAuthArgs) (OAuthResponse, error)
- func (c *Client) OpenDM(ctx context.Context, user string) (string, error)
- func (c *Client) Permalink(ctx context.Context, channel, ts string) (string, error)
- func (c *Client) PostMessage(ctx context.Context, a PostArgs) (Posted, error)
- func (c *Client) Reactions(ctx context.Context, channel, ts string) ([]Reaction, error)
- func (c *Client) RemoveReaction(ctx context.Context, channel, ts, name string) error
- func (c *Client) Replies(ctx context.Context, channel, ts string, a PageArgs) (MessagesPage, error)
- func (c *Client) Revoke(ctx context.Context) error
- func (c *Client) SearchMessages(ctx context.Context, a SearchArgs) (SearchPage, error)
- func (c *Client) UpdateMessage(ctx context.Context, channel, ts, text string) error
- func (c *Client) UserByEmail(ctx context.Context, email string) (UserInfo, error)
- func (c *Client) UserInfo(ctx context.Context, id string) (UserInfo, error)
- type ConversationInfo
- type ConversationsPage
- type Identity
- type Limiter
- type MembersPage
- type MessagesPage
- type OAuthArgs
- type OAuthResponse
- type PageArgs
- type PostArgs
- type Posted
- type Reaction
- type SearchArgs
- type SearchPage
- type TokenSource
- type UserInfo
- type UsersPage
Constants ¶
const DefaultBaseURL = "https://slack.com/api/"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 (*Client) Call ¶
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 ¶
ConnectionsOpen calls apps.connections.open with the app-level token as bearer.
func (*Client) ConversationInfo ¶
func (*Client) ConversationMembers ¶ added in v0.4.0
ConversationMembers pages conversations.members of the conversation id, 1000 ids a page.
func (*Client) DeleteMessage ¶ added in v0.4.0
DeleteMessage removes the message at ts in channel (chat.delete).
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) OAuthAccess ¶
OAuthAccess calls oauth.v2.access without a bearer, so a TokenSource may call it while refreshing.
func (*Client) PostMessage ¶
func (*Client) Reactions ¶
Reactions reads a message's reactions with every user (reactions.get, full=true).
func (*Client) RemoveReaction ¶
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 ¶
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 ¶
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 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.
type MembersPage ¶ added in v0.4.0
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 SearchArgs ¶
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.