Help us shape the future of Go! Take the 2026 Go Developer Survey

slackhook

package module
v0.0.0-...-14cbce9 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

GoDoc Build Status

slackhook

Minimal client for Slack's Incoming WebHooks API.

Examples

import "github.com/videofruit/slackhook"

slackHook := slackhook.New(webhookURL, slackhook.ClientOptions{})

slackHook.Simple("Hello from slackhook!")

Documentation

Overview

slackhook is a minimal client for Slack's Incoming WebHooks API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Type  string `json:"type,omitempty"`
	Text  string `json:"text,omitempty"`
	URL   string `json:"url,omitempty"`
	Style string `json:"style,omitempty"`
}

Action is a link styled as a button

See https://api.slack.com/docs/message-attachments#attaching_buttons_to_messages

type Attachment

type Attachment struct {
	Fallback   string   `json:"fallback,omitempty"` // plain text summary
	Color      string   `json:"color,omitempty"`    // {good|warning|danger|hex}
	AuthorName string   `json:"author_name,omitempty"`
	AuthorLink string   `json:"author_link,omitempty"`
	AuthorIcon string   `json:"author_icon,omitempty"`
	Title      string   `json:"title,omitempty"` // larger, bold text at top of attachment
	TitleLink  string   `json:"title_link,omitempty"`
	Text       string   `json:"text,omitempty"`
	Fields     []Field  `json:"fields,omitempty"`
	Actions    []Action `json:"actions,omitempty"`
	ImageURL   string   `json:"image_url,omitempty"`
	ThumbURL   string   `json:"thumb_url,omitempty"`
	FooterIcon string   `json:"footer,omitempty"`
	Footer     string   `json:"footer_icon,omitempty"`
	Timestamp  int      `json:"ts,omitempty"` // Unix timestamp
}

Attachment provides rich-formatting to messages

See https://api.slack.com/docs/attachments

type Client

type Client struct {
	HTTPClient Poster
	// contains filtered or unexported fields
}

Client for Slack's Incoming WebHook API.

func New

func New(url string, opts ClientOptions) *Client

New Slack Incoming WebHook Client using http.DefaultClient for its Poster.

func (*Client) Send

func (c *Client) Send(msg *Message) error

Send a Message.

func (*Client) Simple

func (c *Client) Simple(msg string) error

Simple text message.

type ClientOptions

type ClientOptions struct {
	HTTPClient Poster
}

ClientOptions specifies options when creating a new Client

type Field

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

Field is displayed in a table inside the message attachment

See https://api.slack.com/docs/message-attachments#fields

type Message

type Message struct {
	Text        string        `json:"text"`
	Channel     string        `json:"channel,omitempty"`
	UserName    string        `json:"username,omitempty"`
	IconURL     string        `json:"icon_url,omitempty"`
	IconEmoji   string        `json:"icon_emoji,omitempty"`
	Attachments []*Attachment `json:"attachments,omitempty"`
}

Message to send to Slack's Incoming WebHook API.

See https://api.slack.com/incoming-webhooks

func (*Message) AddAttachment

func (m *Message) AddAttachment(a *Attachment)

AddAttachment adds attachments to a Slack Message

type Poster

type Poster interface {
	Post(url, contentType string, body io.Reader) (*http.Response, error)
}

Poster interface is the methods of http.Client required by Client to ease testing.

Jump to

Keyboard shortcuts

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