https://github.com/spider-pigs/slackmsg
A simple golang library to send slack messages.
https://github.com/spider-pigs/slackmsg
golang slack
Last synced: 5 months ago
JSON representation
A simple golang library to send slack messages.
- Host: GitHub
- URL: https://github.com/spider-pigs/slackmsg
- Owner: spider-pigs
- License: mit
- Created: 2019-08-08T07:10:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-16T19:00:08.000Z (over 3 years ago)
- Last Synced: 2024-06-19T05:38:57.807Z (about 2 years ago)
- Topics: golang, slack
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 8
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slackmsg
[](https://github.com/spider-pigs/slackmsg/actions) [](https://goreportcard.com/report/github.com/spider-pigs/slackmsg) [](https://godoc.org/github.com/spider-pigs/slackmsg)
A simple golang library to send a slack message.
## Install
```Go
import "github.com/spider-pigs/slackmsg"
```
## Usage
```Go
package main
import (
"context"
"fmt"
"time"
"github.com/spider-pigs/slackmsg"
)
func main() {
// create message
msg := slackmsg.New()
msg.Text = "I am a test message!"
attachment := slackmsg.Attachment{
Text: "And here’s an attachment!",
}
msg.AddAttachment(attachment)
// dump JSON to verify?
fmt.Println(msg.ToJSON())
// send message
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
webhook := "https://hooks.slack.com/services/..."
err := msg.Send(ctx, webhook)
if err != nil {
fmt.Println("failed to send message:", err)
return
}
fmt.Println("successfully sent message")
}
```