slack

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ErrNon200 is the exception class when a non-200 is returned from slack.
	ErrNon200 = "slack; non-200 status code returned from remote"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Username  string `json:"username,omitempty" yaml:"username,omitempty"`
	Channel   string `json:"channel,omitempty" yaml:"channel,omitempty"`
	IconURL   string `json:"iconURL,omitempty" yaml:"iconURL,omitempty"`
	IconEmoji string `json:"iconEmoji,omitempty" yaml:"iconEmoji,omitempty"`
	Webhook   string `json:"webhook,omitempty" yaml:"webhook,omitempty"`
}

Config represents the required fields for the config.

func (Config) GetChannel

func (c Config) GetChannel(inherited ...string) string

GetChannel returns a property or default.

func (Config) GetIconEmoji

func (c Config) GetIconEmoji(inherited ...string) string

GetIconEmoji returns a property or default.

func (Config) GetIconURL

func (c Config) GetIconURL(inherited ...string) string

GetIconURL returns a property or default.

func (Config) GetUsername

func (c Config) GetUsername(inherited ...string) string

GetUsername returns a property or a default.

func (Config) GetWebhook

func (c Config) GetWebhook(defaults ...string) string

GetWebhook returns the webhook url.

func (Config) IsZero

func (c Config) IsZero() bool

IsZero returns if the config is set or not.

type Message

type Message struct {
	Channel      string `json:"channel,omitempty"`
	ResponseType string `json:"response_type,omitempty"`
	Text         string `json:"text"`
	Username     string `json:"username,omitempty"`
	UnfurlLinks  bool   `json:"unfurl_links"`
	IconEmoji    string `json:"icon_emoji,omitempty"`
	IconURL      string `json:"icon_url,omitempty"`

	Attachments []MessageAttachment `json:"attachments"`
}

Message is a message sent to slack.

func ApplyMessageOptions added in v0.3.2

func ApplyMessageOptions(m Message, options ...MessageOption) Message

ApplyMessageOptions applies a set of options against a message and returns the mutated copy.

type MessageAttachment

type MessageAttachment struct {
	Title      string                   `json:"title,omitempty"`
	Color      string                   `json:"color,omitempty"`
	Pretext    string                   `json:"pretext,omitempty"`
	Text       string                   `json:"text,omitempty"`
	MarkdownIn []string                 `json:"mrkdwn_in,omitempty"`
	Fields     []MessageAttachmentField `json:"fields,omitempty"`
}

MessageAttachment is an attachment for a message.

type MessageAttachmentField

type MessageAttachmentField struct {
	Title string `json:"title,omitempty"`
	Value string `json:"value,omitempty"`
	Short bool   `json:"short"`
}

MessageAttachmentField is a field on an attachment.

type MessageOption added in v0.3.2

type MessageOption func(m *Message)

MessageOption is a mutator for messages.

func WithChannel added in v0.3.2

func WithChannel(channel string) MessageOption

WithChannel sets the channel.

func WithIconEmoji added in v0.3.2

func WithIconEmoji(emoji string) MessageOption

WithIconEmoji sets the icon emoji.

func WithIconURL added in v0.3.2

func WithIconURL(url string) MessageOption

WithIconURL sets the icon url.

func WithUsername added in v0.3.2

func WithUsername(username string) MessageOption

WithUsername sets the channel.

type MockSender added in v0.3.1

type MockSender chan Message

MockSender is a mocked sender.

func NewMockSender added in v0.3.1

func NewMockSender() MockSender

NewMockSender creates a new mock sender.

func (MockSender) Send added in v0.3.1

func (ms MockSender) Send(ctx context.Context, m Message) error

Send sends a mocked message.

type Sender added in v0.3.1

type Sender interface {
	Send(context.Context, Message) error
}

Sender is a type that can send slack messages.

type WebhookSender

type WebhookSender struct {
	*webutil.RequestSender
	Config *Config
}

WebhookSender sends slack webhooks.

func NewWebhookSender

func NewWebhookSender(cfg *Config) *WebhookSender

NewWebhookSender creates a new webhook sender.

func (WebhookSender) ApplyDefaults

func (whs WebhookSender) ApplyDefaults(message Message) Message

ApplyDefaults applies defaults.

func (WebhookSender) Send

func (whs WebhookSender) Send(ctx context.Context, message Message) error

Send sends a slack hook.

Jump to

Keyboard shortcuts

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