slack

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoxPrefixInfo    = "⬜️ "
	BoxPrefixWarn    = "🟧 "
	BoxPrefixError   = "🟥 "
	BoxPrefixSuccess = "🟩 "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Token is the token you get from the OAuth&Permissions tab in your slack
	// application's features.
	Token string

	// Channel is the channel ID you get after pressing the 'Get channel
	// details' button (channel title) in any channel, the Channel ID is at the
	// bottom of the pop-up box.
	Channel string

	// URL is optional and only needs to be set when testing with a local mock
	// slack server.
	URL string

	// ErrorLogger is an optional place that any failures to send slack messages
	// are written to; to prevent issues our SendMessage() never returns an
	// error because it runs in a goroutine and returns immediately.
	ErrorLogger io.Writer
}

Config provides configuration for a Slack.

type HighestNumDebouncer added in v1.6.0

type HighestNumDebouncer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

HighestNumDebouncer holds values for debouncing slack messages based on the highest number in a given period.

func NewHighestNumDebouncer added in v1.6.0

func NewHighestNumDebouncer(slacker Slacker, debounceTimeout time.Duration, msg string) *HighestNumDebouncer

NewHighestNumDebouncer initialises a new HighestNumDebouncer instance.

  • slacker: a slacker.
  • debounceTimeout: the minimum interval between sending messages.
  • msg: a message suffix that will be appended to the highest number in the debounce period.

func (*HighestNumDebouncer) SendDebounceMsg added in v1.6.0

func (hnd *HighestNumDebouncer) SendDebounceMsg(num int)

SendDebounceMsg sends a Slack message if conditions are met, ensuring only one unique message is sent within the specified debounce interval.

type Level

type Level int
const (
	Info Level = iota
	Warn
	Error
	Success
)

type Mock

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

func NewMock

func NewMock(logger *gas.StringLogger) *Mock

func (*Mock) SendMessage

func (s *Mock) SendMessage(level Level, msg string)

type Slack

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

Slack is something that lets you send messages to Slack.

func New

func New(config Config) *Slack

New creates a new Slack using the Token, Channel and URL (if provided) from the Config.

To get the token you must first create a Slack application, which needs to be a bot with these scopes added: chat:write, chat:write.customize, chat:write.public, groups:read and incoming-webhook, and then add this bot to your workspace.

func (*Slack) SendMessage

func (s *Slack) SendMessage(level Level, msg string)

SendMessage sends the given message to our configured channel, prefixing it with a colour corresponding to its level.

NB: this returns immediately, sending in a goroutine. To see errors, configer the slacker with an ErrorLogger.

type Slacker added in v1.6.0

type Slacker interface {
	SendMessage(level Level, msg string)
}

Jump to

Keyboard shortcuts

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