diff options
author | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-02-01 01:20:38 +0300 |
---|---|---|
committer | Alexander Kiryukhin <alexander@kiryukhin.su> | 2019-02-01 01:20:38 +0300 |
commit | 8c499a32b7bb614814da84bace3f3e924be92465 (patch) | |
tree | 3bc9d97a01fdb6e4bf219d5de81f1873232fe696 /channel.go | |
parent | fc9aefc97d872ec8faed767a7b9e2a89ee8630f0 (diff) |
fixes
Diffstat (limited to 'channel.go')
-rw-r--r-- | channel.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/channel.go b/channel.go new file mode 100644 index 0000000..95cdd7d --- /dev/null +++ b/channel.go @@ -0,0 +1,39 @@ +package main + +import ( + "encoding/json" + "errors" + "log" + "net/http" + "net/url" +) + +func getUsers(token string, channel string) ([]string, error) { + u, _ := url.Parse("https://slack.com/api/channels.info") + u.Query().Set("token", token) + u.Query().Set("channel", channel) + req, err := http.NewRequest(http.MethodGet, u.String(), nil) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + resp, err := getClient().Do(req) + if err != nil { + log.Println(err) + return nil, err + } + r := struct { + OK bool `json:"ok"` + Error string `json:"error"` + Channel struct { + Members []string `json:"members"` + } `json:"channel"` + }{} + if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { + return nil, err + } + if !r.OK { + return nil, errors.New(r.Error) + } + return r.Channel.Members, nil +} |