provider

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 20 Imported by: 0

README

The "edge" package has been partially copied from rusq/slackdump.

Credits to the https://github.com/rusq.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllChanTypes = []string{"mpim", "im", "public_channel", "private_channel"}
View Source
var ErrChannelsNotReady = errors.New(channelsNotReadyMsg)
View Source
var ErrRefreshRateLimited = errors.New("refresh skipped due to rate limiting")
View Source
var ErrUsersNotReady = errors.New(usersNotReadyMsg)
View Source
var PrivateChanType = "private_channel"
View Source
var PubChanType = "public_channel"

Functions

This section is empty.

Types

type ApiProvider

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

func New

func New(transport string, logger *zap.Logger) *ApiProvider

func (*ApiProvider) ForceRefreshChannels

func (ap *ApiProvider) ForceRefreshChannels(ctx context.Context) error

ForceRefreshChannels bypasses the cache and fetches fresh channel data from Slack API. Use this when a channel lookup fails to attempt recovery with fresh data. Rate limited by SLACK_MCP_MIN_REFRESH_INTERVAL (default 30s) to prevent API abuse. Returns ErrRefreshRateLimited if refresh is skipped due to rate limiting.

func (*ApiProvider) ForceRefreshUsers

func (ap *ApiProvider) ForceRefreshUsers(ctx context.Context) error

ForceRefreshUsers bypasses the cache and fetches fresh user data from Slack API. Rate limited by SLACK_MCP_MIN_REFRESH_INTERVAL (default 30s) to prevent API abuse. Returns ErrRefreshRateLimited if refresh is skipped due to rate limiting.

func (*ApiProvider) GetChannels

func (ap *ApiProvider) GetChannels(ctx context.Context, channelTypes []string) []Channel

func (*ApiProvider) GetChannelsType

func (ap *ApiProvider) GetChannelsType(ctx context.Context, channelType string) []Channel

func (*ApiProvider) GetSlackConnect

func (ap *ApiProvider) GetSlackConnect(ctx context.Context) ([]slack.User, error)

func (*ApiProvider) IsBotToken

func (ap *ApiProvider) IsBotToken() bool

func (*ApiProvider) IsOAuth

func (ap *ApiProvider) IsOAuth() bool

func (*ApiProvider) IsReady

func (ap *ApiProvider) IsReady() (bool, error)

func (*ApiProvider) PatchUser

func (ap *ApiProvider) PatchUser(ctx context.Context, userID string) (*slack.User, error)

PatchUser fetches a single user by ID from the Slack API and adds them to the in-memory users snapshot. This is much cheaper than a full cache rebuild for a single cache miss (O(1) API call vs O(all users)). Disk persistence is skipped — the next full refresh will persist the entry.

func (*ApiProvider) ProvideChannelsMaps

func (ap *ApiProvider) ProvideChannelsMaps() *ChannelsCache

func (*ApiProvider) ProvideUsersMap

func (ap *ApiProvider) ProvideUsersMap() *UsersCache

func (*ApiProvider) RefreshChannels

func (ap *ApiProvider) RefreshChannels(ctx context.Context) error

func (*ApiProvider) RefreshUsers

func (ap *ApiProvider) RefreshUsers(ctx context.Context) error

func (*ApiProvider) SearchUsers

func (ap *ApiProvider) SearchUsers(ctx context.Context, query string, limit int) ([]slack.User, error)

SearchUsers searches for users by name, email, or display name. If the query matches a Slack user ID pattern (e.g., U07VCEPP4N5), it looks up the user directly via the users.info API instead of searching. For OAuth tokens (xoxp/xoxb), it searches the local users cache using regex matching. For browser tokens (xoxc/xoxd), it uses the edge API's UsersSearch method.

func (*ApiProvider) ServerTransport

func (ap *ApiProvider) ServerTransport() string

func (*ApiProvider) SkipCache

func (ap *ApiProvider) SkipCache()

SkipCache marks both users and channels caches as ready without loading any data. Lookups by #channel-name or @username will not work; callers must use channel/user IDs instead.

func (*ApiProvider) Slack

func (ap *ApiProvider) Slack() SlackAPI

type Channel

type Channel struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Topic       string   `json:"topic"`
	Purpose     string   `json:"purpose"`
	MemberCount int      `json:"memberCount"`
	IsMpIM      bool     `json:"mpim"`
	IsIM        bool     `json:"im"`
	IsPrivate   bool     `json:"private"`
	IsExtShared bool     `json:"is_ext_shared"`     // Shared with external organizations
	User        string   `json:"user,omitempty"`    // User ID for IM channels
	Members     []string `json:"members,omitempty"` // Member IDs for the channel
}

func MapChannelFromSlack

func MapChannelFromSlack(c slack.Channel, usersMap map[string]slack.User) Channel

MapChannelFromSlack converts a slack.Channel to our internal Channel type.

type ChannelsCache

type ChannelsCache struct {
	Channels    map[string]Channel `json:"channels"`
	ChannelsInv map[string]string  `json:"channels_inv"`
}

type MCPSlackClient

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

func NewMCPSlackClient

func NewMCPSlackClient(authProvider auth.Provider, logger *zap.Logger) (*MCPSlackClient, error)

func (*MCPSlackClient) AddReactionContext

func (c *MCPSlackClient) AddReactionContext(ctx context.Context, name string, item slack.ItemRef) error

func (*MCPSlackClient) AuthResponse

func (c *MCPSlackClient) AuthResponse() *slack.AuthTestResponse

func (*MCPSlackClient) AuthTest

func (c *MCPSlackClient) AuthTest() (*slack.AuthTestResponse, error)

func (*MCPSlackClient) AuthTestContext

func (c *MCPSlackClient) AuthTestContext(ctx context.Context) (*slack.AuthTestResponse, error)

func (*MCPSlackClient) ClientCounts

func (c *MCPSlackClient) ClientCounts(ctx context.Context) (edge.ClientCountsResponse, error)

func (*MCPSlackClient) ClientUserBoot

func (c *MCPSlackClient) ClientUserBoot(ctx context.Context) (*edge.ClientUserBootResponse, error)

func (*MCPSlackClient) CompleteUploadExternalContext

func (*MCPSlackClient) CreateUserGroupContext

func (c *MCPSlackClient) CreateUserGroupContext(ctx context.Context, userGroup slack.UserGroup, options ...slack.CreateUserGroupOption) (slack.UserGroup, error)

func (*MCPSlackClient) GetConversationHistoryContext

func (*MCPSlackClient) GetConversationInfoContext

func (c *MCPSlackClient) GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)

func (*MCPSlackClient) GetConversationRepliesContext

func (c *MCPSlackClient) GetConversationRepliesContext(ctx context.Context, params *slack.GetConversationRepliesParameters) (msgs []slack.Message, hasMore bool, nextCursor string, err error)

func (*MCPSlackClient) GetConversationsContext

func (c *MCPSlackClient) GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) ([]slack.Channel, string, error)

func (*MCPSlackClient) GetConversationsForUserContext

func (c *MCPSlackClient) GetConversationsForUserContext(ctx context.Context, params *slack.GetConversationsForUserParameters) ([]slack.Channel, string, error)

func (*MCPSlackClient) GetFileContext

func (c *MCPSlackClient) GetFileContext(ctx context.Context, downloadURL string, writer io.Writer) error

func (*MCPSlackClient) GetFileInfoContext

func (c *MCPSlackClient) GetFileInfoContext(ctx context.Context, fileID string, count, page int) (*slack.File, []slack.Comment, *slack.Paging, error)

func (*MCPSlackClient) GetMutedChannels

func (c *MCPSlackClient) GetMutedChannels(ctx context.Context) (map[string]bool, error)

func (*MCPSlackClient) GetUploadURLExternalContext

func (*MCPSlackClient) GetUserGroupMembersContext

func (c *MCPSlackClient) GetUserGroupMembersContext(ctx context.Context, userGroup string, options ...slack.GetUserGroupMembersOption) ([]string, error)

func (*MCPSlackClient) GetUserGroupsContext

func (c *MCPSlackClient) GetUserGroupsContext(ctx context.Context, options ...slack.GetUserGroupsOption) ([]slack.UserGroup, error)

func (*MCPSlackClient) GetUsersContext

func (c *MCPSlackClient) GetUsersContext(ctx context.Context, options ...slack.GetUsersOption) ([]slack.User, error)

func (*MCPSlackClient) GetUsersInfo

func (c *MCPSlackClient) GetUsersInfo(users ...string) (*[]slack.User, error)

func (*MCPSlackClient) IsBotToken

func (c *MCPSlackClient) IsBotToken() bool

func (*MCPSlackClient) IsEnterprise

func (c *MCPSlackClient) IsEnterprise() bool

func (*MCPSlackClient) IsOAuth

func (c *MCPSlackClient) IsOAuth() bool

func (*MCPSlackClient) JoinConversationContext

func (c *MCPSlackClient) JoinConversationContext(ctx context.Context, channelID string) (*slack.Channel, string, []string, error)

func (*MCPSlackClient) LeaveConversationContext

func (c *MCPSlackClient) LeaveConversationContext(ctx context.Context, channelID string) (bool, error)

func (*MCPSlackClient) MarkConversationContext

func (c *MCPSlackClient) MarkConversationContext(ctx context.Context, channel, ts string) error

func (*MCPSlackClient) PostMessageContext

func (c *MCPSlackClient) PostMessageContext(ctx context.Context, channelID string, options ...slack.MsgOption) (string, string, error)

func (*MCPSlackClient) Raw

func (c *MCPSlackClient) Raw() struct {
	Slack *slack.Client
	Edge  *edge.Client
}

func (*MCPSlackClient) RemoveReactionContext

func (c *MCPSlackClient) RemoveReactionContext(ctx context.Context, name string, item slack.ItemRef) error

func (*MCPSlackClient) SavedClearCompleted

func (c *MCPSlackClient) SavedClearCompleted(ctx context.Context) error

func (*MCPSlackClient) SavedList

func (c *MCPSlackClient) SavedList(ctx context.Context, filter string, limit int, cursor string) (edge.SavedListResponse, error)

func (*MCPSlackClient) SavedUpdate

func (c *MCPSlackClient) SavedUpdate(ctx context.Context, itemType, itemID, ts, mark string, dateDue int64) error

func (*MCPSlackClient) SearchContext

func (*MCPSlackClient) UpdateUserGroupContext

func (c *MCPSlackClient) UpdateUserGroupContext(ctx context.Context, userGroupID string, options ...slack.UpdateUserGroupsOption) (slack.UserGroup, error)

func (*MCPSlackClient) UpdateUserGroupMembersContext

func (c *MCPSlackClient) UpdateUserGroupMembersContext(ctx context.Context, userGroup string, members string, options ...slack.UpdateUserGroupMembersOption) (slack.UserGroup, error)

func (*MCPSlackClient) UploadToURL

func (c *MCPSlackClient) UploadToURL(ctx context.Context, params slack.UploadToURLParameters) error

func (*MCPSlackClient) UsersSearch

func (c *MCPSlackClient) UsersSearch(ctx context.Context, query string, count int) ([]slack.User, error)

type SlackAPI

type SlackAPI interface {
	// Standard slack-go API methods
	AuthTest() (*slack.AuthTestResponse, error)
	AuthTestContext(ctx context.Context) (*slack.AuthTestResponse, error)
	GetUsersContext(ctx context.Context, options ...slack.GetUsersOption) ([]slack.User, error)
	GetUsersInfo(users ...string) (*[]slack.User, error)
	PostMessageContext(ctx context.Context, channel string, options ...slack.MsgOption) (string, string, error)
	GetUploadURLExternalContext(ctx context.Context, params slack.GetUploadURLExternalParameters) (*slack.GetUploadURLExternalResponse, error)
	UploadToURL(ctx context.Context, params slack.UploadToURLParameters) error
	CompleteUploadExternalContext(ctx context.Context, params slack.CompleteUploadExternalParameters) (*slack.CompleteUploadExternalResponse, error)
	MarkConversationContext(ctx context.Context, channel, ts string) error
	AddReactionContext(ctx context.Context, name string, item slack.ItemRef) error
	RemoveReactionContext(ctx context.Context, name string, item slack.ItemRef) error
	LeaveConversationContext(ctx context.Context, channelID string) (bool, error)
	JoinConversationContext(ctx context.Context, channelID string) (*slack.Channel, string, []string, error)

	// Used to get messages
	GetConversationHistoryContext(ctx context.Context, params *slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)
	GetConversationRepliesContext(ctx context.Context, params *slack.GetConversationRepliesParameters) (msgs []slack.Message, hasMore bool, nextCursor string, err error)
	SearchContext(ctx context.Context, query string, params slack.SearchParameters) (*slack.SearchMessages, *slack.SearchFiles, error)

	// Used to get files
	GetFileInfoContext(ctx context.Context, fileID string, count, page int) (*slack.File, []slack.Comment, *slack.Paging, error)
	GetFileContext(ctx context.Context, downloadURL string, writer io.Writer) error

	// Used to get channel info (for unread counts with xoxp tokens)
	GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)

	// Used to get channels list from both Slack and Enterprise Grid versions
	GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) ([]slack.Channel, string, error)

	// Used to list only channels the calling user is a member of (users.conversations).
	// For xoxp tokens this is more efficient than conversations.list because it excludes
	// non-member public channels and closed DMs that cannot have unreads.
	GetConversationsForUserContext(ctx context.Context, params *slack.GetConversationsForUserParameters) ([]slack.Channel, string, error)

	// Edge API methods
	ClientUserBoot(ctx context.Context) (*edge.ClientUserBootResponse, error)
	UsersSearch(ctx context.Context, query string, count int) ([]slack.User, error)
	ClientCounts(ctx context.Context) (edge.ClientCountsResponse, error)
	GetMutedChannels(ctx context.Context) (map[string]bool, error)
	SavedList(ctx context.Context, filter string, limit int, cursor string) (edge.SavedListResponse, error)
	SavedUpdate(ctx context.Context, itemType, itemID, ts, mark string, dateDue int64) error
	SavedClearCompleted(ctx context.Context) error

	// User groups API methods
	GetUserGroupsContext(ctx context.Context, options ...slack.GetUserGroupsOption) ([]slack.UserGroup, error)
	GetUserGroupMembersContext(ctx context.Context, userGroup string, options ...slack.GetUserGroupMembersOption) ([]string, error)
	CreateUserGroupContext(ctx context.Context, userGroup slack.UserGroup, options ...slack.CreateUserGroupOption) (slack.UserGroup, error)
	UpdateUserGroupContext(ctx context.Context, userGroupID string, options ...slack.UpdateUserGroupsOption) (slack.UserGroup, error)
	UpdateUserGroupMembersContext(ctx context.Context, userGroup string, members string, options ...slack.UpdateUserGroupMembersOption) (slack.UserGroup, error)
}

type UsersCache

type UsersCache struct {
	Users    map[string]slack.User `json:"users"`
	UsersInv map[string]string     `json:"users_inv"`
}

Directories

Path Synopsis
Package edge provides a limited implementation of undocumented Slack Edge API necessary to get the data from a slack workspace.
Package edge provides a limited implementation of undocumented Slack Edge API necessary to get the data from a slack workspace.

Jump to

Keyboard shortcuts

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