client

package
v2.3.19 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllChannels map[string]string

AllChannels is a map of each channelsId and the name

View Source
var AllUsers config.UserMap

AllUsers is a lookup from user-id to user-name

AuthResponse is holding some basic Slack metadata for the current connection, like Bot-Id, Workspace etc

View Source
var InternalMessages = make(chan msg.Message, 200)

InternalMessages is internal queue of internal messages @deprecated -> use HandleMessageWithDoneHandler instead

Functions

func GetBitbucketClient

func GetBitbucketClient(cfg config.Bitbucket) (*bitbucket.DefaultApiService, error)

GetBitbucketClient initialized a API client based on the given config

func GetChannelIDAndName

func GetChannelIDAndName(identifier string) (id string, name string)

GetChannelIDAndName returns channel-id and channel-name by an identifier which can be an id or a name

func GetContextBlock

func GetContextBlock(text string) *slack.ContextBlock

GetContextBlock generates a "Context block" https://api.slack.com/reference/block-kit/blocks#context

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns the http client for this bot to use the default go-client with a Timeout of 10s

func GetInteractionButton

func GetInteractionButton(id, text, command string, args ...slack.Style) *slack.ButtonBlockElement

GetInteractionButton generates a block "Button" which is able to execute the given command once https://api.slack.com/reference/block-kit/blocks#actions

func GetSlackArchiveLink(message msg.Ref) string

GetSlackArchiveLink returns a permalink to the ref which can be shared

func GetSlackLink(name string, url string, args ...string) slack.AttachmentAction

GetSlackLink generates a "link button" as a slack.AttachmentAction which will open the given URL in the Slack client (when pressed)

func GetTextBlock

func GetTextBlock(text string) *slack.SectionBlock

GetTextBlock wraps a simple text in a Slack Block Section

func GetUserIDAndName

func GetUserIDAndName(identifier string) (id string, name string)

GetUserIDAndName returns the user-id and user-name based on a identifier. If can get a user-id or name

func HandleMessage

func HandleMessage(message msg.Message)

HandleMessage will register the given message in the queue...and returns a sync.WaitGroup which can be used to see when the message is handled

func HandleMessageWithDoneHandler

func HandleMessageWithDoneHandler(message msg.Message) *sync.WaitGroup

HandleMessageWithDoneHandler will register the given message in the queue...and returns a sync.WaitGroup which can be used to see when the message is handled

Types

type Slack

type Slack struct {
	*slack.Client
	Socket *socketmode.Client
	// contains filtered or unexported fields
}

Slack is wrapper to the slack.Client which also holds the the socketmode.Client and all needed config

func GetSlackClient

func GetSlackClient(cfg config.Slack) (*Slack, error)

GetSlackClient establishes a connection to the slack server.

func (*Slack) AddReaction

func (s *Slack) AddReaction(reaction util.Reaction, ref msg.Ref)

AddReaction will add a reaction from the given message

func (*Slack) GetFile added in v2.3.18

func (s *Slack) GetFile(downloadURL string, writer io.Writer) error

GetFile downloads a file from Slack by its private URL

func (*Slack) GetThreadMessages added in v2.2.10

func (s *Slack) GetThreadMessages(ref msg.Ref) ([]slack.Message, error)

GetThreadMessages will send Slack Blocks/Sections to the target

func (*Slack) GetUserPresence added in v2.2.10

func (s *Slack) GetUserPresence(user string) (*slack.UserPresence, error)

GetUserPresence returns the current presence of a user, using the "users.getPresence" API

func (*Slack) PinMessage added in v2.3.9

func (s *Slack) PinMessage(channel string, timestamp string) error

PinMessage will pin a message to the channel

func (*Slack) RemoveReaction

func (s *Slack) RemoveReaction(reaction util.Reaction, ref msg.Ref)

RemoveReaction will remove a reaction from the given message

func (*Slack) ReplyError

func (s *Slack) ReplyError(ref msg.Ref, err error)

ReplyError send a error message as a reply to the user and log it in the log + send it to ErrorChannel (if defined)

func (*Slack) SendBlockMessage

func (s *Slack) SendBlockMessage(ref msg.Ref, blocks []slack.Block, options ...slack.MsgOption) string

SendBlockMessage will send Slack Blocks/Sections to the target

func (*Slack) SendBlockMessageToUser added in v2.2.10

func (s *Slack) SendBlockMessageToUser(user string, blocks []slack.Block, options ...slack.MsgOption) string

SendBlockMessageToUser will send Slack Blocks/Sections to the target

func (*Slack) SendEphemeralMessage added in v2.2.2

func (s *Slack) SendEphemeralMessage(ref msg.Ref, text string, options ...slack.MsgOption)

SendEphemeralMessage sends a message just visible to the current user see https://api.slack.com/methods/chat.postEphemeral

func (*Slack) SendMessage

func (s *Slack) SendMessage(ref msg.Ref, text string, options ...slack.MsgOption) string

SendMessage is the "slow" reply via POST request, needed for Attachment or MsgRef

func (*Slack) SendToUser

func (s *Slack) SendToUser(user string, text string)

SendToUser sends a message to any user via IM channel

func (*Slack) UploadFile added in v2.2.10

func (s *Slack) UploadFile(params slack.UploadFileParameters) (*slack.FileSummary, error)

UploadFile uploads a file to Slack

type SlackClient

type SlackClient interface {
	// ReplyError Replies a error to the current channel/user/thread + log it!
	ReplyError(ref msg.Ref, err error)
	// SendMessage is the extended version of Reply and accepts any slack.MsgOption
	SendMessage(ref msg.Ref, text string, options ...slack.MsgOption) string

	// SendEphemeralMessage sends a message just visible to the current user
	SendEphemeralMessage(ref msg.Ref, text string, options ...slack.MsgOption)

	SendBlockMessageToUser(user string, blocks []slack.Block, options ...slack.MsgOption) string

	// SendBlockMessage will send Slack Blocks/Sections to the target
	SendBlockMessage(ref msg.Ref, blocks []slack.Block, options ...slack.MsgOption) string

	// SendToUser sends a simple text message to a user, using "@username or @U12334"
	SendToUser(user string, text string)
	RemoveReaction(reaction util.Reaction, ref msg.Ref)
	AddReaction(reaction util.Reaction, ref msg.Ref)
	GetReactions(item slack.ItemRef, params slack.GetReactionsParameters) (slack.ReactedItem, error)

	// GetConversationHistory loads the message history from slack
	GetConversationHistory(*slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)

	// GetThreadMessages loads message from a given thread
	GetThreadMessages(ref msg.Ref) ([]slack.Message, error)

	// GetUserPresence returns the current presence of a user, using the "users.getPresence" API
	GetUserPresence(user string) (*slack.UserPresence, error)

	// UploadFile uploads a file to Slack
	UploadFile(params slack.UploadFileParameters) (*slack.FileSummary, error)

	// PinMessage will pin a message to the channel
	PinMessage(channel string, timestamp string) error

	// GetFile downloads a file from Slack by its private URL
	GetFile(downloadURL string, writer io.Writer) error
}

SlackClient is the main interface which is used for all commands to interact with slack for tests we have a mock for it, for production use, we use a slack.Client with some custom logic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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