-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_slack.go
70 lines (55 loc) · 1.19 KB
/
webhook_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jwb
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
func (c *Client) CreateSlackAttachmentWebhook(webhookUrl string, payloadWebhook SlackAttachmentPayloadWebhook) (*SlackAttachmentPayloadWebhook, error) {
rb, err := json.Marshal(payloadWebhook)
if err != nil {
return nil, err
}
fmt.Println("rb", string(rb))
req, err := http.NewRequest(
"POST",
fmt.Sprintf(webhookUrl),
strings.NewReader(string(rb)),
)
if err != nil {
return nil, err
}
_, err = c.doRequest(req)
if err != nil {
return nil, err
}
webhook := SlackAttachmentPayloadWebhook{}
if err != nil {
return nil, err
}
return &webhook, nil
}
func (c *Client) CreateSlackMessageWebhook(webhookUrl string, payloadWebhook SlackMessagePayloadWebhook) (*SlackMessagePayloadWebhook, error) {
rb, err := json.Marshal(payloadWebhook)
if err != nil {
return nil, err
}
fmt.Println("rb", string(rb))
req, err := http.NewRequest(
"POST",
fmt.Sprintf(webhookUrl),
strings.NewReader(string(rb)),
)
if err != nil {
return nil, err
}
_, err = c.doRequest(req)
if err != nil {
return nil, err
}
webhook := SlackMessagePayloadWebhook{}
if err != nil {
return nil, err
}
return &webhook, nil
}