https://github.com/greengeorge/go-slack
Go library to simplify communicating with the Slack API. Mainly for my own apps. In active development.
https://github.com/greengeorge/go-slack
api golang slack
Last synced: 5 months ago
JSON representation
Go library to simplify communicating with the Slack API. Mainly for my own apps. In active development.
- Host: GitHub
- URL: https://github.com/greengeorge/go-slack
- Owner: GreenGeorge
- License: mit
- Created: 2017-12-17T08:41:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-23T06:57:10.000Z (over 8 years ago)
- Last Synced: 2024-06-20T03:46:33.175Z (about 2 years ago)
- Topics: api, golang, slack
- Language: Go
- Size: 109 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go-Slack
========
[](https://circleci.com/gh/GreenGeorge/go-slack/tree/master)
[](http://godoc.org/github.com/greengeorge/go-slack)
Really simple Go library for programatically creating and delivering Slack messages. Just BYO [access token][2] and `http.Client`. Great for creating `slack` reports with reusable components.
## Usage
Install it `$ go get github.com/greengeorge/go-slack`
```go
...
import "github.com/GreenGeorge/go-slack"
// Bring your own Client or just pass nil
client := http.Client{Timeout: time.Second * 10}
// Instantiate go-slack with your access token)
sl := slack.New("xoxp-XXXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXX", client)
// Prepare attachments
attachmentFoo := slack.Attachment{
Title: "Foo",
Text: "You've got Foo",
Color: "#f5b000",
AttachmentType: "default",
Fallback: "You've got Foo",
}
attachmentBar := slack.Attachment{
Title: "Bar",
Text: "You've got Bar",
Color: "#00e6f5",
AttachmentType: "default",
Fallback: "You've got Bar",
}
// Prepare reusable actions
actionBaz := slack.Action{
Name: "Baz",
Text: "Send out the Baz",
Type: "button",
Value: "baz",
Style: "primary",
}
actionFiz := slack.Action{
Name: "Fiz",
Text: "Send out the Fiz",
Type: "button",
Value: "fiz",
Style: "danger",
}
// Mix and match them!
attachmentFoo.AddAction(actionBaz, actionFiz)
attachmentBar.AddAction(actionFiz)
// Setup base messages
messageA := slack.NewMessage("FooBar", "CHANNELIDA", ":skull:")
messageB := slack.NewMessage("BazFiz", "CHANNELIDB",":skull:")
// Assemble the final message
// Add a text message maybe
messageA.Text = "Kunci kesuksesan adalah key of success"
// Add the attachments to the message
messageA.AddAttachment(attachmentFoo, attachmentBar)
messageB.AddAttachment(attachmentBar, attachmentFoo)
// Send them out!
_, err := sl.PostMessage(messageA)
_, err := sl.PostMessage(messageB)
...
```
*et voilà*
![Example result][example]
## API Coverage
Definitely doesn't cover the whole Slack API. Just the parts I need for my use cases (easy message creation and sending by Slack's [Web API][1]). Contributions are most welcome.
Please note the message struct schema might also be incomplete. I've yet to find one list that covers everything.
[1]:https://www.google.com
[2]:https://api.slack.com/apps
[example]:example/example-result.jpg