internal

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SlackChannelNotFoundError is the error string returned by the Slack API when a channel is not found.
	SlackChannelNotFoundError = "channel_not_found"

	// SlackThreadNotFoundError is the error string returned by the Slack API when a thread is not found.
	SlackThreadNotFoundError = "thread_not_found"

	// SlackNoSuchSubTeamError is the error string returned by the Slack API when a user group (sub team) is not found.
	SlackNoSuchSubTeamError = "no_such_subteam"
)

Variables

View Source
var ErrNotConnected = errors.New("client not connected: Connect() must be called first")

ErrNotConnected is returned when an API method is called before Connect().

Functions

func DecryptWebhookPayload

func DecryptWebhookPayload(w *types.Webhook, key []byte) (map[string]any, error)

DecryptWebhookPayload decrypts the encrypted webhook payload (if any) and returns it, or nil if payload is empty. This function does not modify the state of the webhook.

func EncryptWebhookPayload

func EncryptWebhookPayload(w *types.Webhook, key []byte) error

EncryptWebhookPayload encrypts the existing webhook payload (if any) and replaces it with an encrypted version. This function modifies the state of the webhook.

func Hash

func Hash(input ...string) string

func HashBytes

func HashBytes(b []byte) []byte

func IsCtxCanceledErr

func IsCtxCanceledErr(err error) bool

func TrySend

func TrySend[T any](ctx context.Context, msg T, sinkCh chan<- T) error

Types

type Cache

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

Cache is a wrapper around a cache store that provides methods for getting, setting, and deleting cached items.

func NewCache

func NewCache(cacheStore store.StoreInterface, keyPrefix string, logger types.Logger) *Cache

NewCache creates a new Cache instance with the provided cache store, key prefix, and logger. The key prefix is optional, but may be useful for namespacing cache keys.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete removes the item from the cache with the given key. This method returns an error if the deletion fails, since an explicit delete is expected to always succeed. Note: The key is prefixed with the cache's keyPrefix.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) (string, bool)

Get retrieves an item from the cache with the given key. If the item is not found, it returns an empty string and false. If an error occurs during retrieval, it logs the error and returns an empty string and false (or panics if WithPanicOnError is set). Note: The key is prefixed with the cache's keyPrefix.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value string, expiration time.Duration)

Set stores an item in the cache with the given key and expiration duration. If an error occurs during storage, it logs the error (or panics if WithPanicOnError is set). Note: The key is prefixed with the cache's keyPrefix.

func (*Cache) SetWithRandomExpiration

func (c *Cache) SetWithRandomExpiration(ctx context.Context, key string, value string, minExpiration time.Duration, variation time.Duration)

SetWithRandomExpiration stores an item in the cache with a key, value, and a random expiration time. The expiration time is calculated by adding a random variation to a minimum expiration duration. The random variation is between 0 and the absolute value of the provided variation duration. If an error occurs during storage, it logs the error (or panics if WithPanicOnError is set). Note: The key is prefixed with the cache's keyPrefix.

func (*Cache) WithPanicOnError

func (c *Cache) WithPanicOnError() *Cache

WithPanicOnError enables panicking on cache errors instead of logging them, in all Get and Set methods. This is useful for testing and debugging purposes, but should be used with caution in production environments. The default behavior is to log errors, not to panic.

type ChannelSummary

type ChannelSummary struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

func NewChannelSummary

func NewChannelSummary(channel slack.Channel) *ChannelSummary

NewChannelSummary creates a new ChannelSummary from a slack.Channel object. We map only the fields we need, and ignore the rest.

type SlackAPIClient

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

func NewSlackAPIClient

func NewSlackAPIClient(cacheStore cachestore.StoreInterface, cacheKeyPrefix string, logger types.Logger, metrics types.Metrics, cfg *config.SlackClientConfig) *SlackAPIClient

func (*SlackAPIClient) API

func (c *SlackAPIClient) API() *slack.Client

func (*SlackAPIClient) BotIsInChannel

func (c *SlackAPIClient) BotIsInChannel(ctx context.Context, channelID string) (bool, error)

func (*SlackAPIClient) BotUserID

func (c *SlackAPIClient) BotUserID() string

func (*SlackAPIClient) ChatDeleteMessage

func (c *SlackAPIClient) ChatDeleteMessage(ctx context.Context, channelID string, ts string) error

func (*SlackAPIClient) ChatPostMessage

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

func (*SlackAPIClient) ChatUpdateMessage

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

func (*SlackAPIClient) Connect

func (*SlackAPIClient) GetChannelInfo

func (c *SlackAPIClient) GetChannelInfo(ctx context.Context, channelID string) (*slack.Channel, error)

func (*SlackAPIClient) GetUserIDsInChannel

func (c *SlackAPIClient) GetUserIDsInChannel(ctx context.Context, channelID string) (map[string]struct{}, error)

func (*SlackAPIClient) GetUserInfo

func (c *SlackAPIClient) GetUserInfo(ctx context.Context, userID string) (*slack.User, error)

func (*SlackAPIClient) ListBotChannels

func (c *SlackAPIClient) ListBotChannels(ctx context.Context) ([]*ChannelSummary, error)

func (*SlackAPIClient) ListUserGroupMembers

func (c *SlackAPIClient) ListUserGroupMembers(ctx context.Context, groupID string) (map[string]struct{}, error)

func (*SlackAPIClient) MessageHasReplies

func (c *SlackAPIClient) MessageHasReplies(ctx context.Context, channelID, ts string) (bool, error)

func (*SlackAPIClient) NewSocketModeClient

func (c *SlackAPIClient) NewSocketModeClient() *SocketModeClientWrapper

func (*SlackAPIClient) OpenModal

func (c *SlackAPIClient) OpenModal(ctx context.Context, triggerID string, request slack.ModalViewRequest) error

func (*SlackAPIClient) PostEphemeral

func (c *SlackAPIClient) PostEphemeral(ctx context.Context, channelID, userID string, options ...slack.MsgOption) (string, error)

func (*SlackAPIClient) SendResponse

func (c *SlackAPIClient) SendResponse(ctx context.Context, channelID, responseURL, responseType, text string) error

type SocketModeClientWrapper

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

SocketModeClientWrapper is a wrapper around the slack-go/socketmode.Client. It is primarily created to wrap the Events channel in a function, which allows using interfaces more easily.

func NewSocketModeClientWrapper

func NewSocketModeClientWrapper(client *socketmode.Client) *SocketModeClientWrapper

NewSocketModeClientWrapper creates a new instance of SocketModeClientWrapper.

func (*SocketModeClientWrapper) Ack

func (s *SocketModeClientWrapper) Ack(req socketmode.Request, payload ...any)

Ack acknowledges the given socketmode request with an optional payload.

func (*SocketModeClientWrapper) Events

func (s *SocketModeClientWrapper) Events() chan socketmode.Event

Events returns the channel that receives incoming socketmode events.

func (*SocketModeClientWrapper) RunContext

func (s *SocketModeClientWrapper) RunContext(ctx context.Context) error

RunContext is a blocking function that connects the Slack Socket Mode API and handles all incoming requests and outgoing responses.

Jump to

Keyboard shortcuts

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