slack

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTickets

func ExtractTickets(text string, projectKeys []string) []string

ExtractTickets extracts ticket references from text given a list of project keys. For example, with projectKeys=["DEV", "TEL"], it will find "DEV-123", "TEL-456", etc.

func LoadIndex

func LoadIndex() (*models.SlackIndex, error)

LoadIndex loads the Slack index from disk

func LoadToken

func LoadToken() (*config.SlackToken, error)

LoadToken loads the Slack token from the config file

func ResolveChannel

func ResolveChannel(idOrName string) string

ResolveChannel resolves a channel name or ID to a channel ID

func ResolveChannelMentions added in v0.42.0

func ResolveChannelMentions(text string) string

ResolveChannelMentions converts #channel mentions in text to Slack <#CHANNEL_ID> format Example: "Check #dev-team for updates" -> "Check <#C0123456789> for updates"

func ResolveGroupMentions added in v0.45.0

func ResolveGroupMentions(text string) string

ResolveGroupMentions converts @group-handle mentions in text to Slack <!subteam^GROUP_ID> format Example: "Hey @sre-team check this" -> "Hey <!subteam^S0123456789> check this" Run after ResolveMentions so individual users take precedence over groups

func ResolveMentions

func ResolveMentions(text string) string

ResolveMentions converts @username mentions in text to Slack <@USER_ID> format Example: "Hey @john.doe check this" -> "Hey <@U0123456789> check this"

func ResolveUser

func ResolveUser(idOrUsername string) string

ResolveUser resolves a username or ID to a user ID

func SaveIndex

func SaveIndex(idx *models.SlackIndex) error

SaveIndex saves the Slack index to disk

func SaveMentionStatusCache added in v0.4.0

func SaveMentionStatusCache(cache *MentionStatusCache) error

SaveMentionStatusCache saves the cache to disk

func SaveToken

func SaveToken(token *config.SlackToken) error

SaveToken saves the Slack token to the config file

Types

type Client

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

Client wraps the Slack API client

func NewClient

func NewClient(botToken string) (*Client, error)

NewClient creates a new Slack client with the given bot token

func NewClientWithAppToken

func NewClientWithAppToken(botToken, appToken string) (*Client, error)

NewClientWithAppToken creates a client that can also use Socket Mode

func NewClientWithUserToken

func NewClientWithUserToken(botToken, userToken string) (*Client, error)

NewClientWithUserToken creates a client with both bot and user tokens The user token enables search API access

func (*Client) ClassifyMentionStatus

func (c *Client) ClassifyMentionStatus(channelID, timestamp string, myUserIDs, myBotIDs []string) MentionStatus

ClassifyMentionStatus determines the status of a mention based on reactions and replies myUserIDs should include user IDs (U...) for the bot and authenticated user myBotIDs should include bot IDs (B...) to check against message BotID field

func (*Client) DeleteMessage added in v0.46.0

func (c *Client) DeleteMessage(channelID, timestamp string) error

DeleteMessage deletes an existing message

func (*Client) GetBotID

func (c *Client) GetBotID() (string, error)

GetBotID returns the bot ID (B...) of the authenticated bot

func (*Client) GetBotUserID

func (c *Client) GetBotUserID() (string, error)

GetBotUserID returns the user ID of the authenticated bot

func (*Client) GetChannelInfo

func (c *Client) GetChannelInfo(channelID string) (*slack.Channel, error)

GetChannelInfo gets information about a channel

func (*Client) GetChannelMembers added in v0.43.0

func (c *Client) GetChannelMembers(channelID string) ([]string, error)

GetChannelMembers returns all member user IDs for a channel, handling pagination and rate limits

func (*Client) GetMentionsInChannels

func (c *Client) GetMentionsInChannels(userID string, channels []string, limit int, since int64) ([]Mention, error)

GetMentionsInChannels scans channel history for mentions of a user (works with bot tokens) If since is non-zero, only returns mentions from after that time

func (*Client) GetReactions

func (c *Client) GetReactions(channelID, timestamp string) ([]slack.ItemReaction, error)

GetReactions returns reactions on a message Uses user token if available (for channels bot isn't a member of), falls back to bot token

func (*Client) GetThreadReplies

func (c *Client) GetThreadReplies(channelID, threadTS string) ([]slack.Message, error)

GetThreadReplies returns replies in a thread Uses user token if available (for channels bot isn't a member of), falls back to bot token

func (*Client) GetUserPresence

func (c *Client) GetUserPresence(userID string) (*slack.UserPresence, error)

GetUserPresence gets the presence status of a user (requires user token)

func (*Client) HasUserToken

func (c *Client) HasUserToken() bool

HasUserToken returns true if a user token is configured for search

func (*Client) IndexAll

func (c *Client) IndexAll(channelProgressFn, userProgressFn, groupProgressFn, memberProgressFn ProgressFunc) (*models.SlackIndex, error)

IndexAll fetches all channels, users, user groups and builds the index

func (*Client) ListChannels

func (c *Client) ListChannels() ([]slack.Channel, error)

ListChannels lists channels the bot is a member of

func (*Client) ListUserGroups added in v0.45.0

func (c *Client) ListUserGroups() ([]slack.UserGroup, error)

ListUserGroups lists all user groups in the workspace

func (*Client) ListUsers

func (c *Client) ListUsers() ([]slack.User, error)

ListUsers lists all users in the workspace

func (*Client) OpenConversation

func (c *Client) OpenConversation(userID string) (string, error)

OpenConversation opens a DM conversation with a user and returns the channel ID

func (*Client) PostMessage

func (c *Client) PostMessage(channelID, text string) (string, error)

PostMessage sends a message to a channel

func (*Client) PostMessageWithBlocks

func (c *Client) PostMessageWithBlocks(channelID, fallbackText string, blocks []slack.Block) (string, error)

PostMessageWithBlocks sends a message with Block Kit blocks

func (*Client) ReplyToThread

func (c *Client) ReplyToThread(channelID, threadTS, text string) (string, error)

ReplyToThread sends a reply to a thread

func (*Client) Search

func (c *Client) Search(query string, count int, since int64) ([]SearchResult, int, error)

Search performs a general search with the given query (requires user token)

func (*Client) SearchMentions

func (c *Client) SearchMentions(userID string, limit int, since int64) ([]Mention, int, error)

SearchMentions searches for mentions of a user using the search API Returns mentions sorted by timestamp descending. Requires user token.

func (*Client) SearchMessages

func (c *Client) SearchMessages(query string, count int) ([]slack.SearchMessage, int, error)

SearchMessages searches for messages matching a query (requires user token with search:read scope)

func (*Client) SetUserPresence

func (c *Client) SetUserPresence(presence string) error

SetUserPresence sets the user's presence status (requires user token) presence must be "auto" or "away"

func (*Client) TestAuth

func (c *Client) TestAuth() (*slack.AuthTestResponse, error)

TestAuth tests the authentication and returns bot info

func (*Client) TestUserAuth

func (c *Client) TestUserAuth() (*slack.AuthTestResponse, error)

TestUserAuth tests the user token authentication and returns user info

func (*Client) UpdateMessage added in v0.46.0

func (c *Client) UpdateMessage(channelID, timestamp, text string) (string, error)

UpdateMessage edits an existing message

type Mention

type Mention struct {
	ChannelID   string
	ChannelName string
	UserID      string
	Username    string
	Timestamp   string
	ThreadTS    string // Parent thread timestamp (if this is a reply)
	Text        string
	Permalink   string
	Status      MentionStatus
}

Mention represents a message that mentions a user

type MentionStatus

type MentionStatus string

MentionStatus indicates whether a mention has been handled

const (
	MentionStatusPending MentionStatus = "Pending" // No reaction or reply
	MentionStatusAcked   MentionStatus = "Acked"   // Has reaction but no reply
	MentionStatusReplied MentionStatus = "Replied" // Has reply from bot or user
)

type MentionStatusCache added in v0.4.0

type MentionStatusCache struct {
	// Key format: "channelID:timestamp" -> status
	Statuses map[string]MentionStatus `json:"statuses"`
}

MentionStatusCache caches classification results for mentions Only "Replied" and "Acked" statuses are cached (they're stable) "Pending" is not cached as it may change when user replies

func LoadMentionStatusCache added in v0.4.0

func LoadMentionStatusCache() (*MentionStatusCache, error)

LoadMentionStatusCache loads the cache from disk

func (*MentionStatusCache) Get added in v0.4.0

func (c *MentionStatusCache) Get(channelID, timestamp string) MentionStatus

Get returns the cached status for a mention, or empty string if not cached

func (*MentionStatusCache) Set added in v0.4.0

func (c *MentionStatusCache) Set(channelID, timestamp string, status MentionStatus)

Set caches a status (only Replied and Acked are cached)

type OAuthFlow

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

OAuthFlow handles Slack OAuth authentication

func NewOAuthFlow

func NewOAuthFlow(cfg *config.Config) *OAuthFlow

NewOAuthFlow creates a new OAuth flow handler

func (*OAuthFlow) ExchangeCode

func (o *OAuthFlow) ExchangeCode(ctx context.Context, code string) (*config.SlackToken, error)

ExchangeCode exchanges an authorization code for tokens

func (*OAuthFlow) GetAuthURL

func (o *OAuthFlow) GetAuthURL(state string) string

GetAuthURL returns the URL to start the OAuth flow

func (*OAuthFlow) StartAuthServer

func (o *OAuthFlow) StartAuthServer(ctx context.Context) (*config.SlackToken, error)

StartAuthServer starts a local HTTPS server to handle the OAuth callback

type ProgressFunc

type ProgressFunc func(completed, total int)

ProgressFunc is called during indexing with progress updates

type SearchResult

type SearchResult struct {
	ChannelID   string
	ChannelName string
	UserID      string
	Username    string
	Timestamp   string
	Text        string
	Permalink   string
}

SearchResult holds a search result with metadata

Jump to

Keyboard shortcuts

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