slack

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrAPI = errors.New("slack: api error")

ErrAPI indicates Slack returned a logical error (ok=false).

View Source
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

func New(token string, opts ...Option) *Client

New returns a Client for token. It panics on an empty token; callers validate token presence before constructing the client.

func (*Client) AuthTest

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

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

func (c *Client) Channels(ctx context.Context, types string) ([]Channel, error)

Channels lists conversations of the given comma-separated types (for example "public_channel" or "public_channel,private_channel"), excluding archived channels.

func (*Client) ConnectionsOpen

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

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

func (c *Client) PostMessage(ctx context.Context, channel, threadTS, text string) error

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.

func (*Client) Users

func (c *Client) Users(ctx context.Context) ([]User, error)

Users returns all active, non-bot users in the workspace.

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 Option

type Option func(*Client)

Option configures a Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the API base URL.

func WithHTTPClient

func WithHTTPClient(d Doer) Option

WithHTTPClient sets the HTTP doer.

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.

Jump to

Keyboard shortcuts

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