Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/easonlin404/go-slack

A simple, flexible Golang wrapper around the Slack webhook API.
https://github.com/easonlin404/go-slack

go golang slack slack-webhook

Last synced: 22 days ago
JSON representation

A simple, flexible Golang wrapper around the Slack webhook API.

Awesome Lists containing this project

README

        

# go-slack

A simple, flexible Golang wrapper around the [Slack webhook API](https://api.slack.com). Makes it easy to send notifications to Slack from your application(inspired by nodejs [slack-notify](https://github.com/andrewchilds/slack-notify)).

[![Travis branch](https://img.shields.io/travis/easonlin404/go-slack/master.svg)](https://travis-ci.org/easonlin404/go-slack)
[![Codecov branch](https://img.shields.io/codecov/c/github/easonlin404/go-slack/master.svg)](https://codecov.io/gh/easonlin404/go-slack)
[![Go Report Card](https://goreportcard.com/badge/github.com/easonlin404/gin-slack)](https://goreportcard.com/report/github.com/easonlin404/gin-slack)
[![GoDoc](https://godoc.org/github.com/easonlin404/gin-slack?status.svg)](https://godoc.org/github.com/easonlin404/gin-slack)

## Features
* Send plain text and message with attachments
* Send attachments with markdown syntax
* Debug
* Timeout
* Logger
* [Context](https://golang.org/pkg/context/)(todo)

## Installation
```sh
$ go get -u github.com/easonlin404/go-slack
```

## Useage
Basic send text message
```go
// You need get your slack WebhookURL from https://api.slack.com/incoming-webhooks
webhookURL := "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"

message := Message{
Text: "message",
}

r, e := slack.New().
WebhookURL(webhookURL).
SendMessage(message)
```
Send message with attachments
```go
// You need get your slack WebhookURL from https://api.slack.com/incoming-webhooks
webhookURL := "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"

message := Message{
Attachments: []Attachment{
{Title: "title",
Fields: []Field{
{Title: "T1", Value: 0, Short: true},
{Title: "T2", Value: 0, Short: true},
},
},
},
}

r, e := slack.New().
WebhookURL(webhookURL).
SendMessage(message)

```
Attachments enable markdown

```go
// You need get your slack WebhookURL from https://api.slack.com/incoming-webhooks
webhookURL := "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"

message := Message{
Attachments: []Attachment{
{Title: "title", MrkdwnIn: []string{"text"},
Fields: []Field{
{Title: "T1", Value: 0, Short: true},
{Title: "T2", Value: 0, Short: true},
},
},
},
}

r, e := slack.New().
WebhookURL(webhookURL).
SendMessage(message)

```

Debug
```go
// You need get your slack WebhookURL from https://api.slack.com/incoming-webhooks
webhookURL := "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"

message := Message{
Text: "message",
}

r, e := slack.New().Debug(true).
WebhookURL(webhookURL).
SendMessage(message)