slack

package module
v0.0.0-...-0762aee Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: BSD-2-Clause Imports: 1 Imported by: 15

README

Slack Go Report Card License GoDoc Build Status

go-slack is a Go library for the Slack API.

Features

Installation

go get -u github.com/multiplay/go-slack

Examples

The simplest way to use go-slack is to create a webhook client and send chat messages using it e.g.

package main

import (
	"github.com/multiplay/go-slack/chat"
	"github.com/multiplay/go-slack/webhook"
)

func main() {
	c := webhook.New("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX")
	m := &chat.Message{Text: "test message"}
	m.Send(c)
}

If your using logrus you can use the webhook to post to slack based on your logging e.g.

package main

import (
	"github.com/multiplay/go-slack/lrhook"
	"github.com/multiplay/go-slack/chat"
	"github.com/sirupsen/logrus"
)

func main() {
	cfg := lrhook.Config{
		MinLevel:       logrus.ErrorLevel,
		Message:	chat.Message{
			Channel:	"#slack-testing",
			IconEmoji:	":ghost:",
		},
	}
	h := lrhook.New(cfg, "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX")
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.SetLevel(logrus.InfoLevel)
	logrus.AddHook(h)
	logrus.Error("my error")
}

Documentation

License

go-slack is available under the BSD 2-Clause License.

Documentation

Overview

Package slack provides a generic interface for slack clients and some basic types to enable the creation of slack clients.

See the webhook sub directory for an example of such a client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Send sends the request to slack.
	Send(url string, message, response interface{}) error
}

Client represents a slack client.

type Error

type Error struct {
	// StatusCode is the status code returned by the request.
	StatusCode int

	// Message is the message, if any, returned in the body.
	Message string
}

Error represents an error from the Slack API.

func NewError

func NewError(statuscode int, msg string) *Error

NewError returns a new slack error with statuscode and msg.

func (*Error) Error

func (e *Error) Error() string

type Response

type Response struct {
	OK      bool   `json:"ok"`
	Error   string `json:"error,omitempty"`
	Warning string `json:"warning,omitempty"`
}

Response is a generic response from slack which implements SendResponse.

func (Response) Err

func (r Response) Err() string

Err implements SendResponse.Err.

func (Response) Ok

func (r Response) Ok() bool

Ok implements SendResponse.Ok.

func (Response) Warn

func (r Response) Warn() string

Warn implements SendResponse.Warn.

type SendResponse

type SendResponse interface {
	Ok() bool
	Err() string
	Warn() string
}

SendResponse is the interface that responses implement.

Directories

Path Synopsis
Package chat implements the types needed to post chat messages to slack.
Package chat implements the types needed to post chat messages to slack.
cmd
slackit
slackit is a command line golang slack client.
slackit is a command line golang slack client.
Package lrhook provides logrus hook for the Slack.
Package lrhook provides logrus hook for the Slack.
Package test provides a slack client implementation which uses the slack api.test endpoint so is suitable to testing.
Package test provides a slack client implementation which uses the slack api.test endpoint so is suitable to testing.
Package webhook provides a slack webhook client implementation.
Package webhook provides a slack webhook client implementation.

Jump to

Keyboard shortcuts

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