slack

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package slack provides a Slack API client adapter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFile

func ConvertFile(f slack.File) domain.SlackAttachment

ConvertFile converts a single slack-go File to domain.SlackAttachment.

Types

type Client

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

Client wraps the slack-go client with rate limiting.

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

NewClient creates a new Slack client.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(ctx context.Context, channelID, messageTS string) error

DeleteMessage removes a message.

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, downloadURL string) (io.ReadCloser, error)

DownloadFile downloads file content from a private download URL. The caller must close the returned ReadCloser when done.

func (*Client) GetChannel

func (c *Client) GetChannel(ctx context.Context, channelID string) (*domain.SlackChannel, error)

GetChannel returns a single channel by ID.

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser(ctx context.Context) (*domain.SlackUser, error)

GetCurrentUser returns the authenticated user.

func (*Client) GetFileInfo

func (c *Client) GetFileInfo(ctx context.Context, fileID string) (*domain.SlackAttachment, error)

GetFileInfo returns metadata for a single file by its ID.

func (*Client) GetMessages

GetMessages retrieves messages from a channel.

func (*Client) GetThreadReplies

func (c *Client) GetThreadReplies(ctx context.Context, channelID, threadTS string, limit int) ([]domain.SlackMessage, error)

GetThreadReplies retrieves replies in a thread.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, userID string) (*domain.SlackUser, error)

GetUser returns a single user by ID with full profile including custom fields.

func (*Client) GetUsersForMessages

func (c *Client) GetUsersForMessages(ctx context.Context, messages []domain.SlackMessage) error

GetUsersForMessages enriches messages with usernames by looking up user IDs. It modifies the messages slice in-place, updating Username fields for messages where UserID is present but Username is empty.

func (*Client) ListChannels

ListChannels returns all accessible channels.

func (*Client) ListFiles

ListFiles returns files uploaded to a channel or workspace.

func (*Client) ListMyChannels

ListMyChannels returns only channels the current user is a member of. This is much faster than ListChannels for workspaces with many channels.

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, limit int, cursor string) (*domain.SlackUserListResponse, error)

ListUsers returns workspace members.

func (*Client) ResolveChannelByName

func (c *Client) ResolveChannelByName(ctx context.Context, name string) (*domain.SlackChannel, error)

ResolveChannelByName finds a channel by name (case-insensitive). Note: This function iterates through all channels until a match is found, which may be slow for large workspaces. Consider using channel IDs directly when possible.

func (*Client) SearchMessages

func (c *Client) SearchMessages(ctx context.Context, query string, limit int) ([]domain.SlackMessage, error)

SearchMessages searches for messages.

func (*Client) SendMessage

SendMessage sends a new message.

func (*Client) TestAuth

func (c *Client) TestAuth(ctx context.Context) (*domain.SlackAuth, error)

TestAuth validates the token and returns auth info.

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)

UpdateMessage edits an existing message.

type ClientConfig

type ClientConfig struct {
	UserToken    string
	Debug        bool
	RateLimit    rate.Limit
	RateBurst    int
	UserCacheTTL time.Duration
}

ClientConfig holds configuration for the Slack client.

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns sensible defaults. Rate limit is set to 20 requests/minute (Slack Tier 2 limit) with burst of 3. See: https://docs.slack.dev/apis/web-api/rate-limits/

type MockClient

type MockClient struct {
	TestAuthFunc         func(ctx context.Context) (*domain.SlackAuth, error)
	ListChannelsFunc     func(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
	ListMyChannelsFunc   func(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
	GetChannelFunc       func(ctx context.Context, channelID string) (*domain.SlackChannel, error)
	GetMessagesFunc      func(ctx context.Context, params *domain.SlackMessageQueryParams) (*domain.SlackMessageListResponse, error)
	GetThreadRepliesFunc func(ctx context.Context, channelID, threadTS string, limit int) ([]domain.SlackMessage, error)
	SendMessageFunc      func(ctx context.Context, req *domain.SlackSendMessageRequest) (*domain.SlackMessage, error)
	UpdateMessageFunc    func(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)
	DeleteMessageFunc    func(ctx context.Context, channelID, messageTS string) error
	ListUsersFunc        func(ctx context.Context, limit int, cursor string) (*domain.SlackUserListResponse, error)
	GetUserFunc          func(ctx context.Context, userID string) (*domain.SlackUser, error)
	GetCurrentUserFunc   func(ctx context.Context) (*domain.SlackUser, error)
	SearchMessagesFunc   func(ctx context.Context, query string, limit int) ([]domain.SlackMessage, error)
	ListFilesFunc        func(ctx context.Context, params *domain.SlackFileQueryParams) (*domain.SlackFileListResponse, error)
	GetFileInfoFunc      func(ctx context.Context, fileID string) (*domain.SlackAttachment, error)
	DownloadFileFunc     func(ctx context.Context, downloadURL string) (io.ReadCloser, error)
}

MockClient is a mock implementation of SlackClient for testing.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client with default implementations.

func (*MockClient) DeleteMessage

func (m *MockClient) DeleteMessage(ctx context.Context, channelID, messageTS string) error

DeleteMessage removes a message.

func (*MockClient) DownloadFile

func (m *MockClient) DownloadFile(ctx context.Context, downloadURL string) (io.ReadCloser, error)

DownloadFile downloads file content from a URL.

func (*MockClient) GetChannel

func (m *MockClient) GetChannel(ctx context.Context, channelID string) (*domain.SlackChannel, error)

GetChannel returns a single channel by ID.

func (*MockClient) GetCurrentUser

func (m *MockClient) GetCurrentUser(ctx context.Context) (*domain.SlackUser, error)

GetCurrentUser returns the authenticated user.

func (*MockClient) GetFileInfo

func (m *MockClient) GetFileInfo(ctx context.Context, fileID string) (*domain.SlackAttachment, error)

GetFileInfo returns metadata for a single file.

func (*MockClient) GetMessages

GetMessages returns messages from a channel.

func (*MockClient) GetThreadReplies

func (m *MockClient) GetThreadReplies(ctx context.Context, channelID, threadTS string, limit int) ([]domain.SlackMessage, error)

GetThreadReplies returns replies in a thread.

func (*MockClient) GetUser

func (m *MockClient) GetUser(ctx context.Context, userID string) (*domain.SlackUser, error)

GetUser returns a single user by ID.

func (*MockClient) ListChannels

ListChannels returns all accessible channels.

func (*MockClient) ListFiles

ListFiles returns files in a channel or workspace.

func (*MockClient) ListMyChannels

ListMyChannels returns only channels the user is a member of.

func (*MockClient) ListUsers

func (m *MockClient) ListUsers(ctx context.Context, limit int, cursor string) (*domain.SlackUserListResponse, error)

ListUsers returns workspace members.

func (*MockClient) SearchMessages

func (m *MockClient) SearchMessages(ctx context.Context, query string, limit int) ([]domain.SlackMessage, error)

SearchMessages searches for messages.

func (*MockClient) SendMessage

SendMessage sends a new message.

func (*MockClient) TestAuth

func (m *MockClient) TestAuth(ctx context.Context) (*domain.SlackAuth, error)

TestAuth validates the token and returns auth info.

func (*MockClient) UpdateMessage

func (m *MockClient) UpdateMessage(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)

UpdateMessage edits an existing message.

Jump to

Keyboard shortcuts

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