Documentation
¶
Overview ¶
Package slack is a minimal Slack Web API client scoped to what whodar needs to ingest: workspace users, channels, and message history. The token is held only in memory, never serialized, and never logged.
Index ¶
- Variables
- type Channel
- type Client
- func (c *Client) AuthTest(ctx context.Context) (string, error)
- func (c *Client) Channels(ctx context.Context, types string) ([]Channel, error)
- func (c *Client) ConnectionsOpen(ctx context.Context) (string, error)
- func (c *Client) History(ctx context.Context, channelID, oldest string, limit int) ([]Message, error)
- func (c *Client) PostMessage(ctx context.Context, channel, threadTS, text string) error
- func (c *Client) Users(ctx context.Context) ([]User, error)
- type Doer
- type Message
- type Option
- type Profile
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrAPI = errors.New("slack: api error")
ErrAPI indicates Slack returned a logical error (ok=false).
var ErrRateLimited = errors.New("slack: rate limited")
ErrRateLimited indicates Slack kept returning 429 past the retry budget.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// ID is the channel ID.
ID string `json:"id"`
// Name is the channel name without the leading hash.
Name string `json:"name"`
// IsPrivate reports whether the channel is private.
IsPrivate bool `json:"is_private"`
// IsArchived reports whether the channel is archived.
IsArchived bool `json:"is_archived"`
// NumMembers is the member count.
NumMembers int `json:"num_members"`
// Topic is the channel topic.
Topic value `json:"topic"`
// Purpose is the channel purpose.
Purpose value `json:"purpose"`
}
Channel is a Slack conversation.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the Slack Web API.
func New ¶
New returns a Client for token. It panics on an empty token; callers validate token presence before constructing the client.
func (*Client) AuthTest ¶
AuthTest returns the authenticated bot's own user ID. The bot uses it to ignore its own messages and to strip its mention from inbound text.
func (*Client) Channels ¶
Channels lists conversations of the given comma-separated types (for example "public_channel" or "public_channel,private_channel"), excluding archived channels.
func (*Client) ConnectionsOpen ¶
ConnectionsOpen opens a Socket Mode session and returns its WebSocket URL. It requires an app-level token (xapp-), not the bot token.
func (*Client) History ¶
func (c *Client) History(ctx context.Context, channelID, oldest string, limit int) ([]Message, error)
History returns up to limit messages from channelID newer than oldest, a Slack timestamp string ("" means no lower bound). It stops at limit messages or when Slack reports no more pages.
func (*Client) PostMessage ¶
PostMessage posts text to a channel. When threadTS is set, the message is a reply in that thread. Slack mrkdwn formatting in text is honored.
type Doer ¶
type Doer interface {
// Do performs the request and returns the response.
Do(req *http.Request) (*http.Response, error)
}
Doer performs an HTTP request. *http.Client satisfies it; tests inject a stub.
type Message ¶
type Message struct {
// Type is the message type, normally "message".
Type string `json:"type"`
// Subtype distinguishes system messages from user messages.
Subtype string `json:"subtype"`
// User is the author's Slack user ID.
User string `json:"user"`
// BotID is set when a bot authored the message.
BotID string `json:"bot_id"`
// Text is the message body.
Text string `json:"text"`
// TS is the message timestamp.
TS string `json:"ts"`
}
Message is a Slack message.
type Profile ¶
type Profile struct {
// RealName is the user's display name.
RealName string `json:"real_name"`
// Email is the user's email, present only with the users:read.email scope.
Email string `json:"email"`
// Title is the user's profile title.
Title string `json:"title"`
}
Profile holds the subset of a Slack user profile whodar uses.
type User ¶
type User struct {
// ID is the Slack user ID.
ID string `json:"id"`
// Name is the Slack handle.
Name string `json:"name"`
// Deleted reports whether the account is deactivated.
Deleted bool `json:"deleted"`
// IsBot reports whether the account is a bot.
IsBot bool `json:"is_bot"`
// Profile holds name, email, and title.
Profile Profile `json:"profile"`
}
User is a Slack workspace member.