-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchat.go
57 lines (50 loc) · 1.57 KB
/
chat.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
package slack
import (
"context"
"net/url"
)
type ChatService struct {
client *Client
}
type response struct {
OK bool `json:"ok"`
Channel string `json:"channel"`
TS SlackTime `json:"ts"`
Error string `json:"error"`
Warning string `json:"warning"`
}
type permalinkResponse struct {
OK bool `json:"ok"`
Channel string `json:"channel"`
Permalink string `json:"permalink"`
Error string `json:"error"`
}
// https://api.slack.com/methods/chat.postMessage
func (c *ChatService) PostMessage(ctx context.Context, data url.Values) (*response, error) {
resp := new(response)
err := c.client.CreateResource(ctx, "/api/chat.postMessage", data, resp)
return resp, err
}
// https://api.slack.com/methods/chat.delete
func (c *ChatService) DeleteMessage(ctx context.Context, channelID, messageID string) (*response, error) {
data := url.Values{
"channel": []string{channelID},
"ts": []string{messageID},
}
resp := new(response)
err := c.client.CreateResource(ctx, "/api/chat.delete", data, resp) // Delete is a POST
return resp, err
}
// https://api.slack.com/methods/chat.getPermalink
//
// `channelID` has to be the ID of the channel (C*), this endpoint does not
// support the encoded channel names (#foo).
func (c *ChatService) GetPermalink(ctx context.Context, channelID, messageID string) (*permalinkResponse, error) {
data := url.Values{
"channel": []string{channelID},
"message_ts": []string{messageID},
}
resp := new(permalinkResponse)
err := c.client.CreateResource(ctx, "/api/chat.getPermalink", data, resp)
return resp, err
}