slackhook

package module
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 6 Imported by: 3

README

Slackhook GoDoc Go Report Card

Simple client for Slack web hook URLs

Documentation

Index

Constants

View Source
const MockClient = "slack://mock"

Magic URL to use a mock client in dev.

Variables

This section is empty.

Functions

func NoOpLogger added in v0.23.2

func NoOpLogger(ctx context.Context, msg string, args ...any)

NoOpLogger does nothing with log messages.

Types

type Attachment

type Attachment struct {
	Pretext   string  `json:"pretext,omitempty"`
	Fallback  string  `json:"fallback"`
	Color     string  `json:"color,omitempty"`
	Title     string  `json:"title,omitempty"`
	TitleLink string  `json:"title_link,omitempty"`
	Text      string  `json:"text,omitempty"`
	TimeStamp int64   `json:"ts,omitempty"`
	Fields    []Field `json:"fields,omitempty"`
}

type Client

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

Client posts messages to a Slack webhook URL.

func New

func New(hookURL string) *Client

New returns a new client with the hookURL set.

func (*Client) Post

func (sc *Client) Post(ctx context.Context, l Logger, cl *http.Client, msg Message) (err error)

Post message to Slack. Logger must not be nil. Uses http.DefaultClient if cl is nil. Returns an error if response is not 200 OK.

func (*Client) Set added in v0.20.2

func (c *Client) Set(hookURL string) error

Set the hookURL for a Client. If hookURL is MockClient, Client will use a mock client. Set is part of the flag.Value interface.

func (*Client) String added in v0.20.2

func (c *Client) String() string

String is part of the flag.Value interface.

type Field

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

type Logger added in v0.23.2

type Logger = func(ctx context.Context, msg string, args ...any)

Logger is any function that behaves like slog.InfoContext, slog.DebugContext, etc.

type Message

type Message struct {
	Text        string       `json:"text"`
	Attachments []Attachment `json:"attachments"`
}

Message is the JSON object expected by Slack

Jump to

Keyboard shortcuts

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