easonlin404 / go-slack

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-slack

A simple, flexible Golang wrapper around the Slack webhook API. Makes it easy to send notifications to Slack from your application(inspired by nodejs slack-notify).

Travis branch Codecov branch Go Report Card GoDoc

Features

  • Send plain text and message with attachments
  • Send attachments with markdown syntax
  • Debug
  • Timeout
  • Logger
  • Context(todo)

Installation

$ go get -u github.com/easonlin404/go-slack

Useage

Basic send text message

// 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

// 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

// 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

// 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)

About

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

License:MIT License


Languages

Language:Go 100.0%