Documentation
¶
Index ¶
- Constants
- Variables
- func DecryptWebhookPayload(w *types.Webhook, key []byte) (map[string]any, error)
- func EncryptWebhookPayload(w *types.Webhook, key []byte) error
- func Hash(input ...string) string
- func HashBytes(b []byte) []byte
- func IsCtxCanceledErr(err error) bool
- func NewPrefixedMetrics(inner types.Metrics, prefix string) types.Metrics
- func TrySend[T any](ctx context.Context, msg T, sinkCh chan<- T) error
- func WithRateLimitGate(g rateLimitSignaler) func(*SlackAPIClient)
- type Cache
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) Get(ctx context.Context, key string) (string, bool)
- func (c *Cache) Set(ctx context.Context, key string, value string, expiration time.Duration)
- func (c *Cache) SetWithRandomExpiration(ctx context.Context, key string, value string, minExpiration time.Duration, ...)
- func (c *Cache) WithPanicOnError() *Cache
- type ChannelSummary
- type SlackAPIClient
- func (c *SlackAPIClient) API() *slack.Client
- func (c *SlackAPIClient) BotIsInChannel(ctx context.Context, channelID string) (bool, error)
- func (c *SlackAPIClient) BotUserID() string
- func (c *SlackAPIClient) ChatDeleteMessage(ctx context.Context, channelID string, ts string) error
- func (c *SlackAPIClient) ChatPostMessage(ctx context.Context, channelID string, options ...slack.MsgOption) (string, error)
- func (c *SlackAPIClient) ChatUpdateMessage(ctx context.Context, channelID string, options ...slack.MsgOption) (string, error)
- func (c *SlackAPIClient) Connect(ctx context.Context) (*slack.AuthTestResponse, error)
- func (c *SlackAPIClient) GetChannelInfo(ctx context.Context, channelID string) (*slack.Channel, error)
- func (c *SlackAPIClient) GetUserIDsInChannel(ctx context.Context, channelID string) (map[string]struct{}, error)
- func (c *SlackAPIClient) GetUserInfo(ctx context.Context, userID string) (*slack.User, error)
- func (c *SlackAPIClient) ListBotChannels(ctx context.Context) ([]*ChannelSummary, error)
- func (c *SlackAPIClient) ListUserGroupMembers(ctx context.Context, groupID string) (map[string]struct{}, error)
- func (c *SlackAPIClient) MessageHasReplies(ctx context.Context, channelID, ts string) (bool, error)
- func (c *SlackAPIClient) NewSocketModeClient() *SocketModeClientWrapper
- func (c *SlackAPIClient) OpenModal(ctx context.Context, triggerID string, request slack.ModalViewRequest) error
- func (c *SlackAPIClient) PostEphemeral(ctx context.Context, channelID, userID string, options ...slack.MsgOption) (string, error)
- func (c *SlackAPIClient) SendResponse(ctx context.Context, channelID, responseURL, responseType, text string) error
- type SocketModeClientWrapper
- func (s *SocketModeClientWrapper) Ack(ctx context.Context, req *socketmode.Request)
- func (s *SocketModeClientWrapper) AckWithFieldErrorMsg(ctx context.Context, evt *socketmode.Event, fieldName, errMsg string)
- func (s *SocketModeClientWrapper) AckWithPayload(ctx context.Context, req *socketmode.Request, payload any)
- func (s *SocketModeClientWrapper) Events() chan socketmode.Event
- func (s *SocketModeClientWrapper) RunContext(ctx context.Context) error
Constants ¶
const ( // SlackErrChannelNotFound is returned when the target channel does not exist or // the bot lacks visibility of it. Non-retryable. SlackErrChannelNotFound = "channel_not_found" // SlackErrThreadNotFound is returned when the target thread does not exist, // typically because the parent message was deleted. Non-retryable. SlackErrThreadNotFound = "thread_not_found" // SlackErrNoSuchSubTeam is returned when a referenced user group does not exist // in the workspace. Non-retryable. SlackErrNoSuchSubTeam = "no_such_subteam" // SlackErrCantUpdateMessage is returned when the bot attempts to edit a message // it is not permitted to modify (e.g. another user's message). Non-retryable. SlackErrCantUpdateMessage = "cant_update_message" // SlackErrCantDeleteMessage is returned when the bot attempts to delete a message // it is not permitted to remove (e.g. another user's message). Non-retryable. SlackErrCantDeleteMessage = "cant_delete_message" // SlackErrMessageNotFound is returned when the target message does not exist, // typically because it was already deleted. Non-retryable. SlackErrMessageNotFound = "message_not_found" // SlackErrNotInChannel is returned when the bot is not a member of the channel // it is trying to interact with. Non-retryable. SlackErrNotInChannel = "not_in_channel" // SlackErrInvalidBlocks is returned when a message payload contains malformed // Block Kit JSON. Non-retryable. SlackErrInvalidBlocks = "invalid_blocks" // SlackErrIsArchived is returned when the target channel has been archived and // no longer accepts messages. Non-retryable. SlackErrIsArchived = "is_archived" // SlackErrInternalError is a transient server-side error returned by Slack when // something went wrong on their end. Safe to retry. SlackErrInternalError = "internal_error" // SlackErrFatalError is a transient error string returned by Slack for unspecified // server-side failures. Despite the name, Slack treats this as retryable. SlackErrFatalError = "fatal_error" // is temporarily unavailable. Safe to retry. SlackErrServiceUnavailable = "service_unavailable" // SlackErrRequestTimeout is a transient error returned when Slack's own // processing timed out handling the request. Safe to retry. SlackErrRequestTimeout = "request_timeout" // SlackErrRateLimited is returned when the client has hit a rate limit. // Safe to retry after a delay, using the Retry-After header if present. SlackErrRateLimited = "ratelimited" // SlackErrRateLimitedV2 is returned when the client has hit a rate limit. // Safe to retry after a delay, using the Retry-After header if present. SlackErrRateLimitedV2 = "rate_limited" )
Variables ¶
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 ¶
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 ¶
EncryptWebhookPayload encrypts the existing webhook payload (if any) and replaces it with an encrypted version. This function modifies the state of the webhook.
func IsCtxCanceledErr ¶
func NewPrefixedMetrics ¶ added in v0.6.0
NewPrefixedMetrics returns a types.Metrics that prepends prefix to every metric name. If prefix is empty the inner instance is returned unchanged.
func WithRateLimitGate ¶ added in v0.4.0
func WithRateLimitGate(g rateLimitSignaler) func(*SlackAPIClient)
WithRateLimitGate is a functional option that wires a RateLimitSignaler into the SlackAPIClient so that a detected 429 is broadcast to all callers.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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, opts ...func(*SlackAPIClient)) *SlackAPIClient
func (*SlackAPIClient) API ¶
func (c *SlackAPIClient) API() *slack.Client
func (*SlackAPIClient) BotIsInChannel ¶
func (*SlackAPIClient) BotUserID ¶
func (c *SlackAPIClient) BotUserID() string
func (*SlackAPIClient) ChatDeleteMessage ¶
func (*SlackAPIClient) ChatPostMessage ¶
func (*SlackAPIClient) ChatUpdateMessage ¶
func (*SlackAPIClient) Connect ¶
func (c *SlackAPIClient) Connect(ctx context.Context) (*slack.AuthTestResponse, error)
func (*SlackAPIClient) GetChannelInfo ¶
func (*SlackAPIClient) GetUserIDsInChannel ¶
func (*SlackAPIClient) GetUserInfo ¶
func (*SlackAPIClient) ListBotChannels ¶
func (c *SlackAPIClient) ListBotChannels(ctx context.Context) ([]*ChannelSummary, error)
func (*SlackAPIClient) ListUserGroupMembers ¶
func (*SlackAPIClient) MessageHasReplies ¶
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 (*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.
func NewSocketModeClientWrapper ¶
func NewSocketModeClientWrapper(client *socketmode.Client, logger types.Logger) *SocketModeClientWrapper
NewSocketModeClientWrapper creates a new instance of SocketModeClientWrapper.
func (*SocketModeClientWrapper) Ack ¶
func (s *SocketModeClientWrapper) Ack(ctx context.Context, req *socketmode.Request)
Ack acknowledges the given socketmode request.
func (*SocketModeClientWrapper) AckWithFieldErrorMsg ¶ added in v0.10.0
func (s *SocketModeClientWrapper) AckWithFieldErrorMsg(ctx context.Context, evt *socketmode.Event, fieldName, errMsg string)
AckWithFieldErrorMsg acknowledges the given socketmode request with a field error message.
func (*SocketModeClientWrapper) AckWithPayload ¶ added in v0.10.0
func (s *SocketModeClientWrapper) AckWithPayload(ctx context.Context, req *socketmode.Request, payload any)
AckWithPayload acknowledges the given socketmode request with a 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.