Documentation
¶
Overview ¶
Package slack provides a Slack API client adapter.
Index ¶
- func ConvertFile(f slack.File) domain.SlackAttachment
- type Client
- func (c *Client) DeleteMessage(ctx context.Context, channelID, messageTS string) error
- func (c *Client) DownloadFile(ctx context.Context, downloadURL string) (io.ReadCloser, error)
- func (c *Client) GetChannel(ctx context.Context, channelID string) (*domain.SlackChannel, error)
- func (c *Client) GetCurrentUser(ctx context.Context) (*domain.SlackUser, error)
- func (c *Client) GetFileInfo(ctx context.Context, fileID string) (*domain.SlackAttachment, error)
- func (c *Client) GetMessages(ctx context.Context, params *domain.SlackMessageQueryParams) (*domain.SlackMessageListResponse, error)
- func (c *Client) GetThreadReplies(ctx context.Context, channelID, threadTS string, limit int) ([]domain.SlackMessage, error)
- func (c *Client) GetUser(ctx context.Context, userID string) (*domain.SlackUser, error)
- func (c *Client) GetUsersForMessages(ctx context.Context, messages []domain.SlackMessage) error
- func (c *Client) ListChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
- func (c *Client) ListFiles(ctx context.Context, params *domain.SlackFileQueryParams) (*domain.SlackFileListResponse, error)
- func (c *Client) ListMyChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
- func (c *Client) ListUsers(ctx context.Context, limit int, cursor string) (*domain.SlackUserListResponse, error)
- func (c *Client) ResolveChannelByName(ctx context.Context, name string) (*domain.SlackChannel, error)
- func (c *Client) SearchMessages(ctx context.Context, query string, limit int) ([]domain.SlackMessage, error)
- func (c *Client) SendMessage(ctx context.Context, req *domain.SlackSendMessageRequest) (*domain.SlackMessage, error)
- func (c *Client) TestAuth(ctx context.Context) (*domain.SlackAuth, error)
- func (c *Client) UpdateMessage(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)
- type ClientConfig
- type MockClient
- func (m *MockClient) DeleteMessage(ctx context.Context, channelID, messageTS string) error
- func (m *MockClient) DownloadFile(ctx context.Context, downloadURL string) (io.ReadCloser, error)
- func (m *MockClient) GetChannel(ctx context.Context, channelID string) (*domain.SlackChannel, error)
- func (m *MockClient) GetCurrentUser(ctx context.Context) (*domain.SlackUser, error)
- func (m *MockClient) GetFileInfo(ctx context.Context, fileID string) (*domain.SlackAttachment, error)
- func (m *MockClient) GetMessages(ctx context.Context, params *domain.SlackMessageQueryParams) (*domain.SlackMessageListResponse, error)
- func (m *MockClient) GetThreadReplies(ctx context.Context, channelID, threadTS string, limit int) ([]domain.SlackMessage, error)
- func (m *MockClient) GetUser(ctx context.Context, userID string) (*domain.SlackUser, error)
- func (m *MockClient) ListChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
- func (m *MockClient) ListFiles(ctx context.Context, params *domain.SlackFileQueryParams) (*domain.SlackFileListResponse, error)
- func (m *MockClient) ListMyChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
- func (m *MockClient) ListUsers(ctx context.Context, limit int, cursor string) (*domain.SlackUserListResponse, error)
- func (m *MockClient) SearchMessages(ctx context.Context, query string, limit int) ([]domain.SlackMessage, error)
- func (m *MockClient) SendMessage(ctx context.Context, req *domain.SlackSendMessageRequest) (*domain.SlackMessage, error)
- func (m *MockClient) TestAuth(ctx context.Context) (*domain.SlackAuth, error)
- func (m *MockClient) UpdateMessage(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)
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 ¶
DeleteMessage removes a message.
func (*Client) DownloadFile ¶
DownloadFile downloads file content from a private download URL. The caller must close the returned ReadCloser when done.
func (*Client) GetChannel ¶
GetChannel returns a single channel by ID.
func (*Client) GetCurrentUser ¶
GetCurrentUser returns the authenticated user.
func (*Client) GetFileInfo ¶
GetFileInfo returns metadata for a single file by its ID.
func (*Client) GetMessages ¶
func (c *Client) GetMessages(ctx context.Context, params *domain.SlackMessageQueryParams) (*domain.SlackMessageListResponse, error)
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 ¶
GetUser returns a single user by ID with full profile including custom fields.
func (*Client) GetUsersForMessages ¶
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 ¶
func (c *Client) ListChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
ListChannels returns all accessible channels.
func (*Client) ListFiles ¶
func (c *Client) ListFiles(ctx context.Context, params *domain.SlackFileQueryParams) (*domain.SlackFileListResponse, error)
ListFiles returns files uploaded to a channel or workspace.
func (*Client) ListMyChannels ¶
func (c *Client) ListMyChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
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 ¶
func (c *Client) SendMessage(ctx context.Context, req *domain.SlackSendMessageRequest) (*domain.SlackMessage, error)
SendMessage sends a new message.
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 ¶
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 ¶
func (m *MockClient) GetMessages(ctx context.Context, params *domain.SlackMessageQueryParams) (*domain.SlackMessageListResponse, error)
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) ListChannels ¶
func (m *MockClient) ListChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
ListChannels returns all accessible channels.
func (*MockClient) ListFiles ¶
func (m *MockClient) ListFiles(ctx context.Context, params *domain.SlackFileQueryParams) (*domain.SlackFileListResponse, error)
ListFiles returns files in a channel or workspace.
func (*MockClient) ListMyChannels ¶
func (m *MockClient) ListMyChannels(ctx context.Context, params *domain.SlackChannelQueryParams) (*domain.SlackChannelListResponse, error)
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 ¶
func (m *MockClient) SendMessage(ctx context.Context, req *domain.SlackSendMessageRequest) (*domain.SlackMessage, error)
SendMessage sends a new message.
func (*MockClient) UpdateMessage ¶
func (m *MockClient) UpdateMessage(ctx context.Context, channelID, messageTS, newText string) (*domain.SlackMessage, error)
UpdateMessage edits an existing message.