Unity-Technologies / go-slack

Go library for the Slack API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Go library for the Slack API.

License:BSD 2-Clause "Simplified" License


Languages

Language:Go 100.0%