-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.go
53 lines (44 loc) · 943 Bytes
/
slack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package slack
import (
"github.com/easonlin404/esrest"
"net/http"
)
type Slack struct {
webhookURL string
debug bool
}
func New() *Slack {
return &Slack{}
}
type Message struct {
//TODO: other
Text string `json:"text"`
Attachments []Attachment `json:"attachments"`
}
type Attachment struct {
Title string `json:"title"`
Text string `json:"text"`
MrkdwnIn []string `json:"mrkdwn_in"`
Fields []Field `json:"fields"`
}
type Field struct {
Title string `json:"title"`
Value int `json:"value"`
Short bool `json:"short"`
}
func (s *Slack) WebhookURL(webhookURL string) *Slack {
s.webhookURL = webhookURL
return s
}
func (s *Slack) Debug(debug bool) *Slack {
s.debug = debug
return s
}
func (s *Slack) SendMessage(message Message) (*http.Response, error) {
return esrest.New().
Header("Content-Type", "text/plain").
Debug(s.debug).
Post(s.webhookURL).
Body(message).
Do()
}