Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ashwanthkumar/slack-go-webhook

Go Library to send messages to Slack via Webhooks
https://github.com/ashwanthkumar/slack-go-webhook

slack slack-webhook slackapi

Last synced: about 3 hours ago
JSON representation

Go Library to send messages to Slack via Webhooks

Awesome Lists containing this project

README

        

[![GoDoc](https://godoc.org/github.com/ashwanthkumar/slack-go-webhook?status.svg)](https://godoc.org/github.com/ashwanthkumar/slack-go-webhook)

# slack-go-webhook

Go Lang library to send messages to Slack via Incoming Webhooks.

## Usage
```go
package main

import "github.com/ashwanthkumar/slack-go-webhook"
import "fmt"

func main() {
webhookUrl := "https://hooks.slack.com/services/foo/bar/baz"

attachment1 := slack.Attachment {}
attachment1.AddField(slack.Field { Title: "Author", Value: "Ashwanth Kumar" }).AddField(slack.Field { Title: "Status", Value: "Completed" })
attachment1.AddAction(slack.Action { Type: "button", Text: "Book flights 🛫", Url: "https://flights.example.com/book/r123456", Style: "primary" })
attachment1.AddAction(slack.Action { Type: "button", Text: "Cancel", Url: "https://flights.example.com/abandon/r123456", Style: "danger" })
payload := slack.Payload {
Text: "Hello from , a Go-Lang library to send slack webhook messages.\n",
Username: "robot",
Channel: "#general",
IconEmoji: ":monkey_face:",
Attachments: []slack.Attachment{attachment1},
}
err := slack.Send(webhookUrl, "", payload)
if len(err) > 0 {
fmt.Printf("error: %s\n", err)
}
}
```

## License
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0