Documentation ¶
Overview ¶
Package slack includes helpers for sending slack webhooks.
Index ¶
- Constants
- type Config
- type Message
- type MessageAttachment
- type MessageAttachmentField
- type MessageOption
- func OptMessageAttachment(attachment MessageAttachment) MessageOption
- func OptMessageChannel(channel string) MessageOption
- func OptMessageChannelOrDefault(channel string) MessageOption
- func OptMessageIconEmoji(emoji string) MessageOption
- func OptMessageIconEmojiOrDefault(emoji string) MessageOption
- func OptMessageIconURL(url string) MessageOption
- func OptMessageIconURLOrDefault(url string) MessageOption
- func OptMessageResponseType(responseType string) MessageOption
- func OptMessageUsername(username string) MessageOption
- func OptMessageUsernameOrDefault(username string) MessageOption
- type MockWebhookSender
- func (ms MockWebhookSender) PostMessage(channel, text string, options ...MessageOption) error
- func (ms MockWebhookSender) PostMessageContext(ctx context.Context, channel, text string, options ...MessageOption) error
- func (ms MockWebhookSender) Send(ctx context.Context, m Message) error
- func (ms MockWebhookSender) SendAndReadResponse(ctx context.Context, m Message) (*PostMessageResponse, error)
- type PostMessageResponse
- type Sender
- type WebhookSender
- func (whs WebhookSender) MessageDefaults() []MessageOption
- func (whs WebhookSender) PostMessage(channel, messageText string, options ...MessageOption) error
- func (whs WebhookSender) PostMessageAndReadResponse(channel, messageText string, options ...MessageOption) (*PostMessageResponse, error)
- func (whs WebhookSender) PostMessageAndReadResponseContext(ctx context.Context, channel, messageText string, options ...MessageOption) (*PostMessageResponse, error)
- func (whs WebhookSender) PostMessageContext(ctx context.Context, channel, messageText string, options ...MessageOption) error
- func (whs WebhookSender) Send(ctx context.Context, message Message) error
- func (whs WebhookSender) SendAndReadResponse(ctx context.Context, message Message) (*PostMessageResponse, error)
Constants ¶
const ( // ErrNon200 is the exception class when a non-200 is returned from slack. ErrNon200 ex.Class = "slack; non-200 status code returned from remote" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { APIToken string `json:"apiToken,omitempty" yaml:"apiToken,omitempty" env:"SLACK_TOKEN"` Username string `json:"username,omitempty" yaml:"username,omitempty" env:"SLACK_USERNAME"` Channel string `json:"channel,omitempty" yaml:"channel,omitempty" env:"SLACK_CHANNEL"` IconURL string `json:"iconURL,omitempty" yaml:"iconURL,omitempty" env:"SLACK_ICON_URL"` IconEmoji string `json:"iconEmoji,omitempty" yaml:"iconEmoji,omitempty" env:"SLACK_ICON_EMOJI"` Webhook string `json:"webhook,omitempty" yaml:"webhook,omitempty" env:"SLACK_WEBHOOK"` }
Config represents the required fields for the config.
type Message ¶
type Message struct { Username string `json:"username,omitempty"` Channel string `json:"channel,omitempty"` Parse string `json:"parse,omitempty"` ResponseType string `json:"response_type,omitempty"` Text string `json:"text"` IconEmoji string `json:"icon_emoji,omitempty"` IconURL string `json:"icon_url,omitempty"` ThreadTimestamp string `json:"thread_ts,omitempty"` AsUser bool `json:"as_user,omitempty"` LinkNames bool `json:"link_names"` Attachments []MessageAttachment `json:"attachments"` // Response-specific fields BotID string `json:"bot_id,omitempty"` Type string `json:"type,omitempty"` SubType string `json:"subtype,omitempty"` Timestamp string `json:"ts,omitempty"` }
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.
func NewMessage ¶ added in v1.20201204.1
func NewMessage(options ...MessageOption) *Message
NewMessage creates a new message with a given set of options.
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 OptMessageAttachment ¶ added in v1.20201204.1
func OptMessageAttachment(attachment MessageAttachment) MessageOption
OptMessageAttachment adds a message attachment.
func OptMessageChannel ¶ added in v1.20201204.1
func OptMessageChannel(channel string) MessageOption
OptMessageChannel sets the channel.
func OptMessageChannelOrDefault ¶ added in v1.20201204.1
func OptMessageChannelOrDefault(channel string) MessageOption
OptMessageChannelOrDefault sets the channel if its unset.
func OptMessageIconEmoji ¶ added in v1.20201204.1
func OptMessageIconEmoji(emoji string) MessageOption
OptMessageIconEmoji sets the icon emoji.
func OptMessageIconEmojiOrDefault ¶ added in v1.20201204.1
func OptMessageIconEmojiOrDefault(emoji string) MessageOption
OptMessageIconEmojiOrDefault sets the icon emoji.
func OptMessageIconURL ¶ added in v1.20201204.1
func OptMessageIconURL(url string) MessageOption
OptMessageIconURL sets the icon url.
func OptMessageIconURLOrDefault ¶ added in v1.20201204.1
func OptMessageIconURLOrDefault(url string) MessageOption
OptMessageIconURLOrDefault sets the icon url.
func OptMessageResponseType ¶ added in v1.20201204.1
func OptMessageResponseType(responseType string) MessageOption
OptMessageResponseType sets the response type.
func OptMessageUsername ¶ added in v1.20201204.1
func OptMessageUsername(username string) MessageOption
OptMessageUsername sets the username.
func OptMessageUsernameOrDefault ¶ added in v1.20201204.1
func OptMessageUsernameOrDefault(username string) MessageOption
OptMessageUsernameOrDefault sets the username.
type MockWebhookSender ¶ added in v1.20201204.1
type MockWebhookSender chan Message
MockWebhookSender is a mocked sender.
func NewMockWebhookSender ¶ added in v1.20201204.1
func NewMockWebhookSender() MockWebhookSender
NewMockWebhookSender creates a new mock sender.
func (MockWebhookSender) PostMessage ¶ added in v1.20201204.1
func (ms MockWebhookSender) PostMessage(channel, text string, options ...MessageOption) error
PostMessage sends a mocked message.
func (MockWebhookSender) PostMessageContext ¶ added in v1.20201204.1
func (ms MockWebhookSender) PostMessageContext(ctx context.Context, channel, text string, options ...MessageOption) error
PostMessageContext sends a mocked message.
func (MockWebhookSender) Send ¶ added in v1.20201204.1
func (ms MockWebhookSender) Send(ctx context.Context, m Message) error
Send sends a mocked message.
func (MockWebhookSender) SendAndReadResponse ¶ added in v1.20201204.1
func (ms MockWebhookSender) SendAndReadResponse(ctx context.Context, m Message) (*PostMessageResponse, error)
SendAndReadResponse sends a mocked message.
type PostMessageResponse ¶ added in v1.20201204.1
type PostMessageResponse struct { OK bool `json:"ok"` Channel string `json:"channel,omitempty"` Timestamp string `json:"ts,omitempty"` Message Message `json:"message,omitempty"` Error string `json:"error,omitempty"` }
PostMessageResponse is a slack response
type Sender ¶ added in v0.3.1
type Sender interface { Send(ctx context.Context, msg Message) error SendAndReadResponse(ctx context.Context, msg Message) (*PostMessageResponse, error) PostMessage(channel string, messageText string, opts ...MessageOption) error PostMessageContext(ctx context.Context, channel string, messageText string, opts ...MessageOption) error }
Sender is a type that can send slack messages.
type WebhookSender ¶
WebhookSender sends slack webhooks.
func New ¶ added in v1.20201204.1
func New(cfg Config) *WebhookSender
New creates a new webhook sender.
func (WebhookSender) MessageDefaults ¶ added in v1.20201204.1
func (whs WebhookSender) MessageDefaults() []MessageOption
MessageDefaults returns default message options.
func (WebhookSender) PostMessage ¶ added in v1.20201204.1
func (whs WebhookSender) PostMessage(channel, messageText string, options ...MessageOption) error
PostMessage posts a basic message to a given channel.
func (WebhookSender) PostMessageAndReadResponse ¶ added in v1.20201204.1
func (whs WebhookSender) PostMessageAndReadResponse(channel, messageText string, options ...MessageOption) (*PostMessageResponse, error)
PostMessageAndReadResponse posts a basic message to a given channel and returns the deserialized response
func (WebhookSender) PostMessageAndReadResponseContext ¶ added in v1.20201204.1
func (whs WebhookSender) PostMessageAndReadResponseContext(ctx context.Context, channel, messageText string, options ...MessageOption) (*PostMessageResponse, error)
PostMessageAndReadResponseContext posts a basic message to a given channel and returns the deserialized response
func (WebhookSender) PostMessageContext ¶ added in v1.20201204.1
func (whs WebhookSender) PostMessageContext(ctx context.Context, channel, messageText string, options ...MessageOption) error
PostMessageContext posts a basic message to a given chanel with a given context.
func (WebhookSender) Send ¶
func (whs WebhookSender) Send(ctx context.Context, message Message) error
Send sends a slack hook.
func (WebhookSender) SendAndReadResponse ¶ added in v1.20201204.1
func (whs WebhookSender) SendAndReadResponse(ctx context.Context, message Message) (*PostMessageResponse, error)
SendAndReadResponse sends a slack hook and returns the deserialized response